1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-22 12:22:45 +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:
Andres Freund
2017-10-01 15:36:14 -07:00
parent 1f2830f9df
commit 0ba99c84e8
20 changed files with 99 additions and 175 deletions

View File

@@ -18,7 +18,6 @@
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
@@ -33,6 +32,7 @@
#include "libpq/pqformat.h"
#include "libpq/scram.h"
#include "miscadmin.h"
#include "port/pg_bswap.h"
#include "replication/walsender.h"
#include "storage/ipc.h"
#include "utils/backend_random.h"
@@ -2840,7 +2840,7 @@ PerformRadiusTransaction(char *server, char *secret, char *portstr, char *identi
radius_packet *receivepacket = &radius_recv_pack;
char *radius_buffer = (char *) &radius_send_pack;
char *receive_buffer = (char *) &radius_recv_pack;
int32 service = htonl(RADIUS_AUTHENTICATE_ONLY);
int32 service = pg_hton32(RADIUS_AUTHENTICATE_ONLY);
uint8 *cryptvector;
int encryptedpasswordlen;
uint8 encryptedpassword[RADIUS_MAX_PASSWORD_LENGTH];
@@ -2948,7 +2948,7 @@ PerformRadiusTransaction(char *server, char *secret, char *portstr, char *identi
/* Length needs to be in network order on the wire */
packetlength = packet->length;
packet->length = htons(packet->length);
packet->length = pg_hton16(packet->length);
sock = socket(serveraddrs[0].ai_family, SOCK_DGRAM, 0);
if (sock == PGINVALID_SOCKET)
@@ -3074,19 +3074,19 @@ PerformRadiusTransaction(char *server, char *secret, char *portstr, char *identi
}
#ifdef HAVE_IPV6
if (remoteaddr.sin6_port != htons(port))
if (remoteaddr.sin6_port != pg_hton16(port))
#else
if (remoteaddr.sin_port != htons(port))
if (remoteaddr.sin_port != pg_hton16(port))
#endif
{
#ifdef HAVE_IPV6
ereport(LOG,
(errmsg("RADIUS response from %s was sent from incorrect port: %d",
server, ntohs(remoteaddr.sin6_port))));
server, pg_ntoh16(remoteaddr.sin6_port))));
#else
ereport(LOG,
(errmsg("RADIUS response from %s was sent from incorrect port: %d",
server, ntohs(remoteaddr.sin_port))));
server, pg_ntoh16(remoteaddr.sin_port))));
#endif
continue;
}
@@ -3098,11 +3098,11 @@ PerformRadiusTransaction(char *server, char *secret, char *portstr, char *identi
continue;
}
if (packetlength != ntohs(receivepacket->length))
if (packetlength != pg_ntoh16(receivepacket->length))
{
ereport(LOG,
(errmsg("RADIUS response from %s has corrupt length: %d (actual length %d)",
server, ntohs(receivepacket->length), packetlength)));
server, pg_ntoh16(receivepacket->length), packetlength)));
continue;
}