Back to index

glibc  2.9
Functions
get_myaddr.c File Reference
#include <rpc/types.h>
#include <rpc/clnt.h>
#include <rpc/pmap_prot.h>
#include <sys/socket.h>
#include <stdio.h>
#include <unistd.h>
#include <libintl.h>
#include <net/if.h>
#include <ifaddrs.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <arpa/inet.h>

Go to the source code of this file.

Functions

void get_myaddress (struct sockaddr_in *addr)

Function Documentation

void get_myaddress ( struct sockaddr_in addr)

Definition at line 62 of file get_myaddr.c.

{
  struct ifaddrs *ifa;

  if (getifaddrs (&ifa) != 0)
    {
      perror ("get_myaddress: getifaddrs");
      exit (1);
    }

  int loopback = 0;
  struct ifaddrs *run;

 again:
  run = ifa;
  while (run != NULL)
    {
      if ((run->ifa_flags & IFF_UP)
         && run->ifa_addr != NULL
         && run->ifa_addr->sa_family == AF_INET
         && (!(run->ifa_flags & IFF_LOOPBACK)
             || (loopback == 1 && (run->ifa_flags & IFF_LOOPBACK))))
       {
         *addr = *((struct sockaddr_in *) run->ifa_addr);
         addr->sin_port = htons (PMAPPORT);
         goto out;
       }

      run = run->ifa_next;
    }

  if (loopback == 0)
    {
      loopback = 1;
      goto again;
    }
 out:
  freeifaddrs (ifa);

  /* The function is horribly specified.  It does not return any error
     if no interface is up.  Probably this won't happen (at least
     loopback is there) but still...  */
}

Here is the call graph for this function:

Here is the caller graph for this function: