From a1bd18b8293aec56628ec8cf56684de5dbd6228f Mon Sep 17 00:00:00 2001 From: Dmitry Kozlov Date: Tue, 3 Jun 2014 21:33:23 +0400 Subject: make IPv4 address to string conversions endian friendly --- accel-pppd/extra/pppd_compat.c | 4 +++- accel-pppd/radius/packet.c | 4 +++- accel-pppd/utils.c | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/accel-pppd/extra/pppd_compat.c b/accel-pppd/extra/pppd_compat.c index 98240f65..7b1efca3 100644 --- a/accel-pppd/extra/pppd_compat.c +++ b/accel-pppd/extra/pppd_compat.c @@ -383,6 +383,7 @@ static void write_radattr(struct ppp_t *ppp, struct rad_packet_t *pack, int save FILE *f; char *fname1, *fname2 = NULL; int i; + in_addr_t addr; fname1 = _malloc(PATH_MAX); if (!fname1) { @@ -428,7 +429,8 @@ static void write_radattr(struct ppp_t *ppp, struct rad_packet_t *pack, int save fprintf(f, "\n"); break; case ATTR_TYPE_IPADDR: - fprintf(f, "%i.%i.%i.%i\n", attr->val.ipaddr & 0xff, (attr->val.ipaddr >> 8) & 0xff, (attr->val.ipaddr >> 16) & 0xff, (attr->val.ipaddr >> 24) & 0xff); + addr = ntohl(attr->val.ipaddr); + fprintf(f, "%i.%i.%i.%i\n", (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff); break; case ATTR_TYPE_DATE: fprintf(f, "%lu\n", attr->val.date); diff --git a/accel-pppd/radius/packet.c b/accel-pppd/radius/packet.c index 51220672..7729cbf6 100644 --- a/accel-pppd/radius/packet.c +++ b/accel-pppd/radius/packet.c @@ -284,6 +284,7 @@ void rad_packet_print(struct rad_packet_t *pack, struct rad_server_t *s, void (* uint64_t ifid; uint16_t u16[4]; } ifid_u; + in_addr_t addr; if (s) print("[RADIUS(%i) ", s->id); @@ -348,7 +349,8 @@ void rad_packet_print(struct rad_packet_t *pack, struct rad_server_t *s, void (* print("\"%s\"", attr->val.string); break; case ATTR_TYPE_IPADDR: - print("%i.%i.%i.%i", attr->val.ipaddr & 0xff, (attr->val.ipaddr >> 8) & 0xff, (attr->val.ipaddr >> 16) & 0xff, (attr->val.ipaddr >> 24) & 0xff); + addr = ntohl(attr->val.ipaddr); + print("%i.%i.%i.%i", (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff); break; case ATTR_TYPE_IFID: ifid_u.ifid = attr->val.ifid; diff --git a/accel-pppd/utils.c b/accel-pppd/utils.c index 491e6507..e45025f0 100644 --- a/accel-pppd/utils.c +++ b/accel-pppd/utils.c @@ -7,5 +7,6 @@ void __export u_inet_ntoa(in_addr_t addr, char *str) { - sprintf(str, "%i.%i.%i.%i", addr & 0xff, (addr >> 8) & 0xff, (addr >> 16) & 0xff, (addr >> 24) & 0xff); + addr = ntohl(addr); + sprintf(str, "%i.%i.%i.%i", (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff); } -- cgit v1.2.3