Subject: Re: accept() call
To: Christian Kuhtz <>
From: matthew green <>
List: tech-net
Date: 02/04/1997 19:20:47
         new_socket=accept(socket,(struct sockaddr *)&cli_addr,&sizeof(cli_addr));

you can't take the address of a number.  sizeof() "returns" a number.
that's like trying to say:

accept(foo, bar, &4);
   Why is accept() declared as "int accept(int, struct sockaddr *, int *)" and  
   not "int accept(int, struct sockaddr *, int)"?  Why can't I typecast this  
   silly argument without having to waste another temporary variable?

it's passed as a pointer because the accept system call may alter the
size of it.  in netbsd-current, sys/kern/uipc_syscalls.c:sys_accept(),
look at the block of code starting at line 207:

	if (SCARG(uap, name)) {
   Heck, looking at the implementation in Rich Steven's TCP/IP Illustrated Vol  
   II, p. 458, it does even seem like it is using the third argument (retval) at  
   [ ... ]

retval is _not_ the third argument.  retval is the return value of the
system call -- in your example i've quoted above, it is eventually
assigned to `new_socket'.

   retval after that, both being local to the procedure (well, sort of).  And  
   since I have never seen anyone passing anything but sizeof() the sockaddr arg  
   down to accept(), what's the point?

different sockaddr structures have different sizes.  eg, sockaddr_un is
not the same size as sockaddr_in.