PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
ip.h File Reference
#include "getaddrinfo.h"
#include "libpq/pqcomm.h"
Include dependency graph for ip.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define IS_AF_UNIX(fam)   (0)
 

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)
 

Macro Definition Documentation

Function Documentation

void pg_freeaddrinfo_all ( int  hint_ai_family,
struct addrinfo ai 
)

Definition at line 89 of file ip.c.

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

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

90 {
91 #ifdef HAVE_UNIX_SOCKETS
92  if (hint_ai_family == AF_UNIX)
93  {
94  /* struct was built by getaddrinfo_unix (see pg_getaddrinfo_all) */
95  while (ai != NULL)
96  {
97  struct addrinfo *p = ai;
98 
99  ai = ai->ai_next;
100  free(p->ai_addr);
101  free(p);
102  }
103  }
104  else
105 #endif /* HAVE_UNIX_SOCKETS */
106  {
107  /* struct was built by getaddrinfo() */
108  if (ai != NULL)
109  freeaddrinfo(ai);
110  }
111 }
#define freeaddrinfo
Definition: getaddrinfo.h:143
#define free(a)
Definition: header.h:60
#define NULL
Definition: c.h:226
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 58 of file ip.c.

References addrinfo::ai_family, getaddrinfo, and NULL.

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

60 {
61  int rc;
62 
63  /* not all versions of getaddrinfo() zero *result on failure */
64  *result = NULL;
65 
66 #ifdef HAVE_UNIX_SOCKETS
67  if (hintp->ai_family == AF_UNIX)
68  return getaddrinfo_unix(servname, hintp, result);
69 #endif
70 
71  /* NULL has special meaning to getaddrinfo(). */
72  rc = getaddrinfo((!hostname || hostname[0] == '\0') ? NULL : hostname,
73  servname, hintp, result);
74 
75  return rc;
76 }
#define getaddrinfo
Definition: getaddrinfo.h:138
#define NULL
Definition: c.h:226
static char * hostname
Definition: pg_regress.c:86
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 123 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(), and pg_stat_get_backend_client_port().

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