>> In Solaris, how does one bind a socket to a particular interface on a
>> Solaris machine with more than one Ethernet interface? I need to be
>> able to receive Unicast and Broadcast packets on all of the
>> interfaces, and to be able to determine _which_ interface it came in
>- Use the SIOCGIFADDR ioctl to map interfaces to addresses.
>- Bind to INADDR_ANY.
>- Use getsockname() to find out which address an accept()ed
> socket connected.
>#define SIOCGIFADDR _IOWR('i', 13, struct ifreq) /* get if address */
>ioctl(sock, SIOCGIFADDR, &ifr); /* something like this */
I'm interested in binding a socket to a device, and have looked at
the pcap source code. In pcap-linux.c, a generic socket address
stucture is used, and a string containing the name of the device to
use is placed in the data portion. This address structure is then
used in the call to bind. This seems odd to me and I haven't figured
out from the sock man page why this would work. The packet man page
suggests using a sockaddr_ll structure, which contains the hardware
address of the device, in the call to bind. Any idea why this first
method which seems bizzarre to me, would work?
12. binding sockets