cidr.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* $Id$ */
  2. /*
  3. * Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  4. * Copyright (c) 2013-2024 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. #pragma once
  20. #include "cache.h"
  21. struct tcpr_cidr_s {
  22. int family; /* AF_INET or AF_INET6 */
  23. union {
  24. u_int32_t network;
  25. struct tcpr_in6_addr network6;
  26. } u;
  27. int masklen;
  28. struct tcpr_cidr_s *next;
  29. };
  30. typedef struct tcpr_cidr_s tcpr_cidr_t;
  31. struct tcpr_cidrmap_s {
  32. tcpr_cidr_t *from;
  33. tcpr_cidr_t *to;
  34. struct tcpr_cidrmap_s *next;
  35. };
  36. typedef struct tcpr_cidrmap_s tcpr_cidrmap_t;
  37. int ip_in_cidr(const tcpr_cidr_t *, const unsigned long);
  38. int check_ip_cidr(tcpr_cidr_t *, const unsigned long);
  39. int check_ip6_cidr(tcpr_cidr_t *, const struct tcpr_in6_addr *addr);
  40. int parse_cidr(tcpr_cidr_t **, char *, char *delim);
  41. int parse_cidr_map(tcpr_cidrmap_t **, const char *);
  42. int parse_endpoints(tcpr_cidrmap_t **, tcpr_cidrmap_t **, const char *);
  43. void add_cidr(tcpr_cidr_t **, tcpr_cidr_t **);
  44. tcpr_cidr_t *new_cidr(void);
  45. tcpr_cidrmap_t *new_cidr_map(void);
  46. void destroy_cidr(tcpr_cidr_t *);
  47. void print_cidr(tcpr_cidr_t *);
  48. int ip6_in_cidr(const tcpr_cidr_t *mycidr, const struct tcpr_in6_addr *addr);
  49. int check_ip6_cidr(tcpr_cidr_t *, const struct tcpr_in6_addr *addr);