From owner-freebsd-net Wed Jul 1 05:20:08 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id FAA09526 for freebsd-net-outgoing; Wed, 1 Jul 1998 05:20:08 -0700 (PDT) (envelope-from owner-freebsd-net@FreeBSD.ORG) Received: from oslo.geco-prakla.slb.com (geos01.oslo.geco-prakla.slb.com [134.32.44.131]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id FAA09483 for ; Wed, 1 Jul 1998 05:20:00 -0700 (PDT) (envelope-from smoergrd@geos01.oslo.geco-prakla.slb.com) Received: from sunw132.geco-prakla.slb.com (sunw132 [134.32.45.120]) by oslo.geco-prakla.slb.com (8.8.8/8.6.9) with SMTP id OAA07064 for ; Wed, 1 Jul 1998 14:19:25 +0200 (MET DST) Received: by sunw132.geco-prakla.slb.com (SMI-8.6/SMI-SVR4) id OAA01822; Wed, 1 Jul 1998 14:19:24 +0200 To: net@FreeBSD.ORG Subject: Length of incoming UDP datagrams Organization: Schlumberger Geco-Prakla X-Disclaimer: I speak only for myself. From: smoergrd@oslo.geco-prakla.slb.com (Dag-Erling Coidan Smørgrav) Date: 01 Jul 1998 14:19:23 +0200 Message-ID: Lines: 24 X-Mailer: Gnus v5.3/Emacs 19.34 Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org Is there any way to obtain information about the length of an incoming UDP datagram short of actually receiving it in a large enough buffer? It seems strange to me that there should be no way to know ahead of time how much memory to allocate for a datagram. Of course, you can resort to trial and error: allocate a buffer, peek at the message, if the length returned by recvfrom() is shorter than the length of your buffer you're done, otherwise grow your buffer and try again; but it seems an extreme waste of CPU time to me (especially because most of what you're doing is copying data from kernel space to user space... and after you have ascertained the length of the datagram, you still have to remove it from the input buffer by performing an additional recvfrom(), this time without MSG_PEEK) I have also thought of doing a getsockopt(sd, SOL_SOCKET, SO_RCVBUF, &val, &len) and allocating a buffer of that size once and for all, but it always returns 0 (the alternative, of course, is to select a buffer size myself and force it upon the socket with setsockopt()). Anyway, is there a guarantee that no incoming datagram will exceed that size? And what happens to datagrams that *do* exceed that size? Are they silently dropped by the transport layer? DES (puzzled) -- Dag-Erling Smørgrav - smoergrd@oslo.geco-prakla.slb.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message