[Sorry for the incomplete previous message] Hi Melvin, on Mon, 3 Feb 2003 19:38:25 +0100 Melvin Hadasht <melvin.hadasht@free.fr> wrote:
My `info libc` didn't mention an explicit need to do that (except for getsockopt and getsockname); BUT the example initialized the one for accept!!!
According to my "man accept" page, the length "should" be initialised (at least if addr is not NULL) The same source indicates that the addrlen should contain the allocated size of the structure pointed by addr (or more precisely, the sizeof() that structure). In the case of struct sockaddr_un, that size is 110, where 2 bytes are for the sa_family_t and 108 for the char array that holds the name. It seems the length is used to check if the function will not do a buffer overflow when filling it. accept() will then update the addrlen to inform the caller about the real length of the client info. In case of a Unix socket, it seems that it is used (but the string sun_path is of zero length), hence addrlen is returned with the value 2. In our case, as the client address is not used, we could just use NULL for both addr and addrlen. Anyway, in our case, libc info does not say that addrlen need to be initialized if addr is not NULL.
Well this isn't too surprising as the same source explains two equivalent ways to calculate the size of the address, and when tested they are different! :)
Concerning the SUN_LEN, the formula you used takes into account the trailing NUL byte of the string, which is wrong according to info libc: "You should compute the LENGTH parameter for a socket address in the local namespace as the sum of the size of the `sun_family' component and the string length (_not_ the allocation size!) of the file name string". *But* the man page says the addrlen argument to accept() should contain the "size of the structure pointed to by addr", so in this case, the SUN_LEN is not the candidate, but rather the "sizeof(struct sockaddr_un)".
Should we report that?
You mean reporting that accept() needs addrlen initialized if addr is not NULL? I don't know, as it seems that my system is the only one with that symptom. Farvel (Danish: Farewell) -- Melvin Hadasht