pidgin/pidgin

Use GLib's byte-order macros.

2020-12-18, Elliott Sales de Andrade
503cfa50c8c3
Parents 0006f8158d6e
Children ce30656a8486
Use GLib's byte-order macros.

Testing Done:
Compile only.

Reviewed at https://reviews.imfreedom.org/r/282/
--- a/libpurple/nat-pmp.c Thu Dec 17 23:50:15 2020 -0600
+++ b/libpurple/nat-pmp.c Fri Dec 18 01:38:49 2020 -0600
@@ -152,7 +152,7 @@
sin = (struct sockaddr_in *)sa;
if ((sin->sin_addr.s_addr == INADDR_ANY) &&
mask &&
- (ntohl(((struct sockaddr_in *)mask)->sin_addr.s_addr) == 0L ||
+ (g_ntohl(((struct sockaddr_in *)mask)->sin_addr.s_addr) == 0L ||
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
mask->sa_len == 0
#else
@@ -297,7 +297,7 @@
/* Default port for NAT-PMP is 5351 */
if (gateway->sin_port != PMP_PORT)
- gateway->sin_port = htons(PMP_PORT);
+ gateway->sin_port = g_htons(PMP_PORT);
req_timeout.tv_sec = 0;
req_timeout.tv_usec = PMP_TIMEOUT;
@@ -374,8 +374,8 @@
purple_debug_info("nat-pmp", "Response received from NAT-PMP device:\n");
purple_debug_info("nat-pmp", "version: %d\n", resp.version);
purple_debug_info("nat-pmp", "opcode: %d\n", resp.opcode);
- purple_debug_info("nat-pmp", "resultcode: %d\n", ntohs(resp.resultcode));
- purple_debug_info("nat-pmp", "epoch: %d\n", ntohl(resp.epoch));
+ purple_debug_info("nat-pmp", "resultcode: %d\n", g_ntohs(resp.resultcode));
+ purple_debug_info("nat-pmp", "epoch: %d\n", g_ntohl(resp.epoch));
struct in_addr in;
in.s_addr = resp.address;
purple_debug_info("nat-pmp", "address: %s\n", inet_ntoa(in));
@@ -412,7 +412,7 @@
/* Default port for NAT-PMP is 5351 */
if (gateway->sin_port != PMP_PORT)
- gateway->sin_port = htons(PMP_PORT);
+ gateway->sin_port = g_htons(PMP_PORT);
resp = g_new0(PurplePmpMapResponse, 1);
@@ -425,9 +425,9 @@
memset(&req, 0, sizeof(PurplePmpMapRequest));
req.version = 0;
req.opcode = ((type == PURPLE_PMP_TYPE_UDP) ? PMP_MAP_OPCODE_UDP : PMP_MAP_OPCODE_TCP);
- req.privateport = htons(privateport); /* What a difference byte ordering makes...d'oh! */
- req.publicport = htons(publicport);
- req.lifetime = htonl(lifetime);
+ req.privateport = g_htons(privateport); /* What a difference byte ordering makes...d'oh! */
+ req.publicport = g_htons(publicport);
+ req.lifetime = g_htonl(lifetime);
/* The NAT-PMP spec says we should attempt to contact the gateway 9 times, doubling the time we wait each time.
* Even starting with a timeout of 0.1 seconds, that means that we have a total waiting of 204.6 seconds.
@@ -478,11 +478,11 @@
purple_debug_info("nat-pmp", "Response received from NAT-PMP device:\n");
purple_debug_info("nat-pmp", "version: %d\n", resp->version);
purple_debug_info("nat-pmp", "opcode: %d\n", resp->opcode);
- purple_debug_info("nat-pmp", "resultcode: %d\n", ntohs(resp->resultcode));
- purple_debug_info("nat-pmp", "epoch: %d\n", ntohl(resp->epoch));
- purple_debug_info("nat-pmp", "privateport: %d\n", ntohs(resp->privateport));
- purple_debug_info("nat-pmp", "publicport: %d\n", ntohs(resp->publicport));
- purple_debug_info("nat-pmp", "lifetime: %d\n", ntohl(resp->lifetime));
+ purple_debug_info("nat-pmp", "resultcode: %d\n", g_ntohs(resp->resultcode));
+ purple_debug_info("nat-pmp", "epoch: %d\n", g_ntohl(resp->epoch));
+ purple_debug_info("nat-pmp", "privateport: %d\n", g_ntohs(resp->privateport));
+ purple_debug_info("nat-pmp", "publicport: %d\n", g_ntohs(resp->publicport));
+ purple_debug_info("nat-pmp", "lifetime: %d\n", g_ntohl(resp->lifetime));
}
#endif
--- a/libpurple/network.c Thu Dec 17 23:50:15 2020 -0600
+++ b/libpurple/network.c Fri Dec 18 01:38:49 2020 -0600
@@ -114,7 +114,7 @@
struct ifconf ifc;
struct ifreq *ifr;
struct sockaddr_in *sinptr;
- guint32 lhost = htonl((127 << 24) + 1); /* 127.0.0.1 */
+ guint32 lhost = g_htonl((127 << 24) + 1); /* 127.0.0.1 */
long unsigned int add;
int source = fd;
@@ -144,7 +144,7 @@
sinptr = (struct sockaddr_in *)(gpointer)&ifr->ifr_addr;
if (sinptr->sin_addr.s_addr != lhost)
{
- add = ntohl(sinptr->sin_addr.s_addr);
+ add = g_ntohl(sinptr->sin_addr.s_addr);
g_snprintf(ip, 16, "%lu.%lu.%lu.%lu",
((add >> 24) & 255),
((add >> 16) & 255),
@@ -417,7 +417,7 @@
memset(&sockin, 0, sizeof(struct sockaddr_in));
sockin.sin_family = PF_INET;
- sockin.sin_port = htons(port);
+ sockin.sin_port = g_htons(port);
if (bind(listenfd, (struct sockaddr *)&sockin, sizeof(struct sockaddr_in)) != 0) {
purple_debug_warning("network", "bind: %s\n", g_strerror(errno));
@@ -532,7 +532,7 @@
return 0;
}
- return ntohs(addr.sin_port);
+ return g_ntohs(addr.sin_port);
}
gboolean
--- a/libpurple/protocols/bonjour/mdns_dns_sd.c Thu Dec 17 23:50:15 2020 -0600
+++ b/libpurple/protocols/bonjour/mdns_dns_sd.c Fri Dec 18 01:38:49 2020 -0600
@@ -279,7 +279,7 @@
args->full_service_name = g_strdup(fullname);
/* TODO: Should this be per resolver? */
- args->bb->port_p2pj = ntohs(port);
+ args->bb->port_p2pj = g_ntohs(port);
/* We don't want to hit the cleanup code */
return;
@@ -496,7 +496,7 @@
purple_debug_info("bonjour", "Registering presence on port %d\n", data->port_p2pj);
errorCode = DNSServiceRegister(&presence_sr, kDNSServiceInterfaceIndexAny,
0, bonjour_get_jid(data->account), LINK_LOCAL_RECORD_NAME,
- NULL, NULL, htons(data->port_p2pj), TXTRecordGetLength(&dns_data), TXTRecordGetBytesPtr(&dns_data),
+ NULL, NULL, g_htons(data->port_p2pj), TXTRecordGetLength(&dns_data), TXTRecordGetBytesPtr(&dns_data),
_mdns_service_register_callback, NULL);
break;
--- a/libpurple/protocols/irc/dcc_send.c Thu Dec 17 23:50:15 2020 -0600
+++ b/libpurple/protocols/irc/dcc_send.c Fri Dec 18 01:38:49 2020 -0600
@@ -65,7 +65,7 @@
return;
}
- l = htonl(purple_xfer_get_bytes_sent(xfer));
+ l = g_htonl(purple_xfer_get_bytes_sent(xfer));
result = purple_xfer_write(xfer, (guchar *)&l, sizeof(l));
if (result != sizeof(l)) {
purple_debug_error("irc", "unable to send acknowledgement: %s\n", g_strerror(errno));
@@ -133,7 +133,7 @@
nip = strtoul(token[i], NULL, 10);
if (nip) {
- addr.s_addr = htonl(nip);
+ addr.s_addr = g_htonl(nip);
xfer->ip = g_strdup(inet_ntoa(addr));
} else {
xfer->ip = g_strdup(token[i]);
@@ -184,7 +184,7 @@
break;
memcpy(&val, xd->rxqueue, sizeof(val));
- acked = ntohl(val);
+ acked = g_ntohl(val);
xd->rxlen -= 4;
if (xd->rxlen) {
--- a/libpurple/protocols/jabber/useravatar.c Thu Dec 17 23:50:15 2020 -0600
+++ b/libpurple/protocols/jabber/useravatar.c Fri Dec 18 01:38:49 2020 -0600
@@ -129,14 +129,14 @@
png->signature[5] == 0x0a &&
png->signature[6] == 0x1a &&
png->signature[7] == 0x0a &&
- ntohl(png->ihdr.length) == 0x0d &&
+ GUINT32_FROM_BE(png->ihdr.length) == 0x0d &&
png->ihdr.type[0] == 'I' &&
png->ihdr.type[1] == 'H' &&
png->ihdr.type[2] == 'D' &&
png->ihdr.type[3] == 'R') {
/* parse PNG header to get the size of the image (yes, this is required) */
- guint32 width = ntohl(png->ihdr.width);
- guint32 height = ntohl(png->ihdr.height);
+ guint32 width = GUINT32_FROM_BE(png->ihdr.width);
+ guint32 height = GUINT32_FROM_BE(png->ihdr.height);
PurpleXmlNode *data, *info;
char *lengthstring, *widthstring, *heightstring;
--- a/libpurple/protocols/zephyr/ZParseNot.c Thu Dec 17 23:50:15 2020 -0600
+++ b/libpurple/protocols/zephyr/ZParseNot.c Fri Dec 18 01:38:49 2020 -0600
@@ -147,8 +147,8 @@
if (ZReadAscii(ptr, end-ptr, (unsigned char *)&notice->z_uid,
sizeof(ZUnique_Id_t)) == ZERR_BADFIELD)
BAD_PACKET;
- notice->z_time.tv_sec = ntohl((unsigned long) notice->z_uid.tv.tv_sec);
- notice->z_time.tv_usec = ntohl((unsigned long) notice->z_uid.tv.tv_usec);
+ notice->z_time.tv_sec = GUINT64_FROM_BE((guint64)notice->z_uid.tv.tv_sec);
+ notice->z_time.tv_usec = GUINT64_FROM_BE((guint64)notice->z_uid.tv.tv_usec);
numfields--;
next_field (ptr);
}
@@ -158,7 +158,7 @@
if (numfields) {
if (ZReadAscii16(ptr, end-ptr, &notice->z_port) == ZERR_BADFIELD)
BAD_PACKET;
- notice->z_port = htons(notice->z_port);
+ notice->z_port = g_htons(notice->z_port);
numfields--;
next_field (ptr);
}
@@ -261,8 +261,8 @@
if (ZReadAscii(ptr, end-ptr, (unsigned char *)&notice->z_multiuid,
sizeof(ZUnique_Id_t)) == ZERR_BADFIELD)
BAD_PACKET;
- notice->z_time.tv_sec = ntohl((unsigned long) notice->z_multiuid.tv.tv_sec);
- notice->z_time.tv_usec = ntohl((unsigned long) notice->z_multiuid.tv.tv_usec);
+ notice->z_time.tv_sec = GUINT64_FROM_BE((guint64)notice->z_multiuid.tv.tv_sec);
+ notice->z_time.tv_usec = GUINT64_FROM_BE((guint64)notice->z_multiuid.tv.tv_usec);
numfields--;
next_field (ptr);
}
--- a/libpurple/protocols/zephyr/ZRetSubs.c Thu Dec 17 23:50:15 2020 -0600
+++ b/libpurple/protocols/zephyr/ZRetSubs.c Fri Dec 18 01:38:49 2020 -0600
@@ -24,7 +24,7 @@
if (!port) /* use default port */
port = __Zephyr_port;
- retval = ZMakeAscii16(asciiport, sizeof(asciiport), ntohs(port));
+ retval = ZMakeAscii16(asciiport, sizeof(asciiport), g_ntohs(port));
if (retval != ZERR_NONE)
return (retval);
--- a/libpurple/protocols/zephyr/Zinternal.c Thu Dec 17 23:50:15 2020 -0600
+++ b/libpurple/protocols/zephyr/Zinternal.c Fri Dec 18 01:38:49 2020 -0600
@@ -540,8 +540,8 @@
notice->z_uid.tv.tv_sec = realtime / G_USEC_PER_SEC;
notice->z_uid.tv.tv_usec =
realtime - notice->z_uid.tv.tv_sec * G_USEC_PER_SEC;
- notice->z_uid.tv.tv_sec = htonl((unsigned long)notice->z_uid.tv.tv_sec);
- notice->z_uid.tv.tv_usec = htonl((unsigned long)notice->z_uid.tv.tv_usec);
+ notice->z_uid.tv.tv_sec = GUINT64_TO_BE((guint64)notice->z_uid.tv.tv_sec);
+ notice->z_uid.tv.tv_usec = GUINT64_TO_BE((guint64)notice->z_uid.tv.tv_usec);
memcpy(&notice->z_uid.zuid_addr, &__My_addr, sizeof(__My_addr));
@@ -617,7 +617,7 @@
return (ZERR_HEADERLEN);
ptr += strlen(ptr)+1;
- if (ZMakeAscii16(ptr, end-ptr, ntohs(notice->z_port)) == ZERR_FIELDLEN)
+ if (ZMakeAscii16(ptr, end-ptr, g_ntohs(notice->z_port)) == ZERR_FIELDLEN)
return (ZERR_HEADERLEN);
ptr += strlen(ptr)+1;
@@ -776,9 +776,9 @@
partnotice.z_uid.tv.tv_usec =
realtime - partnotice.z_uid.tv.tv_sec * G_USEC_PER_SEC;
partnotice.z_uid.tv.tv_sec =
- htonl((unsigned long)partnotice.z_uid.tv.tv_sec);
+ GUINT64_TO_BE((guint64)partnotice.z_uid.tv.tv_sec);
partnotice.z_uid.tv.tv_usec =
- htonl((unsigned long)partnotice.z_uid.tv.tv_usec);
+ GUINT64_TO_BE((guint64)partnotice.z_uid.tv.tv_usec);
memcpy(&partnotice.z_uid.zuid_addr, &__My_addr, sizeof(__My_addr));
}
message_len = MIN(notice->z_message_len - offset, fragsize);