PostgreSQL Source Code  git master
ip.h File Reference
#include <netdb.h>
#include <sys/socket.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.

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

◆ pg_freeaddrinfo_all()

void pg_freeaddrinfo_all ( int  hint_ai_family,
struct addrinfo *  ai 
)

Definition at line 82 of file ip.c.

83 {
84  if (hint_ai_family == AF_UNIX)
85  {
86  /* struct was built by getaddrinfo_unix (see pg_getaddrinfo_all) */
87  while (ai != NULL)
88  {
89  struct addrinfo *p = ai;
90 
91  ai = ai->ai_next;
92  free(p->ai_addr);
93  free(p);
94  }
95  }
96  else
97  {
98  /* struct was built by getaddrinfo() */
99  if (ai != NULL)
100  freeaddrinfo(ai);
101  }
102 }
#define free(a)
Definition: header.h:65

References free.

Referenced by ident_inet(), ListenServerPort(), parse_hba_auth_opt(), parse_hba_line(), PerformRadiusTransaction(), and PQconnectPoll().

◆ pg_getaddrinfo_all()

int pg_getaddrinfo_all ( const char *  hostname,
const char *  servname,
const struct addrinfo *  hintp,
struct addrinfo **  result 
)

Definition at line 53 of file ip.c.

55 {
56  int rc;
57 
58  /* not all versions of getaddrinfo() zero *result on failure */
59  *result = NULL;
60 
61  if (hintp->ai_family == AF_UNIX)
62  return getaddrinfo_unix(servname, hintp, result);
63 
64  /* NULL has special meaning to getaddrinfo(). */
65  rc = getaddrinfo((!hostname || hostname[0] == '\0') ? NULL : hostname,
66  servname, hintp, result);
67 
68  return rc;
69 }
static int getaddrinfo_unix(const char *path, const struct addrinfo *hintsp, struct addrinfo **result)
Definition: ip.c:153
static char * hostname
Definition: pg_regress.c:115

References getaddrinfo_unix(), and hostname.

Referenced by ident_inet(), ListenServerPort(), parse_hba_auth_opt(), parse_hba_line(), PerformRadiusTransaction(), and PQconnectPoll().

◆ pg_getnameinfo_all()

int pg_getnameinfo_all ( const struct sockaddr_storage *  addr,
int  salen,
char *  node,
int  nodelen,
char *  service,
int  servicelen,
int  flags 
)

Definition at line 114 of file ip.c.

118 {
119  int rc;
120 
121  if (addr && addr->ss_family == AF_UNIX)
122  rc = getnameinfo_unix((const struct sockaddr_un *) addr, salen,
123  node, nodelen,
124  service, servicelen,
125  flags);
126  else
127  rc = getnameinfo((const struct sockaddr *) addr, salen,
128  node, nodelen,
129  service, servicelen,
130  flags);
131 
132  if (rc != 0)
133  {
134  if (node)
135  strlcpy(node, "???", nodelen);
136  if (service)
137  strlcpy(service, "???", servicelen);
138  }
139 
140  return rc;
141 }
static int getnameinfo_unix(const struct sockaddr_un *sa, int salen, char *node, int nodelen, char *service, int servicelen, int flags)
Definition: ip.c:228
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
Definition: un.h:12

References getnameinfo_unix(), and strlcpy().

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