monitor: Use l_get_be16 and l_put_be16 instead of open coding it

This commit is contained in:
Marcel Holtmann 2018-11-01 21:27:04 +01:00
parent e4222d0ebe
commit a9c2d71874
2 changed files with 8 additions and 21 deletions

View File

@ -459,11 +459,8 @@ static int analyze_pcap(const char *pathname)
continue; continue;
} }
arphrd_type = L_GET_UNALIGNED((const uint16_t *) (buf + 2)); arphrd_type = l_get_be16(buf + 2);
arphrd_type = L_BE16_TO_CPU(arphrd_type); proto_type = l_get_be16(buf + 14);
proto_type = L_GET_UNALIGNED((const uint16_t *) (buf + 14));
proto_type = L_BE16_TO_CPU(proto_type);
switch (arphrd_type) { switch (arphrd_type) {
case ARPHRD_ETHER: case ARPHRD_ETHER:
@ -603,14 +600,9 @@ static int process_pcap(struct pcap *pcap, uint16_t id)
continue; continue;
} }
pkt_type = L_GET_UNALIGNED((const uint16_t *) buf); pkt_type = l_get_be16(buf);
pkt_type = L_BE16_TO_CPU(pkt_type); arphrd_type = l_get_be16(buf + 2);
proto_type = l_get_be16(buf + 14);
arphrd_type = L_GET_UNALIGNED((const uint16_t *) (buf + 2));
arphrd_type = L_BE16_TO_CPU(arphrd_type);
proto_type = L_GET_UNALIGNED((const uint16_t *) (buf + 14));
proto_type = L_BE16_TO_CPU(proto_type);
switch (arphrd_type) { switch (arphrd_type) {
case ARPHRD_ETHER: case ARPHRD_ETHER:

View File

@ -4049,14 +4049,9 @@ static void store_packet(struct nlmon *nlmon, const struct timeval *tv,
memset(sll_hdr, 0, sizeof(sll_hdr)); memset(sll_hdr, 0, sizeof(sll_hdr));
pkt_type = L_CPU_TO_BE16(pkt_type); l_put_be16(pkt_type, buf);
L_PUT_UNALIGNED(pkt_type, (uint16_t *) buf); l_put_be16(arphrd_type, buf + 2);
l_put_be16(proto_type, buf + 14);
arphrd_type = L_CPU_TO_BE16(arphrd_type);
L_PUT_UNALIGNED(arphrd_type, (uint16_t *) (buf + 2));
proto_type = L_CPU_TO_BE16(proto_type);
L_PUT_UNALIGNED(proto_type, (uint16_t *) (buf + 14));
pcap_write(nlmon->pcap, tv, &sll_hdr, sizeof(sll_hdr), data, size); pcap_write(nlmon->pcap, tv, &sll_hdr, sizeof(sll_hdr), data, size);
} }