vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Am 27.12.2006 um 02:38 schrieb Ted Unangst: > On 12/23/06, Holger Freyther <freyther@inf.fu-berlin.de> wrote: >> getsockname(int s, struct sockaddr *name, socklen_t *namelen); >> >> namelen is a input and output parameter. The input case is pretty >> obvious >> and I'm going to skip it. For the output case I have seen two >> different behaviours. >> >> Linux and OpenSolaris copy the size of the actual in-kernel structure >> into >> namelen regardles of the input value of namelen. >> The BSDs copy MIN(namelen,sa->sa_len) back into namelen. >> -Is it worth fixing the BSDs to set sa_len as namelen > > yes, it seems the behavior is incorrect. i'm curious what > stevens's book says. From UNIX Network Programming Volume 1 Second Edition on page 108 of Section 4.10. I don't see, on a quick look, a definition of the addrlen semantic. The example code cheats a bit as it is doing the following. int sockfd_to_family(int sockfd) { union { struct sockaddr sa; char data[MAXSOCKADDR]; } un; socklen_t len; len = MAXSOCKADDR; if(getsockname(sockfd, (SA*)un.data, &len) < 0 ) ... MAXSOCKADDR is defined to 128 which is large enough to fill the sockaddr for Unix Domain Sockets (at least on Linux) (Allocate room for largest socket address structure). So the steven's asks us to waste memory but is not defining the "len". And this way it avoids running into the issue shown in Tobias's test case. kind regards holger |