Re: Finding all IPv4 addresses associated with INADDR_ANY (?)

From: Chuck Swiger (cswiger_at_mac.com)
Date: 02/24/04

  • Next message: Petri Helenius: "Re: ng_netflow: testers are welcome"
    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"
    

  • Next message: Petri Helenius: "Re: ng_netflow: testers are welcome"

    Relevant Pages

    • Re: Problem with socket
      ... Be aware that those port numbers are part of the IANA-assigned range. ... socket operations on sockets for which there are no handles... ... The result of using comma lists is ... you have used the completely meaningless word "crash" to describe your ...
      (microsoft.public.vc.mfc)
    • RE: call is blocked in recvfrom() and no further proceedings in Win CE
      ... In windows CE, I'm able to send a request but I'm unable to receive it. ... Create another socket & bind with server IP address. ... > My program has to send request to service through port 5070(in this port only ...
      (microsoft.public.windowsce.embedded)
    • Re: ISA Event
      ... applying ISA SP1 resolved the issue. ... So it's worth asking - is this SBS ... > Web Proxy service failed to bind its socket to 192.168.4.9 port 443. ...
      (microsoft.public.backoffice.smallbiz2000)
    • Re: Freebsd IP Forwarding performance (question, and some info) [7-stable, current, em, smp]
      ... INADDR_ANY and a specific port. ... sendtoon a specific address and port on a socket that has been bound to ... bogus exit code) and adds a sleep after send failure. ... unless HZ is too small or the queue is too large. ...
      (freebsd-net)
    • Re: RMI binding to SAME port but DIFFERENT IP address on SAME host
      ... A socket is identified by its IP address, its port number, and its ... via the Sockets API. ... > port number for each listening interface, ...
      (comp.lang.java)