[BusyBox] tftp: bind with no sin_family

Jason Schoon floydpink at gmail.com
Thu May 19 14:05:38 UTC 2005


The memset tells you how things are going to behave in the bind. The 
original code could be expanded as follows:

memset(&sa, 0, len);
sa.sin_family = AF_UNSPEC;
sa.sin_addr.s_addr = INADDR_ANY; (defined as 0L)

For most intents and purposes, AF_UNSPEC behaves very similar to AF_INET. 
Here is a good page describing the various address families:
http://www.opengroup.org/onlinepubs/009619199/getad.htm




On 5/19/05, Shaun Jackman <sjackman at gmail.com> wrote:
> 
> These two lines from tftp.c have me a little confused:
> memset(&sa, 0, len);
> bind(socketfd, (struct sockaddr *)&sa, len);
> With no sin_family value set, does this call mean anything to the
> kernel? The call succeeds under Linux at least, but I have no idea
> what effect the call has.
> 
> Could these lines be removed with no ill effect? Do they perhaps have
> the same semantics as the following:
> memset(&sa, 0, len);
> sa.sin_family = AF_INET;
> sa.sin_addr.s_addr = INADDR_ANY;
> bind(socketfd, (struct sockaddr *)&sa, len);
> If so, is the kernel inferring the sin_family type from the domain of
> the socket file descriptor?
> 
> This is mostly for my own curiosity. I really expected the bind call
> to fail and was rather surprised when I saw that it didn't. I'd
> appreciate someone putting my mind to rest.
> 
> Cheers,
> Shaun
> _______________________________________________
> busybox mailing list
> busybox at mail.busybox.net
> http://busybox.net/mailman/listinfo/busybox
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.busybox.net/pipermail/busybox/attachments/20050519/f5472fac/attachment-0002.htm 


More information about the busybox mailing list