Neil%Teleos.com@ai.sri.com (Neil Hunt) (04/25/89)
Does anyone know anything about the missing 16 bytes are which are reported by ioctl(sock, FIONREAD, &n) when applied to an internet datagram socket? I find that if ioctl reports N bytes available on the socket, then a read with a much larger buffer returns a maximum of N-16 bytes. If there are multiple datagrams, with lengths N0, N1, ...Nn, then N = N0 + N1 + ... + Nn + 16, and after packet n has been read, (theoretically leaving 16 bytes, according to the original report) the next read blocks, and an additional ioctl(sock, FIONREAD, &n) performed at that point reports 0 bytes available. Here is the code, which is supposed never to block: (Error checks removed for clarity.) read_last(sock, packet, len) char *packet; { ioctl(sock, FIONREAD, &n); while(n > 0) { i = read(sock, packet, len); n -= i; } return i; } A workaround is easy. I was curious whether this is a bug, or if it is just a case of not finding the right page in the manual (is there such a thing as a right page in ``Socket Based IPC Tutorial''?) PS: The system in question is a Sun 2/120, 3.5; also Sun 2/50, 3.5. Neil/.