Subject: Re: CVS commit: src/sys
To: None <dyoung@netbsd.org>
From: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
List: source-changes
Date: 09/19/2007 20:23:16
hi,

the initializer of in_any.sin_addr seems to assume that INADDR_ANY is
a constant.  actually it might not be, depending on endian and
compilier optimizations.  i don't think it's a good idea to rely on
optimizations in this way.

YAMAMOTO Takashi

> Module Name:	src
> Committed By:	dyoung
> Date:		Wed Sep 19 04:33:45 UTC 2007
> 
> Modified Files:
> 	src/sys/kern: uipc_domain.c uipc_socket.c uipc_syscalls.c
> 	src/sys/netinet: in.h in_pcb.h in_proto.c ip_output.c raw_ip.c
> 	    tcp_usrreq.c
> 	src/sys/netinet6: icmp6.c in6_proto.c ip6_output.c raw_ip6.c
> 	src/sys/sys: domain.h socket.h socketvar.h
> 
> Log Message:
> 1) Introduce a new socket option, (SOL_SOCKET, SO_NOHEADER), that
>    tells a socket that it should both add a protocol header to tx'd
>    datagrams and remove the header from rx'd datagrams:
> 
>         int onoff = 1, s = socket(...);
>         setsockopt(s, SOL_SOCKET, SO_NOHEADER, &onoff);
> 
> 2) Add an implementation of (SOL_SOCKET, SO_NOHEADER) for raw IPv4
>    sockets.
> 
> 3) Reorganize the protocols' pr_ctloutput implementations a bit.
>    Consistently return ENOPROTOOPT when an option is unsupported,
>    and EINVAL if a supported option's arguments are incorrect.
>    Reorganize the flow of code so that it's more clear how/when
>    options are passed down the stack until they are handled.
> 
>    Shorten some pr_ctloutput staircases for readability.
> 
> 4) Extract common mbuf code into subroutines, add new sockaddr
>    methods, and introduce a new subroutine, fsocreate(), for reuse
>    later; use it first in sys_socket():
> 
> struct mbuf *m_getsombuf(struct socket *so)
> 
>         Create an mbuf and make its owner the socket `so'.
> 
> struct mbuf *m_intopt(struct socket *so, int val)
> 
>         Create an mbuf, make its owner the socket `so', put the
>         int `val' into it, and set its length to sizeof(int).
> 
> int fsocreate(..., int *fd)
> 
>         Create a socket, a la socreate(9), put the socket into the
>         given LWP's descriptor table, return the descriptor at `fd'
>         on success.
> 
> void *sockaddr_addr(struct sockaddr *sa, socklen_t *slenp)
> const void *sockaddr_const_addr(const struct sockaddr *sa, socklen_t *slenp)
> 
>         Extract a pointer to the address part of a sockaddr.  Write
>         the length of the address  part at `slenp', if `slenp' is
>         not NULL.
> 
> socklen_t sockaddr_getlen(const struct sockaddr *sa)
> 
>         Return the length of a sockaddr.  This just evaluates to
>         sa->sa_len.  I only add this for consistency with code that
>         appears in a portable userland library that I am going to
>         import.
> 
> const struct sockaddr *sockaddr_any(const struct sockaddr *sa)
> 
>         Return the "don't care" sockaddr in the same family as
>         `sa'.  This is the address a client should sobind(9) if it
>         does not care the source address and, if applicable, the
>         port et cetera that it uses.
> 
> const void *sockaddr_anyaddr(const struct sockaddr *sa, socklen_t *slenp)
> 
>         Return the "don't care" sockaddr in the same family as
>         `sa'.  This is the address a client should sobind(9) if it
>         does not care the source address and, if applicable, the
>         port et cetera that it uses.
> 
> 
> To generate a diff of this commit:
> cvs rdiff -r1.70 -r1.71 src/sys/kern/uipc_domain.c
> cvs rdiff -r1.141 -r1.142 src/sys/kern/uipc_socket.c
> cvs rdiff -r1.119 -r1.120 src/sys/kern/uipc_syscalls.c
> cvs rdiff -r1.80 -r1.81 src/sys/netinet/in.h
> cvs rdiff -r1.42 -r1.43 src/sys/netinet/in_pcb.h
> cvs rdiff -r1.88 -r1.89 src/sys/netinet/in_proto.c
> cvs rdiff -r1.183 -r1.184 src/sys/netinet/ip_output.c
> cvs rdiff -r1.99 -r1.100 src/sys/netinet/raw_ip.c
> cvs rdiff -r1.136 -r1.137 src/sys/netinet/tcp_usrreq.c
> cvs rdiff -r1.136 -r1.137 src/sys/netinet6/icmp6.c
> cvs rdiff -r1.78 -r1.79 src/sys/netinet6/in6_proto.c
> cvs rdiff -r1.120 -r1.121 src/sys/netinet6/ip6_output.c
> cvs rdiff -r1.86 -r1.87 src/sys/netinet6/raw_ip6.c
> cvs rdiff -r1.26 -r1.27 src/sys/sys/domain.h
> cvs rdiff -r1.88 -r1.89 src/sys/sys/socket.h
> cvs rdiff -r1.98 -r1.99 src/sys/sys/socketvar.h
> 
> Please note that diffs are not public domain; they are subject to the
> copyright notices on the relevant files.