gottsc@citrus.citr.uq.oz.au (John Gottschalk) (03/25/91)
Hello, I have a question on the accept() system function. The function and its parameters are defined as follows: int accept(s, addr, addrlen) int s; struct sockaddr *addr; int *addrlen; where addr is filled in with the address of the connecting entity, and addrlen is the length of the address. In the tutorial on sockets in the SUN manual there are examples where null-pointers are supplied as the last two parameters, yet none of the manuals I have read state that these parameters are optional, in fact there is an error defined, EFAULT, which is used if the addr parameter is not is a writable part of the user address space. Can anybody tell me if null-pointers can be supplied for these parameters, or not? -- thanks in advance, John Gottschalk ===================================================================== John Gottschalk (gottsc@citrus.uq.oz) Center for Information Technology Research, University of Queensland, St Lucia, 4072, Queensland, Australia, +61 7 365 4321 (phone), +61 7 371 3044 (fax) =====================================================================
jik@athena.mit.edu (Jonathan I. Kamens) (03/25/91)
Yes, you an specify null pointers for the addr and addrlen arguments to accept(). The kernel checks specifically if the addrlen pointer is null, and if it is, does not attempt to fill the addr structure with anything. This is equivalent to saying, "I'm not really interested in the address from which the connection originates, so don't bother to tell me." Note: I'm not 100% certain that this will work on all systems that support accept(), so you might not want to rely on it. It isn't a lot of effort to allocate a sockaddr structure and pass it in, after all, so worrying about whether or not passing in a null pointer will work on every architecture on which you ever end up compiling your code may not be worth the hassle. Incidentally, the EFAULT error is for if the address is *non-null* and falls outside the writeable part of the user address space. -- Jonathan Kamens USnail: MIT Project Athena 11 Ashford Terrace jik@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710