PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
test_ifaddrs.c File Reference
#include "postgres.h"
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include "libpq/ifaddr.h"
Include dependency graph for test_ifaddrs.c:

Go to the source code of this file.

Functions

static void print_addr (struct sockaddr *addr)
 
static void callback (struct sockaddr *addr, struct sockaddr *mask, void *unused)
 
int main (int argc, char *argv[])
 

Function Documentation

static void callback ( struct sockaddr *  addr,
struct sockaddr *  mask,
void *  unused 
)
static
int main ( int  argc,
char *  argv[] 
)

Definition at line 59 of file test_ifaddrs.c.

References callback(), NULL, pg_foreach_ifaddr(), and strerror().

60 {
61 #ifdef WIN32
62  WSADATA wsaData;
63 
64  if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
65  {
66  fprintf(stderr, "WSAStartup failed\n");
67  return 1;
68  }
69 #endif
70 
72  fprintf(stderr, "pg_foreach_ifaddr failed: %s\n", strerror(errno));
73  return 0;
74 }
int pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data)
Definition: ifaddr.c:562
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:49
#define NULL
Definition: c.h:226
const char * strerror(int errnum)
Definition: strerror.c:19
static void print_addr ( struct sockaddr *  addr)
static

Definition at line 19 of file test_ifaddrs.c.

References getnameinfo, NI_NUMERICHOST, and NULL.

Referenced by callback().

20 {
21  char buffer[256];
22  int ret,
23  len;
24 
25  switch (addr->sa_family)
26  {
27  case AF_INET:
28  len = sizeof(struct sockaddr_in);
29  break;
30 #ifdef HAVE_IPV6
31  case AF_INET6:
32  len = sizeof(struct sockaddr_in6);
33  break;
34 #endif
35  default:
36  len = sizeof(struct sockaddr_storage);
37  break;
38  }
39 
40  ret = getnameinfo(addr, len, buffer, sizeof(buffer), NULL, 0,
42  if (ret != 0)
43  printf("[unknown: family %d]", addr->sa_family);
44  else
45  printf("%s", buffer);
46 }
#define NI_NUMERICHOST
Definition: getaddrinfo.h:80
#define NULL
Definition: c.h:226
#define getnameinfo
Definition: getaddrinfo.h:153