From 88a9724ae3532db500eb1d599a2215e8bf2707c4 Mon Sep 17 00:00:00 2001 From: kein name Date: Tue, 25 Jul 2023 16:42:30 +0200 Subject: [PATCH] inet_aton() -> inet_pton() --- configure.ac | 2 +- src/compat/Makefile.in | 2 +- src/compat/compat.h | 1 - src/compat/inet_aton.c | 204 ----------------------------------------- src/compat/inet_aton.h | 40 -------- src/eggdrop.h | 2 + src/mod/dns.mod/dns.c | 2 +- src/mod/module.h | 5 +- src/modules.c | 2 +- 9 files changed, 7 insertions(+), 253 deletions(-) delete mode 100644 src/compat/inet_aton.c delete mode 100644 src/compat/inet_aton.h diff --git a/configure.ac b/configure.ac index defe04557..49be1c15c 100644 --- a/configure.ac +++ b/configure.ac @@ -113,7 +113,7 @@ AX_TYPE_SOCKLEN_T AX_CREATE_STDINT_H([eggint.h]) # Checks for functions and their arguments. -AC_CHECK_FUNCS([dprintf explicit_bzero explicit_memset getrandom inet_aton isascii memset_s random rand lrand48 snprintf strlcpy vsnprintf]) +AC_CHECK_FUNCS([dprintf explicit_bzero explicit_memset getrandom isascii memset_s random rand lrand48 snprintf strlcpy vsnprintf]) AC_FUNC_SELECT_ARGTYPES EGG_FUNC_B64_NTOP AC_FUNC_MMAP diff --git a/src/compat/Makefile.in b/src/compat/Makefile.in index c431ee491..570db2e21 100644 --- a/src/compat/Makefile.in +++ b/src/compat/Makefile.in @@ -17,7 +17,7 @@ STRIP = @STRIP@ CFLAGS = @CFLAGS@ -I../.. -I$(top_srcdir) -I$(top_srcdir)/src @SSL_INCLUDES@ @DEFS@ $(CFLGS) CPPFLAGS = @CPPFLAGS@ -OBJS = base64.o explicit_bzero.o in6.o inet_aton.o snprintf.o strlcpy.o +OBJS = base64.o explicit_bzero.o in6.o snprintf.o strlcpy.o doofus: @echo "" diff --git a/src/compat/compat.h b/src/compat/compat.h index 0346097b5..1e3260e63 100644 --- a/src/compat/compat.h +++ b/src/compat/compat.h @@ -24,7 +24,6 @@ #define _EGG_COMPAT_COMPAT_H #include "base64.h" -#include "inet_aton.h" #include "snprintf.h" #include "explicit_bzero.h" #include "strlcpy.h" diff --git a/src/compat/inet_aton.c b/src/compat/inet_aton.c deleted file mode 100644 index dc2c02d44..000000000 --- a/src/compat/inet_aton.c +++ /dev/null @@ -1,204 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * inet_aton.c -- provides inet_aton() if necessary. - * - * Portions Copyright (C) 2000 - 2023 Eggheads Development Team - */ - -#include "main.h" -#include "inet_aton.h" - -#ifndef HAVE_ISASCII -# define inet_isascii(x) 1 /* Let checks succeed if we don't have isascii(). */ -#else -# define inet_isascii(x) egg_isascii(x) -#endif - -#ifndef HAVE_INET_ATON -/*- - * SPDX-License-Identifier: (BSD-3-Clause AND ISC) - * - * Copyright (c) 1983, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -/* - * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") - * Portions Copyright (c) 1996-1999 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT - * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static const char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93"; -static const char rcsid[] = "$Id: inet_addr.c,v 1.5 2005/04/27 04:56:19 sra Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include - -#include -#include - -#include - -/* - * Check whether "cp" is a valid ascii representation - * of an Internet address and convert to a binary address. - * Returns 1 if the address is valid, 0 if not. - * This replaces inet_addr, the return value from which - * cannot distinguish between failure and a local broadcast address. - */ -int egg_inet_aton(const char *cp, struct in_addr *addr) { - u_long val; - int base, n; - char c; - u_int8_t parts[4]; - u_int8_t *pp = parts; - int digit; - - c = *cp; - for (;;) { - /* - * Collect number up to ``.''. - * Values are specified as for C: - * 0x=hex, 0=octal, isdigit=decimal. - */ - if (!isdigit((unsigned char)c)) - return (0); - val = 0; base = 10; digit = 0; - if (c == '0') { - c = *++cp; - if (c == 'x' || c == 'X') - base = 16, c = *++cp; - else { - base = 8; - digit = 1 ; - } - } - for (;;) { - if (isascii(c) && isdigit((unsigned char)c)) { - if (base == 8 && (c == '8' || c == '9')) - return (0); - val = (val * base) + (c - '0'); - c = *++cp; - digit = 1; - } else if (base == 16 && isascii(c) && - isxdigit((unsigned char)c)) { - val = (val << 4) | - (c + 10 - (islower((unsigned char)c) ? 'a' : 'A')); - c = *++cp; - digit = 1; - } else - break; - } - if (c == '.') { - /* - * Internet format: - * a.b.c.d - * a.b.c (with c treated as 16 bits) - * a.b (with b treated as 24 bits) - */ - if (pp >= parts + 3 || val > 0xffU) - return (0); - *pp++ = val; - c = *++cp; - } else - break; - } - /* - * Check for trailing characters. - */ - if (c != '\0' && (!isascii(c) || !isspace((unsigned char)c))) - return (0); - /* - * Did we get a valid digit? - */ - if (!digit) - return (0); - /* - * Concoct the address according to - * the number of parts specified. - */ - n = pp - parts + 1; - switch (n) { - case 1: /* a -- 32 bits */ - break; - - case 2: /* a.b -- 8.24 bits */ - if (val > 0xffffffU) - return (0); - val |= (uint32_t)parts[0] << 24; - break; - - case 3: /* a.b.c -- 8.8.16 bits */ - if (val > 0xffffU) - return (0); - val |= ((uint32_t)parts[0] << 24) | (parts[1] << 16); - break; - - case 4: /* a.b.c.d -- 8.8.8.8 bits */ - if (val > 0xffU) - return (0); - val |= ((uint32_t)parts[0] << 24) | (parts[1] << 16) | - (parts[2] << 8); - break; - } - if (addr != NULL) - addr->s_addr = htonl(val); - return (1); -} -#endif /* !HAVE_INET_ATON */ diff --git a/src/compat/inet_aton.h b/src/compat/inet_aton.h deleted file mode 100644 index 97303653b..000000000 --- a/src/compat/inet_aton.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * inet_aton.h - * prototypes for inet_aton.c - */ -/* - * Copyright (C) 2000 - 2023 Eggheads Development Team - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef _EGG_COMPAT_INET_ATON_H -#define _EGG_COMPAT_INET_ATON_H - -#include "src/main.h" -#ifdef HAVE_SYS_SOCKET_H -# include -#endif -#include -#include - -#ifndef HAVE_INET_ATON -/* Use our own implementation. */ -int egg_inet_aton(const char *cp, struct in_addr *addr); -#else -# define egg_inet_aton inet_aton -#endif - -#endif /* !__EGG_COMPAT_INET_ATON_H */ diff --git a/src/eggdrop.h b/src/eggdrop.h index 0b7015648..f7d9f43a7 100644 --- a/src/eggdrop.h +++ b/src/eggdrop.h @@ -318,6 +318,7 @@ typedef uint32_t IP; /* The following functions are for backward compatibility only */ #define egg_bzero(dest, len) memset(dest, 0, len) +#define egg_inet_aton(src, dst) inet_pton(AF_INET, src, dst) #define egg_memcpy memcpy #define egg_memset memset #define egg_strcasecmp strcasecmp @@ -340,6 +341,7 @@ typedef int (*IntFunc) (); #include #include +#include typedef struct { int family; diff --git a/src/mod/dns.mod/dns.c b/src/mod/dns.mod/dns.c index e0b8cb59b..9bdc05ecd 100644 --- a/src/mod/dns.mod/dns.c +++ b/src/mod/dns.mod/dns.c @@ -180,7 +180,7 @@ static char *dns_change(ClientData cdata, Tcl_Interp *irp, } else port = NAMESERVER_PORT; /* port 53 */ /* Ignore invalid addresses */ - if (egg_inet_aton(list[i], &myres.nsaddr_list[myres.nscount].sin_addr)) { + if (inet_pton(AF_INET, list[i], &myres.nsaddr_list[myres.nscount].sin_addr)) { myres.nsaddr_list[myres.nscount].sin_port = htons(port); myres.nsaddr_list[myres.nscount].sin_family = AF_INET; myres.nscount++; diff --git a/src/mod/module.h b/src/mod/module.h index 1fd109b5c..c77a7aebe 100644 --- a/src/mod/module.h +++ b/src/mod/module.h @@ -60,9 +60,6 @@ #undef Assert /* Compatibility functions. */ -#ifdef egg_inet_aton -# undef egg_inet_aton -#endif #ifdef egg_vsnprintf # undef egg_vsnprintf #endif @@ -430,7 +427,7 @@ typedef void (*chanout_butfunc)(int, int, const char *, ...) ATTRIBUTE_FORMAT(pr #define sock_has_data ((int(*)(int, int))global[248]) #define bots_in_subtree ((int (*)(tand_t *))global[249]) #define users_in_subtree ((int (*)(tand_t *))global[250]) -#define egg_inet_aton ((int (*)(const char *cp, struct in_addr *addr))global[251]) +/* was egg_inet_aton -- use inet_pton() instead */ /* 252 - 255 */ #define egg_snprintf (global[252]) #define egg_vsnprintf ((int (*)(char *, size_t, const char *, va_list))global[253]) diff --git a/src/modules.c b/src/modules.c index 5bcab0e56..b34679c36 100644 --- a/src/modules.c +++ b/src/modules.c @@ -526,7 +526,7 @@ Function global_table[] = { (Function) sock_has_data, (Function) bots_in_subtree, (Function) users_in_subtree, - (Function) egg_inet_aton, + (Function) 0, /* was egg_inet_aton -- use inet_pton() instead */ /* 252 - 255 */ (Function) egg_snprintf, (Function) egg_vsnprintf,