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

Go to the source code of this file.

Functions

int pg_getaddrinfo_all (const char *hostname, const char *servname, const struct addrinfo *hintp, struct addrinfo **result)
 
void pg_freeaddrinfo_all (int hint_ai_family, struct addrinfo *ai)
 
int pg_getnameinfo_all (const struct sockaddr_storage *addr, int salen, char *node, int nodelen, char *service, int servicelen, int flags)
 

Function Documentation

void pg_freeaddrinfo_all ( int  hint_ai_family,
struct addrinfo ai 
)

Definition at line 88 of file ip.c.

References addrinfo::ai_addr, addrinfo::ai_next, free, freeaddrinfo, and NULL.

Referenced by connectDBStart(), ident_inet(), parse_hba_auth_opt(), parse_hba_line(), PerformRadiusTransaction(), pgstat_init(), release_all_addrinfo(), and StreamServerPort().

89 {
90 #ifdef HAVE_UNIX_SOCKETS
91  if (hint_ai_family == AF_UNIX)
92  {
93  /* struct was built by getaddrinfo_unix (see pg_getaddrinfo_all) */
94  while (ai != NULL)
95  {
96  struct addrinfo *p = ai;
97 
98  ai = ai->ai_next;
99  free(p->ai_addr);
100  free(p);
101  }
102  }
103  else
104 #endif /* HAVE_UNIX_SOCKETS */
105  {
106  /* struct was built by getaddrinfo() */
107  if (ai != NULL)
108  freeaddrinfo(ai);
109  }
110 }
#define freeaddrinfo
Definition: getaddrinfo.h:143
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
struct addrinfo * ai_next
Definition: getaddrinfo.h:109
struct sockaddr * ai_addr
Definition: getaddrinfo.h:107
int pg_getaddrinfo_all ( const char *  hostname,
const char *  servname,
const struct addrinfo hintp,
struct addrinfo **  result 
)

Definition at line 57 of file ip.c.

References addrinfo::ai_family, getaddrinfo, and NULL.

Referenced by connectDBStart(), ident_inet(), parse_hba_auth_opt(), parse_hba_line(), PerformRadiusTransaction(), pgstat_init(), and StreamServerPort().

59 {
60  int rc;
61 
62  /* not all versions of getaddrinfo() zero *result on failure */
63  *result = NULL;
64 
65 #ifdef HAVE_UNIX_SOCKETS
66  if (hintp->ai_family == AF_UNIX)
67  return getaddrinfo_unix(servname, hintp, result);
68 #endif
69 
70  /* NULL has special meaning to getaddrinfo(). */
71  rc = getaddrinfo((!hostname || hostname[0] == '\0') ? NULL : hostname,
72  servname, hintp, result);
73 
74  return rc;
75 }
#define getaddrinfo
Definition: getaddrinfo.h:138
#define NULL
Definition: c.h:229
static char * hostname
Definition: pg_regress.c:88
int ai_family
Definition: getaddrinfo.h:103
int pg_getnameinfo_all ( const struct sockaddr_storage addr,
int  salen,
char *  node,
int  nodelen,
char *  service,
int  servicelen,
int  flags 
)

Definition at line 122 of file ip.c.

References getnameinfo, and strlcpy().

Referenced by BackendInitialize(), check_hostname(), ClientAuthentication(), connectFailureMessage(), fill_hba_line(), ident_inet(), inet_client_addr(), inet_client_port(), inet_server_addr(), inet_server_port(), pg_stat_get_activity(), pg_stat_get_backend_client_addr(), pg_stat_get_backend_client_port(), and StreamServerPort().

126 {
127  int rc;
128 
129 #ifdef HAVE_UNIX_SOCKETS
130  if (addr && addr->ss_family == AF_UNIX)
131  rc = getnameinfo_unix((const struct sockaddr_un *) addr, salen,
132  node, nodelen,
133  service, servicelen,
134  flags);
135  else
136 #endif
137  rc = getnameinfo((const struct sockaddr *) addr, salen,
138  node, nodelen,
139  service, servicelen,
140  flags);
141 
142  if (rc != 0)
143  {
144  if (node)
145  strlcpy(node, "???", nodelen);
146  if (service)
147  strlcpy(service, "???", servicelen);
148  }
149 
150  return rc;
151 }
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
#define getnameinfo
Definition: getaddrinfo.h:153