mirror of
https://github.com/postgres/postgres.git
synced 2025-08-31 17:02:12 +03:00
Replace most usages of ntoh[ls] and hton[sl] with pg_bswap.h.
All postgres internal usages are replaced, it's just libpq example usages that haven't been converted. External users of libpq can't generally rely on including postgres internal headers. Note that this includes replacing open-coded byte swapping of 64bit integers (using two 32 bit swaps) with a single 64bit swap. Where it looked applicable, I have removed netinet/in.h and arpa/inet.h usage, which previously provided the relevant functionality. It's perfectly possible that I missed other reasons for including those, the buildfarm will tell. Author: Andres Freund Discussion: https://postgr.es/m/20170927172019.gheidqy6xvlxb325@alap3.anarazel.de
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
|
||||
#include "getaddrinfo.h"
|
||||
#include "libpq/pqcomm.h" /* needed for struct sockaddr_storage */
|
||||
#include "port/pg_bsawp.h"
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
@@ -178,7 +179,7 @@ getaddrinfo(const char *node, const char *service,
|
||||
if (node)
|
||||
{
|
||||
if (node[0] == '\0')
|
||||
sin.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
sin.sin_addr.s_addr = pg_hton32(INADDR_ANY);
|
||||
else if (hints.ai_flags & AI_NUMERICHOST)
|
||||
{
|
||||
if (!inet_aton(node, &sin.sin_addr))
|
||||
@@ -221,13 +222,13 @@ getaddrinfo(const char *node, const char *service,
|
||||
else
|
||||
{
|
||||
if (hints.ai_flags & AI_PASSIVE)
|
||||
sin.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
sin.sin_addr.s_addr = pg_hton32(INADDR_ANY);
|
||||
else
|
||||
sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
sin.sin_addr.s_addr = pg_hton32(INADDR_LOOPBACK);
|
||||
}
|
||||
|
||||
if (service)
|
||||
sin.sin_port = htons((unsigned short) atoi(service));
|
||||
sin.sin_port = pg_hton16((unsigned short) atoi(service));
|
||||
|
||||
#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
|
||||
sin.sin_len = sizeof(sin);
|
||||
@@ -402,7 +403,7 @@ getnameinfo(const struct sockaddr *sa, int salen,
|
||||
if (sa->sa_family == AF_INET)
|
||||
{
|
||||
ret = snprintf(service, servicelen, "%d",
|
||||
ntohs(((struct sockaddr_in *) sa)->sin_port));
|
||||
pg_ntoh16(((struct sockaddr_in *) sa)->sin_port));
|
||||
}
|
||||
if (ret == -1 || ret >= servicelen)
|
||||
return EAI_MEMORY;
|
||||
|
Reference in New Issue
Block a user