(Note: Xpost and fup2 comp.unix.programmer)
hello, world\n
I'm porting an OPSF implementation to an embedded system (pSOS 2.5, which
claims it's IP stack is derived from 4.3BSD) and observe the following
puzzling behavior. I wonder whether it's a bug in the OS, in my code, or
a misunderstanding:
I use a raw socket to receive and send OSPF packets and set the
IP_HDRINCL option:
// Open network
if ((netfd = socket(AF_INET, SOCK_RAW, PROT_OSPF)) == -1) {
do_log(LOG_ERR, "Network open failed: %d", errno);
exit(1);
}
// We will supply headers on output and want them on input
int hincl = 1;
if (setsockopt(netfd, IPPROTO_IP, IP_HDRINCL,
(char *)&hincl, sizeof(hincl)) != 0) {
do_log(LOG_ERR, "setsockopt: IP_HDRINCL, pNA error %#x", errno);
exit(1);
}
Sending my own assembled OSPF packets is no problem. Reception however
is mysterious. I use
char buffer[65536];
int plen;
int fromlen;
plen = recvfrom (netfd, buffer, sizeof (buffer), 0, 0, &fromlen);
if (plen < 0) {
do_log (LOG_ERR, "recvfrom: %d", errno);
return;
}
At this point, the buffer has the packet, including the IP header - so
far so good. However, the value plen as returned from recvfrom is not
the same as the one indicated in the IP header. The IP header's length
field is 20 less than plen, e.g. not accounting for the IP header length
itself: Say, plen is 88, while the 16 bit value at buffer+3 is 68 (big
endian system, so no, it's not a network order vs machine byte order
problem). According to rfc 791 (IP) the length is the total length
including the header.
Question: is it allowed behavior that the return value from recvfrom
can be different from the packet's IP header?
Regards,
Jens
--
Jens Schweikhardt http://www.schweikhardt.net/
SIGSIG -- signature too long (core dumped)