]>
git.ipfire.org Git - thirdparty/squid.git/blob - helpers/basic_auth/squid_radius_auth/radius-util.c
6e0e08e0390397efee8c8d64b7600bda8a490fe6
1 // 2008-05-14: rename to radius-util.* to avoid name clashes with squid util.*
5 * Remote Authentication Dial In User Service
8 * Livingston Enterprises, Inc.
9 * 6920 Koll Center Parkway
10 * Pleasanton, CA 94566
12 * Copyright 1992 Livingston Enterprises, Inc.
13 * Copyright 1997 Cistron Internet Services B.V.
15 * Permission to use, copy, modify, and distribute this software for any
16 * purpose and without fee is hereby granted, provided that this
17 * copyright and permission notice appear on all copies and supporting
18 * documentation, the name of Livingston Enterprises, Inc. not be used
19 * in advertising or publicity pertaining to distribution of the
20 * program without specific prior permission, and notice be given
21 * in supporting documentation that copying and distribution is by
22 * permission of Livingston Enterprises, Inc.
24 * Livingston Enterprises, Inc. makes no representations about
25 * the suitability of this software for any purpose. It is
26 * provided "as is" without express or implied warranty.
31 * util.c Miscellanous generic functions.
36 "@(#)util.c 1.5 Copyright 1992 Livingston Enterprises Inc\n"
37 " 2.1 Copyright 1997 Cistron Internet Services B.V.";
42 #include <sys/types.h>
45 #include <sys/socket.h>
51 #include <netinet/in.h>
77 #include "radius-util.h"
80 * Check for valid IP address in standard dot notation.
82 static int good_ipaddr(char *addr
)
89 while (*addr
!= '\0' && *addr
!= ' ') {
93 } else if (!isdigit(*addr
)) {
97 if (digit_count
> 3) {
103 if (dot_count
!= 3) {
111 * Return an IP address in host long notation from
112 * one supplied in standard dot notation.
114 static u_int32_t
ipstr2long(char *ip_str
)
123 ipaddr
= (u_int32_t
)0;
124 for (i
= 0;i
< 4;i
++) {
128 while (*ip_str
!= '.' && *ip_str
!= '\0' && count
< 4) {
129 if (!isdigit(*ip_str
)) {
130 return((u_int32_t
)0);
135 if (count
>= 4 || count
== 0) {
136 return((u_int32_t
)0);
139 cur_byte
= atoi(buf
);
140 if (cur_byte
< 0 || cur_byte
> 255) {
141 return((u_int32_t
)0);
144 ipaddr
= ipaddr
<< 8 | (u_int32_t
)cur_byte
;
150 * Return an IP address in host long notation from a host
151 * name or address in dot notation.
153 u_int32_t
get_ipaddr(char *host
)
157 if (good_ipaddr(host
) == 0) {
158 return(ipstr2long(host
));
159 } else if ((hp
= gethostbyname(host
)) == (struct hostent
*)NULL
) {
160 return((u_int32_t
)0);
162 return(ntohl(*(u_int32_t
*)hp
->h_addr
));