diff options
| author | Denys Fedoryshchenko <denys.f@collabora.com> | 2026-09-01 09:08:47 +0300 |
|---|---|---|
| committer | Denys Fedoryshchenko <denys.f@collabora.com> | 2026-09-01 09:08:47 +0300 |
| commit | 7d4f8524f57ba0ac77e47171bebfc0370df667b1 (patch) | |
| tree | b3020b4e2aac0deac02721b7ebfe96c5ca4519b9 /accel-pppd/ipv6 | |
| parent | c12e1242c0ab98255661f84be3eb37148c00cb38 (diff) | |
| download | accel-ppp-7d4f8524f57ba0ac77e47171bebfc0370df667b1.tar.gz accel-ppp-7d4f8524f57ba0ac77e47171bebfc0370df667b1.zip | |
utils: centralize unaligned integer accessors
Diffstat (limited to 'accel-pppd/ipv6')
| -rw-r--r-- | accel-pppd/ipv6/dhcpv6.c | 4 | ||||
| -rw-r--r-- | accel-pppd/ipv6/dhcpv6_packet.c | 18 |
2 files changed, 6 insertions, 16 deletions
diff --git a/accel-pppd/ipv6/dhcpv6.c b/accel-pppd/ipv6/dhcpv6.c index 1d565a76..a0b159cf 100644 --- a/accel-pppd/ipv6/dhcpv6.c +++ b/accel-pppd/ipv6/dhcpv6.c @@ -23,6 +23,7 @@ #include "ipv6_dns.h" #include "events.h" #include "iputils.h" +#include "utils.h" #include "dhcpv6.h" @@ -229,8 +230,7 @@ static void insert_oro(struct dhcpv6_packet *reply, struct dhcpv6_option *opt) struct in6_addr dns[MAX_DNS_COUNT]; for (i = ntohs(opt->hdr->len) / 2, ptr = opt->hdr->data; i; i--, ptr += sizeof(code)) { - memcpy(&code, ptr, sizeof(code)); - code = ntohs(code); + code = u_read_be16(ptr); if (code == D6_OPTION_DNS_SERVERS) { dns_count = ipv6_dns_get(reply->ses, conf_dns, conf_dns_count, dns, MAX_DNS_COUNT); diff --git a/accel-pppd/ipv6/dhcpv6_packet.c b/accel-pppd/ipv6/dhcpv6_packet.c index 1bf297af..f1c168b6 100644 --- a/accel-pppd/ipv6/dhcpv6_packet.c +++ b/accel-pppd/ipv6/dhcpv6_packet.c @@ -4,6 +4,7 @@ #include "log.h" #include "memdebug.h" +#include "utils.h" #include "dhcpv6.h" @@ -34,14 +35,6 @@ static void print_dnssl(struct dhcpv6_option *opt, void (*print)(const char *fmt static void print_ia_prefix(struct dhcpv6_option *opt, void (*print)(const char *fmt, ...)); static void print_aftr_gw(struct dhcpv6_option *opt, void (*print)(const char *fmt, ...)); -static uint16_t dhcpv6_read_u16(const void *ptr) -{ - uint16_t value; - - memcpy(&value, ptr, sizeof(value)); - return ntohs(value); -} - static struct dict_option known_options[] = { { D6_OPTION_CLIENTID, "Client-ID", 1, sizeof(uint16_t), 0, print_clientid }, { D6_OPTION_SERVERID, "Server-ID", 0, sizeof(uint16_t), 0, print_clientid }, @@ -497,7 +490,7 @@ static void print_oro(struct dhcpv6_option *opt, void (*print)(const char *fmt, else print(" "); - code = dhcpv6_read_u16(ptr); + code = u_read_be16(ptr); for (dopt = known_options; dopt->code; dopt++) { if (code == dopt->code) break; @@ -531,13 +524,10 @@ static void print_uint8(struct dhcpv6_option *opt, void (*print)(const char *fmt static void print_time(struct dhcpv6_option *opt, void (*print)(const char *fmt, ...)) { - uint16_t val; - - if (ntohs(opt->hdr->len) < sizeof(val)) + if (ntohs(opt->hdr->len) < sizeof(uint16_t)) return; - memcpy(&val, opt->hdr->data, sizeof(val)); - print(" %u", ntohs(val)); + print(" %u", u_read_be16(opt->hdr->data)); } static void print_ipv6addr(struct dhcpv6_option *opt, void (*print)(const char *fmt, ...)) |
