/[radius]/radius/lib/iputil.c
ViewVC logotype

Diff of /radius/lib/iputil.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by gray, Sun Nov 23 19:08:56 2003 UTC revision 1.6 by gray, Tue Nov 25 15:52:29 2003 UTC
# Line 39  Line 39 
39  int resolve_hostnames = 1;  int resolve_hostnames = 1;
40    
41  /*  /*
42     * Check for valid IP address in standard dot notation.
43     */
44    static int
45    good_ipaddr(const char *addr)
46    {
47            int     dot_count;
48            int     digit_count;
49    
50            dot_count = 0;
51            digit_count = 0;
52            while (*addr != 0 && *addr != ' ') {
53                    if (*addr == '.') {
54                            if (++dot_count > 3)
55                                    break;
56                            digit_count = 0;
57                    } else if (!(isdigit(*addr) && ++digit_count <= 3)) {
58                            return -1;
59                    }
60                    addr++;
61            }
62    
63            return (dot_count != 3);
64    }
65    
66    /*
67   *      Return a printable host name (or IP address in dot notation)   *      Return a printable host name (or IP address in dot notation)
68   *      for the supplied IP address.   *      for the supplied IP address.
69   */   */
# Line 72  ip_gethostname(UINT4 ipaddr, char *nameb Line 97  ip_gethostname(UINT4 ipaddr, char *nameb
97   * name or address in dot notation.   * name or address in dot notation.
98   */   */
99  UINT4  UINT4
100  ip_gethostaddr(char *host)  ip_gethostaddr(const char *host)
101  {  {
102          struct hostent  *hp, hent;          struct hostent  *hp, hent;
103          char buffer[512];          char buffer[512];
# Line 88  ip_gethostaddr(char *host) Line 113  ip_gethostaddr(char *host)
113  }  }
114    
115  /*  /*
  * Check for valid IP address in standard dot notation.  
  */  
 int  
 good_ipaddr(char *addr)  
 {  
         int     dot_count;  
         int     digit_count;  
   
         dot_count = 0;  
         digit_count = 0;  
         while (*addr != 0 && *addr != ' ') {  
                 if (*addr == '.') {  
                         if (++dot_count > 3)  
                                 break;  
                         digit_count = 0;  
                 } else if (!(isdigit(*addr) && ++digit_count <= 3)) {  
                         return -1;  
                 }  
                 addr++;  
         }  
   
         return (dot_count != 3);  
 }  
   
 /*  
116   * Return an IP address in standard dot notation for the   * Return an IP address in standard dot notation for the
117   * provided address in host long notation.   * provided address in host long notation.
118   */   */
# Line 132  ip_iptostr(UINT4 ipaddr, char *buffer) Line 132  ip_iptostr(UINT4 ipaddr, char *buffer)
132   *      one supplied in standard dot notation.   *      one supplied in standard dot notation.
133   */   */
134  UINT4  UINT4
135  ip_strtoip(char *ip_str)  ip_strtoip(const char *ip_str)
136  #ifdef HAVE_INET_ATON  #ifdef HAVE_INET_ATON
137  {  {
138          struct in_addr in;          struct in_addr in;
# Line 178  ip_strtoip(char *ip_str) Line 178  ip_strtoip(char *ip_str)
178  #endif  #endif
179    
180  int  int
181  ip_getnetaddr(char *str, NETDEF *netdef)  ip_getnetaddr(const char *str, NETDEF *netdef)
182  {  {
183          char *p = strchr(str, '/');          char *p = strchr(str, '/');
184          if (!p) {          if (!p) {
# Line 212  ip_getnetaddr(char *str, NETDEF *netdef) Line 212  ip_getnetaddr(char *str, NETDEF *netdef)
212  }  }
213    
214  int  int
215  ip_addr_in_net_p(NETDEF *netdef, UINT4 ipaddr)  ip_addr_in_net_p(const NETDEF *netdef, UINT4 ipaddr)
216  {  {
217          return netdef->ipaddr == (ipaddr & netdef->netmask);          return netdef->ipaddr == (ipaddr & netdef->netmask);
218  }  }

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26