svn commit: r358655 - head/sbin/mount_nfs

Gleb Smirnoff glebius at freebsd.org
Thu Mar 12 17:54:22 UTC 2020


On Thu, Mar 05, 2020 at 11:15:04PM +0100, Dimitry Andric wrote:
D> > S> > Why don't just declare the buffer as:
D> > S> >
D> > S> >   struct if_msghdr buf;
D> > S> >
D> > S> > and then do:
D> > S> >
D> > S> >   nread = read(s, &buf, sizeof buf);
D> > S> >
D> > S> > ?  You are never reading more than one if_msghdr anyway, and then there
D> > S> > is no need to cast anything.
D> > S>
D> > S> My inspiration: route socket can return other messages (man 4 route)
D> > 
D> > Yes, exactly. We don't know what size next datagram is going to be.
D> 
D> Oh, in that case this code seems completely wrong.  How do you know the
D> full datagram will be delivered with one read() call?
D> 
D> If it always is, then there is no need to read more than the size of
D> struct if_msghdr, since you are not using any data beyond it.  So in
D> that case, you can suffice with read(..., sizeof(if_msghdr)).
D> 
D> If the read() call will return partial results, you must repeatedly call
D> it in a loop, until you either reach EOF, or have enough data. In that
D> case, a buffer with the size of if_msghdr is also enough, since you
D> never need to read beyond that.

Sorry for delayed answer. The routing socket is a datagram socket,
it isn't like TCP, it can't deliver partial datagrams. If we don't
supply enough space for datagram that arrived, it won't be delivered.

So the right solution is suppling plenty of space, but parse only
part we are interested in.

-- 
Gleb Smirnoff


More information about the svn-src-head mailing list