#include #include #include #include #include #include #include #include "common/ip.h"">

PostgreSQL Source Code: src/common/ip.c File Reference (original) (raw)

#include "[postgres.h](postgres%5F8h%5Fsource.html)"
#include <[unistd.h](unistd%5F8h%5Fsource.html)>
#include <sys/stat.h>
#include <[sys/socket.h](socket%5F8h%5Fsource.html)>
#include <[netdb.h](netdb%5F8h%5Fsource.html)>
#include <[netinet/in.h](in%5F8h%5Fsource.html)>
#include <[netinet/tcp.h](tcp%5F8h%5Fsource.html)>
#include <[arpa/inet.h](port%5F2win32%5F2arpa%5F2inet%5F8h%5Fsource.html)>
#include <[sys/file.h](file%5F8h%5Fsource.html)>
#include "[common/ip.h](ip%5F8h%5Fsource.html)"

Go to the source code of this file.

Functions
static int getaddrinfo_unix (const char *path, const struct addrinfo *hintsp, struct addrinfo **result)
static int getnameinfo_unix (const struct sockaddr_un *sa, int salen, char *node, int nodelen, char *service, int servicelen, int flags)
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)

getaddrinfo_unix()

static int getaddrinfo_unix ( const char * path, const struct addrinfo * hintsp, struct addrinfo ** result ) static

Definition at line 153 of file ip.c.

155{

156 struct addrinfo hints = {0};

157 struct addrinfo *aip;

159

160 *result = NULL;

161

162 if (strlen(path) >= sizeof(unp->sun_path))

163 return EAI_FAIL;

164

165 if (hintsp == NULL)

166 {

167 hints.ai_family = AF_UNIX;

168 hints.ai_socktype = SOCK_STREAM;

169 }

170 else

171 memcpy(&hints, hintsp, sizeof(hints));

172

173 if (hints.ai_socktype == 0)

174 hints.ai_socktype = SOCK_STREAM;

175

176 if (hints.ai_family != AF_UNIX)

177 {

178

179 return EAI_FAIL;

180 }

181

182 aip = calloc(1, sizeof(struct addrinfo));

183 if (aip == NULL)

184 return EAI_MEMORY;

185

187 if (unp == NULL)

188 {

190 return EAI_MEMORY;

191 }

192

193 aip->ai_family = AF_UNIX;

194 aip->ai_socktype = hints.ai_socktype;

195 aip->ai_protocol = hints.ai_protocol;

196 aip->ai_next = NULL;

197 aip->ai_canonname = NULL;

198 *result = aip;

199

201 aip->ai_addr = (struct sockaddr *) unp;

202 aip->ai_addrlen = sizeof(struct sockaddr_un);

203

205

206

207

208

209

210

211

212

213

214

215 if (path[0] == '@')

216 {

219 }

220

221 return 0;

222}

unsigned short sun_family

References calloc, free, sockaddr_un::sun_family, and sockaddr_un::sun_path.

Referenced by pg_getaddrinfo_all().

getnameinfo_unix()

static int getnameinfo_unix ( const struct sockaddr_un * sa, int salen, char * node, int nodelen, char * service, int servicelen, int flags ) static

Definition at line 228 of file ip.c.

232{

233 int ret;

234

235

236 if (sa == NULL || sa->sun_family != AF_UNIX ||

237 (node == NULL && service == NULL))

238 return EAI_FAIL;

239

240 if (node)

241 {

242 ret = snprintf(node, nodelen, "%s", "[local]");

243 if (ret < 0 || ret >= nodelen)

244 return EAI_MEMORY;

245 }

246

247 if (service)

248 {

249

250

251

252

253 if (sa->sun_path[0] == '\0' && sa->sun_path[1] != '\0')

254 ret = snprintf(service, servicelen, "@%s", sa->sun_path + 1);

255 else

256 ret = snprintf(service, servicelen, "%s", sa->sun_path);

257 if (ret < 0 || ret >= servicelen)

258 return EAI_MEMORY;

259 }

260

261 return 0;

262}

References snprintf.

Referenced by pg_getnameinfo_all().

pg_freeaddrinfo_all()

void pg_freeaddrinfo_all ( int hint_ai_family,
struct addrinfo * ai
)

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

59 *result = NULL;

60

61 if (hintp->ai_family == AF_UNIX)

63

64

66 servname, hintp, result);

67

68 return rc;

69}

static int getaddrinfo_unix(const char *path, const struct addrinfo *hintsp, struct addrinfo **result)

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)

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)

size_t strlcpy(char *dst, const char *src, size_t siz)

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(), log_status_format(), pg_stat_get_activity(), pg_stat_get_backend_client_addr(), and pg_stat_get_backend_client_port().