Codebase list arping / 2efe32f
More checking for short packets Thomas Habets 2 years ago
1 changed file(s) with 33 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
1414 *
1515 */
1616 /*
17 * Copyright (C) 2000-2019 Thomas Habets <thomas@habets.se>
17 * Copyright (C) 2000-2022 Thomas Habets <thomas@habets.se>
1818 *
1919 * This program is free software; you can redistribute it and/or modify
2020 * it under the terms of the GNU General Public License as published by
13251325 getclock(&arrival);
13261326
13271327 if (vlan_tag >= 0) {
1328 if (h->caplen < LIBNET_802_1Q_H + LIBNET_ARP_H + 2*(ETH_ALEN + 4)) {
1329 return;
1330 }
13281331 veth = (void*)packet;
13291332 harp = (void*)((char*)veth + LIBNET_802_1Q_H);
13301333 pkt_srcmac = veth->vlan_shost;
13311334 } else {
1332 // Short packet.
13331335 if (h->caplen < LIBNET_ETH_H + LIBNET_ARP_H + 2*(ETH_ALEN + 4)) {
13341336 return;
13351337 }
1336
13371338 heth = (void*)packet;
13381339 harp = (void*)((char*)heth + LIBNET_ETH_H);
13391340 pkt_srcmac = heth->_802_3_shost;
1340 // Wrong length of hardware address.
1341 if (harp->ar_hln != ETH_ALEN) {
1342 return;
1343 }
1344
1345 // Wrong length of protocol address.
1346 if (harp->ar_pln != 4) {
1347 return;
1348 }
1349 }
1341 }
1342 if (verbose > 3) {
1343 printf("arping: ... good length\n");
1344 }
1345
1346 // Wrong length of hardware address.
1347 if (harp->ar_hln != ETH_ALEN) {
1348 return;
1349 }
1350 if (verbose > 3) {
1351 printf("arping: ... L2 addr len is correct\n");
1352 }
1353
1354 // Wrong length of protocol address.
1355 if (harp->ar_pln != 4) {
1356 return;
1357 }
1358 if (verbose > 3) {
1359 printf("arping: ... L3 addr len is correct\n");
1360 }
13501361
13511362 // ARP reply.
13521363 if (htons(harp->ar_op) != ARPOP_REPLY) {
15031514 getclock(&arrival);
15041515
15051516 if (vlan_tag >= 0) {
1517 if (h->caplen < LIBNET_ETH_H + LIBNET_IPV4_H + LIBNET_ICMPV4_H) {
1518 return;
1519 }
15061520 veth = (void*)packet;
15071521 hip = (void*)((char*)veth + LIBNET_802_1Q_H);
15081522 hicmp = (void*)((char*)hip + LIBNET_IPV4_H);
15091523 pkt_srcmac = veth->vlan_shost;
15101524 pkt_dstmac = veth->vlan_dhost;
15111525 } else {
1526 if (h->caplen < LIBNET_ETH_H + LIBNET_ARP_H + LIBNET_ICMPV4_H) {
1527 return;
1528 }
15121529 heth = (void*)packet;
15131530 hip = (void*)((char*)heth + LIBNET_ETH_H);
15141531 hicmp = (void*)((char*)hip + LIBNET_IPV4_H);
15151532 pkt_srcmac = heth->_802_3_shost;
15161533 pkt_dstmac = heth->_802_3_dhost;
1534 }
1535 if (verbose > 3) {
1536 printf("arping: ... good length\n");
15171537 }
15181538
15191539 // Dest MAC must be me.