]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/auth/basic/RADIUS/radius-util.cc
2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 // 2008-05-14: rename to radius-util.* to avoid name clashes with squid util.*
13 * Remote Authentication Dial In User Service
16 * Livingston Enterprises, Inc.
17 * 6920 Koll Center Parkway
18 * Pleasanton, CA 94566
20 * Copyright 1992 Livingston Enterprises, Inc.
21 * Copyright 1997 Cistron Internet Services B.V.
23 * Permission to use, copy, modify, and distribute this software for any
24 * purpose and without fee is hereby granted, provided that this
25 * copyright and permission notice appear on all copies and supporting
26 * documentation, the name of Livingston Enterprises, Inc. not be used
27 * in advertising or publicity pertaining to distribution of the
28 * program without specific prior permission, and notice be given
29 * in supporting documentation that copying and distribution is by
30 * permission of Livingston Enterprises, Inc.
32 * Livingston Enterprises, Inc. makes no representations about
33 * the suitability of this software for any purpose. It is
34 * provided "as is" without express or implied warranty.
39 * util.c Miscellaneous generic functions.
44 "@(#)util.c 1.5 Copyright 1992 Livingston Enterprises Inc\n"
45 " 2.1 Copyright 1997 Cistron Internet Services B.V.";
48 #include "auth/basic/RADIUS/radius-util.h"
55 #include <sys/socket.h>
58 #include <netinet/in.h>
68 * Check for valid IP address in standard dot notation.
70 static int good_ipaddr(char *addr
)
77 while (*addr
!= '\0' && *addr
!= ' ') {
81 } else if (!isdigit(*addr
)) {
85 if (digit_count
> 3) {
99 * Return an IP address in host long notation from
100 * one supplied in standard dot notation.
102 static uint32_t ipstr2long(char *ip_str
)
111 ipaddr
= (uint32_t)0;
112 for (i
= 0; i
< 4; ++i
) {
116 while (*ip_str
!= '.' && *ip_str
!= '\0' && count
< 4) {
117 if (!isdigit(*ip_str
)) {
125 if (count
>= 4 || count
== 0) {
129 cur_byte
= atoi(buf
);
130 if (cur_byte
< 0 || cur_byte
> 255) {
134 ipaddr
= ipaddr
<< 8 | (uint32_t)cur_byte
;
140 * Return an IP address in host long notation from a host
141 * name or address in dot notation.
143 uint32_t get_ipaddr(char *host
)
147 if (good_ipaddr(host
) == 0) {
148 return(ipstr2long(host
));
149 } else if ((hp
= gethostbyname(host
)) == (struct hostent
*)NULL
) {
152 return(ntohl(*(uint32_t *)hp
->h_addr
));