Given a socket which has been properly created, opened, and then bound to some port and the special INADDR_ANY ``wildcard'' address, I need to be able to them programatically find all of the IPv4 addresses that the socket was just bound to.
Try something like the following:
struct ifaddrs *if_ptr, *ifap;
if (getifaddrs(&ifap) == -1) {
fatal(strerror(errno));
/*NOTREACHED*/
} /* iterate over the list of interfaces on the machine */
for (if_ptr = ifap; if_ptr; if_ptr = if_ptr->ifa_next) {
switch (if_ptr->ifa_addr->sa_family) {
case AF_INET:
/* check that the interface is UP before we try to use it */
flags = if_ptr->ifa_flags;
if (!(flags & IFF_UP)) break;
/* do something here using if_ptr->ifa_addr */ case AF_INET6:
/* do something else for IPv6... */
}
}...although be sure to call ntohl() on the address to get things in the local byte-ordering...
-- -Chuck
_______________________________________________ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-net To unsubscribe, send any mail to "[EMAIL PROTECTED]"
