diff options
author | Dmitry Kozlov <xeb@mail.ru> | 2014-06-03 21:33:23 +0400 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2014-06-03 21:33:23 +0400 |
commit | 093c53e3e08abb609cae6e58b1b438616c57c17f (patch) | |
tree | 10599557e5373498f773b57e0af84e7219875434 | |
parent | b002a1bdc060bf26497ea65174bfb66468560abb (diff) | |
download | accel-ppp-093c53e3e08abb609cae6e58b1b438616c57c17f.tar.gz accel-ppp-093c53e3e08abb609cae6e58b1b438616c57c17f.zip |
make IPv4 address to string conversions endian friendly
-rw-r--r-- | accel-pppd/ctrl/ipoe/dhcpv4.c | 56 | ||||
-rw-r--r-- | accel-pppd/extra/pppd_compat.c | 4 | ||||
-rw-r--r-- | accel-pppd/radius/packet.c | 4 | ||||
-rw-r--r-- | accel-pppd/utils.c | 3 |
4 files changed, 40 insertions, 27 deletions
diff --git a/accel-pppd/ctrl/ipoe/dhcpv4.c b/accel-pppd/ctrl/ipoe/dhcpv4.c index 35fc4688..1d3033ff 100644 --- a/accel-pppd/ctrl/ipoe/dhcpv4.c +++ b/accel-pppd/ctrl/ipoe/dhcpv4.c @@ -241,34 +241,42 @@ void dhcpv4_print_packet(struct dhcpv4_packet *pack, int relay, void (*print)(co print("[DHCPv4 %s%s xid=%x ", relay ? "relay " : "", msg_name[pack->msg_type - 1], pack->hdr->xid); - if (pack->hdr->ciaddr) + if (pack->hdr->ciaddr) { + in_addr_t addr = ntohl(pack->hdr->ciaddr); print("ciaddr=%i.%i.%i.%i ", - pack->hdr->ciaddr & 0xff, - (pack->hdr->ciaddr >> 8) & 0xff, - (pack->hdr->ciaddr >> 16) & 0xff, - (pack->hdr->ciaddr >> 24) & 0xff); - - if (pack->hdr->yiaddr) + (addr >> 24) & 0xff, + (addr >> 16) & 0xff, + (addr >> 8) & 0xff, + addr & 0xff); + } + + if (pack->hdr->yiaddr) { + in_addr_t addr = ntohl(pack->hdr->yiaddr); print("yiaddr=%i.%i.%i.%i ", - pack->hdr->yiaddr & 0xff, - (pack->hdr->yiaddr >> 8) & 0xff, - (pack->hdr->yiaddr >> 16) & 0xff, - (pack->hdr->yiaddr >> 24) & 0xff); - - if (pack->hdr->siaddr) + (addr >> 24) & 0xff, + (addr >> 16) & 0xff, + (addr >> 8) & 0xff, + addr & 0xff); + } + + if (pack->hdr->siaddr) { + in_addr_t addr = ntohl(pack->hdr->siaddr); print("siaddr=%i.%i.%i.%i ", - pack->hdr->siaddr & 0xff, - (pack->hdr->siaddr >> 8) & 0xff, - (pack->hdr->siaddr >> 16) & 0xff, - (pack->hdr->siaddr >> 24) & 0xff); - - if (pack->hdr->giaddr) + (addr >> 24) & 0xff, + (addr >> 16) & 0xff, + (addr >> 8) & 0xff, + addr & 0xff); + } + + if (pack->hdr->giaddr) { + in_addr_t addr = ntohl(pack->hdr->giaddr); print("giaddr=%i.%i.%i.%i ", - pack->hdr->giaddr & 0xff, - (pack->hdr->giaddr >> 8) & 0xff, - (pack->hdr->giaddr >> 16) & 0xff, - (pack->hdr->giaddr >> 24) & 0xff); - + (addr >> 24) & 0xff, + (addr >> 16) & 0xff, + (addr >> 8) & 0xff, + addr & 0xff); + } + print("chaddr=%02x:%02x:%02x:%02x:%02x:%02x ", pack->hdr->chaddr[0], pack->hdr->chaddr[1], diff --git a/accel-pppd/extra/pppd_compat.c b/accel-pppd/extra/pppd_compat.c index 7bdf5974..e005e8be 100644 --- a/accel-pppd/extra/pppd_compat.c +++ b/accel-pppd/extra/pppd_compat.c @@ -430,6 +430,7 @@ static void write_radattr(struct pppd_compat_pd *pd, struct rad_packet_t *pack) FILE *f; char *fname1, *fname2 = NULL; int i; + in_addr_t addr; fname1 = _malloc(PATH_MAX); if (!fname1) { @@ -478,7 +479,8 @@ static void write_radattr(struct pppd_compat_pd *pd, struct rad_packet_t *pack) 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 ace9f6e2..5bff60af 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 45e8709c..81b4c993 100644 --- a/accel-pppd/utils.c +++ b/accel-pppd/utils.c @@ -12,7 +12,8 @@ extern int urandom_fd; 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); } int __export u_readlong(long int *dst, const char *src, |