user287474
user287474

Reputation: 325

Accept() in C - Socket Programming

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?

Upvotes: 0

Views: 1314

Answers (1)

fluter
fluter

Reputation: 13846

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;

Upvotes: 1

Related Questions