0

I am trying to code a server using the following example code, but I'm having trouble with these statements in particular.

int Accept(int s, struct sockaddr *addr, socklen_t *addrlen) 
{
     int rc;

     if ((rc = accept(s, addr, addrlen)) < 0)
          unix_error("Accept error");
      return rc;
}
...

socklen_t clientlen = sizeof(struct sockaddr_storage); 
int connectFd = Accept(listenfd, (SA *)&clientaddr, &clientlen)

If I were to use SA, it would pull up an error saying the following:

server.c:175:36: error: ‘SA’ undeclared (first use in this function)  
   connectFd = accept(listenFd, ( SA *  )&clientaddr, &c);  

server.c:175:36: note: each undeclared identifier is reported only once for   each function it appears in   server.c:175:40: error:
expected expression before ‘)’ token  
   connectFd = accept(listenFd, (SA * ) &clientaddr, &c);  
server.c:175:18: error: too few arguments to function ‘accept’  
   connectFd = accept(listenFd, (SA *)&clientaddr, &c);

Is there any way to solve this?

7
  • 3
    I've never seen SA as a data type in either POSIX or C standard context. Apparently it's from the csapp.h header file. How is it defined? Is it a macro? Commented May 8, 2016 at 10:25
  • Because of the example of the link, clientaddr's datatype is "struct sockaddr_storage". Would casting it be safe? Commented May 8, 2016 at 10:28
  • Oh I see, let me do some digging. Commented May 8, 2016 at 10:28
  • This might help. Commented May 8, 2016 at 10:29
  • @Downvoter : I have, also, never heard of it. The op needs to put that information here if he really wish to get some help.. Commented May 8, 2016 at 10:30

1 Answer 1

1

The type SA is not defined in your program, the compiler could not find it, you might want to add following typedef to your program:

typedef struct sockaddr SA;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.