Possible UDP socket bugs?

H. Peter Anvin (hpa@transmeta.com)
7 Aug 1997 18:59:28 GMT


Ran into the following possible bugs while writing a simple UDP
client/server application:

1. The following code is used to see if the server was spawned from
inetd and hence has a socket on stdin:

if ( getsockopt(0, SOL_SOCKET, SO_TYPE, &socktype, &typelen) == 0 )
{

However, socktype returned is in the ballpark 0x40000000 and
typelen is 0. As far as I read the spec, socktype should be
SOCK_DGRAM and typelen be sizeof(int).

Kernel: 2.1.42

2. I got the following error from the kernel:

in.loadavgd forgot to set AF_INET in udp sendmsg. Fix it!

However, the code is blatantly simple:

if ( recvfrom(sockfd, buffer, 64, 0, &fromaddr, &addrlen) < 0 )
break;

/* The first 8 bytes of the packet are returned in the reply;
reserved for client matching requests with replies */

bzero(buffer+8, 64-8);
loadavg = get_loadavg();
if ( loadavg >= 0.0 ) {
sprintf(buffer+8, "%g", loadavg);
sendto(sockfd, buffer, 64, 0, &fromaddr, addrlen);

It seems to me that the kernel itself should set AF_INET in
"fromaddr" before returning.

Kernel: 2.1.48

-hpa

-- 
    PGP: 2047/2A960705 BA 03 D3 2C 14 A8 A8 BD  1E DF FE 69 EE 35 BD 74
    See http://www.zytor.com/~hpa/ for web page and full PGP public key
Always looking for a few good BOsFH.  **  Linux - the OS of global cooperation
        I am Baha'i -- ask me about it or see http://www.bahai.org/