ethernet.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* $Id$ */
  2. /*
  3. * Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  4. * Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  5. *
  6. * The Tcpreplay Suite of tools is free software: you can redistribute it
  7. * and/or modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or with the authors permission any later version.
  10. *
  11. * The Tcpreplay Suite is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with the Tcpreplay Suite. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <assert.h>
  20. #include <string.h>
  21. #include "ethernet.h"
  22. /*
  23. * Takes a ptr to an ethernet address and returns
  24. * 1 if it is unicast or 0 if it is multicast or
  25. * broadcast. As per RFC7042.
  26. */
  27. int
  28. is_unicast_ethernet(tcpeditdlt_t *ctx, const u_char *ether)
  29. {
  30. assert(ctx);
  31. assert(ether);
  32. /* ff:ff:ff:ff:ff:ff - broadcast */
  33. if (memcmp(ether, BROADCAST_MAC, ETHER_ADDR_LEN) == 0)
  34. return 0;
  35. /* 01:00:5e:(00:00:00-7f:ff:ff) - IPv4 Multicast and MLPS Multicast */
  36. if (memcmp(&ether[0], IPV4_MULTICAST_MAC, 3) == 0)
  37. return 0;
  38. /* 33:33 - IPv6 Multicast */
  39. if (memcmp(&ether[0], IPV6_MULTICAST_MAC, 2) == 0)
  40. return 0;
  41. /*
  42. * 00:00:5e:(00:01:00 – 00:01:ff) - IPv4 Virtual Router Redundancy Protocol
  43. * 00:00:5e:(00:02:00 – 00:02:ff) - IPv6 Virtual Router Redundancy Protocol
  44. */
  45. if (memcmp(&ether[0], IPV4_VRRP, 5) == 0
  46. || memcmp(&ether[0], IPV6_VRRP, 5) == 0)
  47. return 0;
  48. /* everything else is unicast */
  49. return 1;
  50. }