Re: about the bind action in lpf.c
Roy Marples
Sun Apr 21 01:15:39 2013
On 19/04/2013 12:09, jayce lee wrote:
In lpf.c, dhcpcd declares a variable named su.
union sockunion {
struct sockaddr sa;
struct sockaddr_in sin;
struct sockaddr_ll sll;
struct sockaddr_storage ss;
} su;
It only initialize the su.sll, but in the action of bind, the socket
fd bind to su.sa [1] with the addr_len of sizeof(su).
I'm confusing why we need a sockunion and bind to su.sa [1] with the
length of sizeof(su)?
It's how we pass sockaddr_ll to bind as bind only accepts sockaddr_sa.
It's an elegant method which avoids needless casting.
See here for a more complete answer:
http://stackoverflow.com/questions/1429645/how-to-cast-sockaddr-storage-and-avoid-breaking-strict-aliasing-rules
Thanks
Roy
Archive administrator: postmaster@marples.name