From owner-freebsd-bugs Sat Feb 28 13:06:15 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id NAA19692 for freebsd-bugs-outgoing; Sat, 28 Feb 1998 13:06:15 -0800 (PST) (envelope-from owner-freebsd-bugs@FreeBSD.ORG) Received: from alpha.xerox.com (firewall-user@alpha.Xerox.COM [13.1.64.93]) by hub.freebsd.org (8.8.8/8.8.8) with SMTP id NAA19684 for ; Sat, 28 Feb 1998 13:06:13 -0800 (PST) (envelope-from fenner@parc.xerox.com) Received: from crevenia.parc.xerox.com ([13.2.116.11]) by alpha.xerox.com with SMTP id <51995(2)>; Sat, 28 Feb 1998 13:06:09 PST Received: from localhost by crevenia.parc.xerox.com with SMTP id <177476>; Sat, 28 Feb 1998 13:05:52 -0800 To: Adel Abushaev cc: freebsd-bugs@FreeBSD.ORG Subject: Re: Possible ioctl() implementation mistake In-reply-to: Your message of "Sat, 28 Feb 98 09:50:28 PST." <199802281750.UAA07054@alpha.ksu.ru> Date: Sat, 28 Feb 1998 13:05:40 PST From: Bill Fenner Message-Id: <98Feb28.130552pst.177476@crevenia.parc.xerox.com> Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org This is an old BSD bug. It's also present in IRIX 6.2, OSF1 3.2, SunOS 4.1.3_U1, and NeXTStep 3.3 . The problem is that the 16-byte sockaddr is stored in the receive buffer too, for recvfrom() to return. FIONREAD returns the amount of data in the receive buffer, without worrying about whether it's really data or control info. For example, if I setsockopt(...,IP_RECVDSTADDR,...), server's output becomes ioctl: 544 recv: 512 ioctl: 0 since both the source and the destination are on the socket buffer queue. There are a couple possible fixes: 1. Walk the socket buffer, adding up the lengths of MT_HEADER, MT_DATA or MT_OOBDATA mbufs. This is easy but it's a shame to convert an O(1) function to an O(N) one. 2. Redefine sb_cc to be the data-only length (which appears to be the intent in any case) and make sure that the sockbuf handling functions manage it properly. This may or may not be easy, depending on how much other pieces of the system know about sockbuf internals. Bill To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message