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 <netinet/in.h>
#include <arpa/inet.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 58 of file test_ifaddrs.c.

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

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

Definition at line 18 of file test_ifaddrs.c.

References buffer, getnameinfo, NI_NUMERICHOST, and NULL.

Referenced by callback().

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