Re: Finding all IPv4 addresses associated with INADDR_ANY (?)
From: Chuck Swiger (cswiger_at_mac.com)
Date: 02/24/04
- Previous message: Mike Silbersack: "Re: default socket receive buffer size, net.inet.tcp.recvspace (?)"
- In reply to: Ronald F. Guilmette: "Finding all IPv4 addresses associated with INADDR_ANY (?)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 24 Feb 2004 01:48:57 -0500 To: "Ronald F. Guilmette" <rfg@monkeys.com>
Ronald F. Guilmette wrote:
> 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 _______________________________________________ freebsd-net@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-net To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org"
- Previous message: Mike Silbersack: "Re: default socket receive buffer size, net.inet.tcp.recvspace (?)"
- In reply to: Ronald F. Guilmette: "Finding all IPv4 addresses associated with INADDR_ANY (?)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|