nfs-ganesha 1.4
|
00001 /* 00002 * libcidr.h - Header file for libCIDR 00003 */ 00004 00005 #ifndef __LIBCIDR_H 00006 #define __LIBCIDR_H 00007 00008 /* We need the fixed-size int types. See discussion below. */ 00009 #include <inttypes.h> 00010 /* We need the struct in[6]_addr defs */ 00011 #include <netinet/in.h> 00012 00013 00014 /* CONSTANTS */ 00015 /* String forms (cidr_to_str()) */ 00016 #define CIDR_NOFLAGS (0) 00017 #define CIDR_NOCOMPACT (1) /* Don't do :: compaction */ 00018 #define CIDR_VERBOSE (1<<1) /* Don't minimize leading zeros */ 00019 #define CIDR_USEV6 (1<<2) /* Use v6 form for v4 addresses */ 00020 #define CIDR_USEV4COMPAT (1<<3) /* Use v4-compat rather than v4-mapped */ 00021 #define CIDR_NETMASK (1<<4) /* Show netmask instead of pflen */ 00022 #define CIDR_ONLYADDR (1<<5) /* Only show the address */ 00023 #define CIDR_ONLYPFLEN (1<<6) /* Only show the pf/mask */ 00024 #define CIDR_WILDCARD (1<<7) /* Show wildcard-mask instead of netmask */ 00025 #define CIDR_FORCEV6 (1<<8) /* Force treating as v6 address */ 00026 #define CIDR_FORCEV4 (1<<9) /* Force treating as v4 address */ 00027 #define CIDR_REVERSE (1<<10) /* Return a DNS PTR name */ 00028 00029 /* Protocols */ 00030 #define CIDR_NOPROTO 0 00031 #define CIDR_IPV4 1 00032 #define CIDR_IPV6 2 00033 00034 /* Versioning info */ 00035 #define CIDR_VERSION "1.1" 00036 #define CIDR_RELEASE "release" 00037 #define CIDR_REVISION " (fullermd@over-yonder.net-20061125141312-f6mjjptgl4zqh6wt)" 00038 #define CIDR_VERSION_STR (CIDR_VERSION "-" CIDR_RELEASE CIDR_REVISION) 00039 00040 00041 /* DATA STRUCTURES */ 00042 /* 00043 * Discussion: 00044 * uint*_t are defined by POSIX and C99. We only probably NEED stdint.h 00045 * defines, since we don't need the various output stuff. However, for 00046 * now, we'll get all of inttypes.h because some older platforms only 00047 * have it, and define the uint*_t's in there (FreeBSD 4.x being the most 00048 * obvious one I care about). Revisit this down the line if necessary. 00049 * 00050 * Note that you should almost certainly not be messing with this 00051 * structure directly from external programs. Use the cidr_get_*() 00052 * functions to get a copy to work with. 00053 */ 00054 struct cidr_addr 00055 { 00056 int version; 00057 uint8_t addr[16]; 00058 uint8_t mask[16]; 00059 int proto; 00060 }; 00061 typedef struct cidr_addr CIDR; 00062 00063 00064 /* PROTOTYPES */ 00065 CIDR *cidr_addr_broadcast(const CIDR *); 00066 CIDR *cidr_addr_hostmax(const CIDR *); 00067 CIDR *cidr_addr_hostmin(const CIDR *); 00068 CIDR *cidr_addr_network(const CIDR *); 00069 CIDR *cidr_alloc(void); 00070 int cidr_contains(const CIDR *, const CIDR *); 00071 CIDR *cidr_dup(const CIDR *); 00072 int cidr_equals(const CIDR *, const CIDR *); 00073 void cidr_free(CIDR *); 00074 CIDR *cidr_from_inaddr(const struct in_addr *); 00075 CIDR *cidr_from_in6addr(const struct in6_addr *); 00076 CIDR *cidr_from_str(const char *); 00077 uint8_t *cidr_get_addr(const CIDR *); 00078 uint8_t *cidr_get_mask(const CIDR *); 00079 int cidr_get_pflen(const CIDR *); 00080 int cidr_get_proto(const CIDR *); 00081 int cidr_is_v4mapped(const CIDR *); 00082 CIDR **cidr_net_subnets(const CIDR *); 00083 CIDR *cidr_net_supernet(const CIDR *); 00084 const char *cidr_numaddr(const CIDR *); 00085 const char *cidr_numaddr_pflen(int); 00086 const char *cidr_numhost(const CIDR *); 00087 const char *cidr_numhost_pflen(int); 00088 struct in_addr *cidr_to_inaddr(const CIDR *, struct in_addr *); 00089 struct in6_addr *cidr_to_in6addr(const CIDR *, struct in6_addr *); 00090 char *cidr_to_str(const CIDR *, int); 00091 const char *cidr_version(void); 00092 00093 00094 #endif /* __LIBCIDR_H */