bb2d391712fb0208347ffc0b88abe146df14dc0a galt Fri Jun 21 18:21:50 2019 -0700 Adding Support for CIDR specification of subnets, e.g. 192.168.1.255/31. It still supports the older subnet format too, e.g. 192.168 diff --git src/inc/internet.h src/inc/internet.h index 1633799..c10f7e1 100644 --- src/inc/internet.h +++ src/inc/internet.h @@ -1,43 +1,60 @@ /* internet - some stuff for routines that use the internet * and aren't afraid to include some internet specific structures * and the like. See also net for stuff that is higher level. */ #ifndef INTERNET_H +#define INTERNET_H #include #include #include #include +struct cidr +/* Store CIDR address as IP and length */ + { + bits32 ip; + int subnetLength; + }; + bits32 internetHostIp(char *hostName); /* Get IP v4 address (in host byte order) for hostName. * Warn and return 0 if there's a problem. */ boolean internetFillInAddress(char *hostName, int port, struct sockaddr_in *address); /* Fill in address. Warn and return FALSE if can't. */ boolean internetIpToDottedQuad(bits32 ip, char dottedQuad[17]); /* Convert IP4 address in host byte order to dotted quad * notation. Warn and return FALSE if there's a * problem. */ boolean internetDottedQuadToIp(char *dottedQuad, bits32 *retIp); /* Convert dotted quad format address to IP4 address in * host byte order. Warn and return FALSE if there's a * problem. */ boolean internetIsDottedQuad(char *s); /* Returns TRUE if it looks like s is a dotted quad. */ void internetParseDottedQuad(char *dottedQuad, unsigned char quad[4]); /* Parse dotted quads into quad */ void internetUnpackIp(bits32 packed, unsigned char unpacked[4]); /* Convert from 32 bit to 4-byte format with most significant * byte first. */ -boolean internetIpInSubnet(unsigned char unpackedIp[4], - unsigned char subnet[4]); -/* Return true if unpacked IP address is in subnet. */ +bits32 internetPackIp(unsigned char unpacked[4]); +/* Convert from 4-byte format with most significant + * byte first to native 32-bit format. */ + +void internetCidrRange(struct cidr *cidr, bits32 *pStartIp, bits32 *pEndIp); +/* get range of CIDR formatted subnet as start and end IPs. */ + +boolean internetIpInSubnetCidr(unsigned char unpackedIp[4], struct cidr *cidr); +/* Return true if unpacked IP address is in subnet cidr. */ + +struct cidr *internetParseSubnetCidr(char *cidr); +/* parse input CIDR format IP for range or subnet */ #endif /* INTERNET_H */