Re: sendmsg() arguments

kuznet@ms2.inr.ac.ru
Sun, 16 May 1999 18:40:16 +0400 (MSK DST)


Hello!

> In Linux 2.0.x and other systems sendmsg() in its second argument msg
> allows msg->msg_namelen to contain nonsense if msg->msg_name is NULL (what
> kinda makes sense -- NULL in msg->msg_name means that there is no address
> involved, so its size is meaningless). However 2.2.x checks msg->msg_namelen
> instead -- if it's nonzero, msg->msg_name is considered to be an address
> even if it's NULL (and therefore error is returned). Why?

Because I consider this as the only correct way.

sendmsg() behaviour is not prescribed by any standards
and this way is preferred, because:

- it is error prone: bad msg_name and msg_namelen!=0 is
usual application bug, showing malloc failure or memory corruption.
- it saves one statement if (name==NULL) namelen=0

BTW some time ago recvfrom() behaved in the same manner,
but broken way appeared to be described as valid in UNIX98,
so that it was changed.

Alexey Kuznetsov

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/