nfs-ganesha 1.4

cidr_num.c

Go to the documentation of this file.
00001 /*
00002  * Show some numbers
00003  */
00004 #ifdef HAVE_CONFIG_H
00005 #include "config.h"
00006 #endif
00007 
00008 #include <errno.h>
00009 #include <string.h>
00010 
00011 #include "cidr.h"
00012 #include "cidr_pow2_p.h"
00013 
00014 /* Number of total addresses in a given prefix length */
00015 const char *
00016 cidr_numaddr_pflen(int pflen)
00017 {
00018 
00019         if(pflen<0 || pflen>128)
00020         {
00021                 errno = EINVAL;
00022                 return(NULL);
00023         }
00024         return(__cidr_pow2[128-pflen]);
00025 }
00026 
00027 
00028 /* Addresses in a CIDR block */
00029 const char *
00030 cidr_numaddr(const CIDR *addr)
00031 {
00032         int pflen;
00033 
00034         if(addr==NULL)
00035         {
00036                 errno = EFAULT;
00037                 return(NULL);
00038         }
00039 
00040         pflen = cidr_get_pflen(addr);
00041         if(addr->proto==CIDR_IPV4)
00042                 pflen += 96;
00043 
00044         return(cidr_numaddr_pflen(pflen));
00045 }
00046 
00047 
00048 /* Hosts in a prefix length */
00049 const char *
00050 cidr_numhost_pflen(int pflen)
00051 {
00052 
00053         if(pflen<0 || pflen>128)
00054         {
00055                 errno = EINVAL;
00056                 return(NULL);
00057         }
00058         return(__cidr_pow2m2[128-pflen]);
00059 }
00060 
00061 
00062 /* Addresses in a CIDR block */
00063 const char *
00064 cidr_numhost(const CIDR *addr)
00065 {
00066         int pflen;
00067 
00068         if(addr==NULL)
00069         {
00070                 errno = EFAULT;
00071                 return(NULL);
00072         }
00073 
00074         pflen = cidr_get_pflen(addr);
00075         if(addr->proto==CIDR_IPV4)
00076                 pflen += 96;
00077 
00078         return(cidr_numhost_pflen(pflen));
00079 }