From 0ba99c84e8c7138143059b281063d4cca5a2bfea Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Sun, 1 Oct 2017 15:36:14 -0700 Subject: 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 --- src/backend/postmaster/postmaster.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/backend/postmaster') diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 8a2cc2fc2b4..2b2b993e2cf 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -74,8 +74,6 @@ #include #include #include -#include -#include #include #include @@ -107,6 +105,7 @@ #include "miscadmin.h" #include "pg_getopt.h" #include "pgstat.h" +#include "port/pg_bswap.h" #include "postmaster/autovacuum.h" #include "postmaster/bgworker_internals.h" #include "postmaster/fork_process.h" @@ -1072,7 +1071,7 @@ PostmasterMain(int argc, char *argv[]) "_postgresql._tcp.", NULL, NULL, - htons(PostPortNumber), + pg_hton16(PostPortNumber), 0, NULL, NULL, @@ -1966,7 +1965,7 @@ ProcessStartupPacket(Port *port, bool SSLdone) return STATUS_ERROR; } - len = ntohl(len); + len = pg_ntoh32(len); len -= 4; if (len < (int32) sizeof(ProtocolVersion) || @@ -2002,7 +2001,7 @@ ProcessStartupPacket(Port *port, bool SSLdone) * The first field is either a protocol version number or a special * request code. */ - port->proto = proto = ntohl(*((ProtocolVersion *) buf)); + port->proto = proto = pg_ntoh32(*((ProtocolVersion *) buf)); if (proto == CANCEL_REQUEST_CODE) { @@ -2281,8 +2280,8 @@ processCancelRequest(Port *port, void *pkt) int i; #endif - backendPID = (int) ntohl(canc->backendPID); - cancelAuthCode = (int32) ntohl(canc->cancelAuthCode); + backendPID = (int) pg_ntoh32(canc->backendPID); + cancelAuthCode = (int32) pg_ntoh32(canc->cancelAuthCode); /* * See if we have a matching backend. In the EXEC_BACKEND case, we can no -- cgit v1.2.3