Back to index

glibc  2.9
Defines | Functions | Variables
test-ifaddrs.c File Reference
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ifaddrs.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "../test-skeleton.c"

Go to the source code of this file.


#define TEST_FUNCTION   do_test ()


static const char * addr_string (struct sockaddr *sa, char *buf, size_t size)
static int do_test (void)


static int failures

Define Documentation

#define TEST_FUNCTION   do_test ()

Definition at line 99 of file test-ifaddrs.c.

Function Documentation

static const char* addr_string ( struct sockaddr sa,
char *  buf,
size_t  size 
) [static]

Definition at line 31 of file test-ifaddrs.c.

  if (sa == NULL)
    return "<none>";

  switch (sa->sa_family)
    case AF_INET:
      return inet_ntop (AF_INET, &((struct sockaddr_in *) sa)->sin_addr,
                     buf, size);
    case AF_INET6:
      return inet_ntop (AF_INET6, &((struct sockaddr_in6 *) sa)->sin6_addr,
                     buf, size);
#ifdef AF_LINK
    case AF_LINK:
      return "<link>";
    case AF_UNSPEC:
      return "---";

#ifdef AF_PACKET
    case AF_PACKET:
      return "<packet>";

      printf ("sa_family=%d %08x\n", sa->sa_family,
             *(int*)&((struct sockaddr_in *) sa)->sin_addr.s_addr);
      return "<unexpected sockaddr family>";

Here is the call graph for this function:

Here is the caller graph for this function:

static int do_test ( void  ) [static]

Definition at line 66 of file test-ifaddrs.c.

  struct ifaddrs *ifaces, *ifa;

  if (getifaddrs (&ifaces) < 0)
      if (errno != ENOSYS)
         printf ("Couldn't get any interfaces: %s.\n", strerror (errno));
         exit (1);
      /* The function is simply not implemented.  */
      exit (0);

  puts ("\
Name           Flags   Address         Netmask         Broadcast/Destination");

  for (ifa = ifaces; ifa != NULL; ifa = ifa->ifa_next)
      char abuf[64], mbuf[64], dbuf[64];
      printf ("%-15s%#.4x  %-15s %-15s %-15s\n",
             ifa->ifa_name, ifa->ifa_flags,
             addr_string (ifa->ifa_addr, abuf, sizeof (abuf)),
             addr_string (ifa->ifa_netmask, mbuf, sizeof (mbuf)),
             addr_string (ifa->ifa_broadaddr, dbuf, sizeof (dbuf)));

  freeifaddrs (ifaces);

  return failures ? 1 : 0;

Here is the call graph for this function:

Variable Documentation

int failures [static]

Definition at line 28 of file test-ifaddrs.c.