diff options
| author | Joseph Mingrone <jrm@FreeBSD.org> | 2023-05-10 15:02:34 +0000 |
|---|---|---|
| committer | Joseph Mingrone <jrm@FreeBSD.org> | 2023-05-10 15:04:46 +0000 |
| commit | 51a183021fce3928d24b11c319d2787f5a15ae87 (patch) | |
| tree | 03e681bfda053978ba896745828e09cb056ad156 /missing | |
| parent | f91036a44a189fa5d0b5f1c6dea0a396a0f928c0 (diff) | |
Import tcpdump 4.99.4vendor/tcpdump/4.99.4
Reviewed by: emaste
Sponsored by: The FreeBSD Foundation
Diffstat (limited to 'missing')
| -rw-r--r-- | missing/datalinks.c | 2 | ||||
| -rw-r--r-- | missing/dlnames.c | 5 | ||||
| -rw-r--r-- | missing/getopt_long.c | 30 | ||||
| -rw-r--r-- | missing/getopt_long.h | 66 | ||||
| -rw-r--r-- | missing/getservent.c | 143 | ||||
| -rw-r--r-- | missing/pcap_dump_ftell.c | 46 | ||||
| -rw-r--r-- | missing/snprintf.c | 119 | ||||
| -rw-r--r-- | missing/strlcat.c | 8 | ||||
| -rw-r--r-- | missing/strlcpy.c | 8 | ||||
| -rw-r--r-- | missing/strsep.c | 6 |
10 files changed, 297 insertions, 136 deletions
diff --git a/missing/datalinks.c b/missing/datalinks.c index 4a7d6fe961d7..17f60bec5b54 100644 --- a/missing/datalinks.c +++ b/missing/datalinks.c @@ -32,7 +32,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif #include <netdissect-stdinc.h> diff --git a/missing/dlnames.c b/missing/dlnames.c index 16bfcf7940c2..03c2b38c1b7f 100644 --- a/missing/dlnames.c +++ b/missing/dlnames.c @@ -32,7 +32,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif #include <netdissect-stdinc.h> @@ -119,9 +119,6 @@ static struct dlt_choice dlt_choices[] = { #ifdef DLT_LINUX_IRDA DLT_CHOICE(DLT_LINUX_IRDA, "Linux IrDA"), #endif -#ifdef DLT_LANE8023 - DLT_CHOICE(DLT_LANE8023, "Linux 802.3 LANE"), -#endif #ifdef DLT_CIP DLT_CHOICE(DLT_CIP, "Linux Classical IP-over-ATM"), #endif diff --git a/missing/getopt_long.c b/missing/getopt_long.c index 80857369804d..ece000623534 100644 --- a/missing/getopt_long.c +++ b/missing/getopt_long.c @@ -57,6 +57,8 @@ #include <string.h> #include <stdarg.h> +#include "diag-control.h" + #define GNU_COMPATIBLE /* Be more compatible, configure's use us! */ #define PRINT_ERROR ((opterr) && (*options != ':')) @@ -68,7 +70,7 @@ /* return values */ #define BADCH (int)'?' #define BADARG ((*options == ':') ? (int)':' : (int)'?') -#define INORDER (int)1 +#define INORDER (int)1 #define EMSG "" @@ -158,11 +160,29 @@ permute_args(int panonopt_start, int panonopt_end, int opt_end, pos -= nnonopts; else pos += nopts; + /* + * This is annoying - I guess the + * "char * const argv[]" in the declaration + * of getopt() - and thus getopt_long() - + * means that it makes a promise not to + * shuffle the arguments, but here we are, + * shuffling the arguments. + * + * (No, it's not a promise that it won't + * modify any of the argument strings. + * It's a promise that it won't modify + * the array of pointers to the argument + * strings.) + * + * So squelch the cast warnings. + */ swap = nargv[pos]; +DIAG_OFF_CAST_QUAL /* LINTED const cast */ ((char **) nargv)[pos] = nargv[cstart]; /* LINTED const cast */ ((char **)nargv)[cstart] = swap; +DIAG_ON_CAST_QUAL } } } @@ -291,6 +311,7 @@ parse_long_options(char * const *nargv, const char *options, } if (long_options[match].has_arg == required_argument || long_options[match].has_arg == optional_argument) { +DIAG_OFF_CAST_QUAL if (has_equal) optarg = (char *)has_equal; else if (long_options[match].has_arg == @@ -300,6 +321,7 @@ parse_long_options(char * const *nargv, const char *options, */ optarg = nargv[optind++]; } +DIAG_ON_CAST_QUAL } if ((long_options[match].has_arg == required_argument) && (optarg == NULL)) { @@ -543,9 +565,11 @@ start: ++optind; } else { /* takes (optional) argument */ optarg = NULL; - if (*place) /* no white space */ + if (*place) { /* no white space */ +DIAG_OFF_CAST_QUAL optarg = (char *)place; - else if (oli[1] != ':') { /* arg not optional */ +DIAG_ON_CAST_QUAL + } else if (oli[1] != ':') { /* arg not optional */ if (++optind >= nargc) { /* no arg */ place = EMSG; if (PRINT_ERROR) diff --git a/missing/getopt_long.h b/missing/getopt_long.h new file mode 100644 index 000000000000..af97965e4f73 --- /dev/null +++ b/missing/getopt_long.h @@ -0,0 +1,66 @@ +/* $NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $ */ +/* $FreeBSD$ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Dieter Baron and Thomas Klausner. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +#ifndef ND_GETOPT_LONG_H_ +#define ND_GETOPT_LONG_H_ + +/* + * GNU-like getopt_long()/getopt_long_only() with 4.4BSD optreset extension. + * getopt() is declared here too for GNU programs. + */ +#define no_argument 0 +#define required_argument 1 +#define optional_argument 2 + +struct option { + /* name of long option */ + const char *name; + /* + * one of no_argument, required_argument, and optional_argument: + * whether option takes an argument + */ + int has_arg; + /* if not NULL, set *flag to val when option found */ + int *flag; + /* if flag not NULL, value to set *flag to; else return value */ + int val; +}; + +int getopt_long(int, char * const *, const char *, + const struct option *, int *); +int getopt_long_only(int, char * const *, const char *, + const struct option *, int *); + +extern char *optarg; /* getopt(3) external variables */ +extern int optind, opterr, optopt; + +#endif /* ! ND_GETOPT_LONG_H_ */ diff --git a/missing/getservent.c b/missing/getservent.c new file mode 100644 index 000000000000..39cee068a69b --- /dev/null +++ b/missing/getservent.c @@ -0,0 +1,143 @@ +/* + * Copyright (c) 1983, 1993 The Regents of the University of California. + * Copyright (c) 1993 Digital Equipment Corporation. + * Copyright (c) 2012 G. Vanem <gvanem@yahoo.no>. + * Copyright (c) 2017 Ali Abdulkadir <autostart.ini@gmail.com>. + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <netdissect-stdinc.h> +#include <getservent.h> + +static FILE *servf = NULL; +static char line[BUFSIZ+1]; +static struct servent serv; +static char *serv_aliases[MAXALIASES]; +int _serv_stayopen; +const char *etc_path(const char *file); + +/* +* Check if <file> exists in the current directory and, if so, return it. +* Else return either "%SYSTEMROOT%\System32\drivers\etc\<file>" +* or $PREFIX/etc/<file>. +* "<file>" is aka __PATH_SERVICES (aka "services" on Windows and +* "/etc/services" on other platforms that would need this). +*/ +const char *etc_path(const char *file) +{ + const char *env = getenv(__PATH_SYSROOT); + static char path[_MAX_PATH]; + + /* see if "<file>" exists locally or whether __PATH_SYSROOT is valid */ + if (fopen(file, "r") || !env) + return (file); + else +#ifdef _WIN32 + snprintf(path, sizeof(path), "%s%s%s", env, __PATH_ETC_INET, file); +#else + snprintf(path, sizeof(path), "%s%s", env, file); +#endif + return (path); +} + +void +setservent(int f) +{ + if (servf == NULL) + servf = fopen(etc_path(__PATH_SERVICES), "r"); + else + rewind(servf); + _serv_stayopen |= f; +} + +void +endservent(void) +{ + if (servf) { + fclose(servf); + servf = NULL; + } + _serv_stayopen = 0; +} + +struct servent * +getservent(void) +{ + char *p; + char *cp, **q; + + if (servf == NULL && (servf = fopen(etc_path(__PATH_SERVICES), "r")) == NULL) + return (NULL); + +again: + if ((p = fgets(line, BUFSIZ, servf)) == NULL) + return (NULL); + if (*p == '#') + goto again; + cp = strpbrk(p, "#\n"); + if (cp == NULL) + goto again; + *cp = '\0'; + serv.s_name = p; + p = strpbrk(p, " \t"); + if (p == NULL) + goto again; + *p++ = '\0'; + while (*p == ' ' || *p == '\t') + p++; + cp = strpbrk(p, ",/"); + if (cp == NULL) + goto again; + *cp++ = '\0'; + serv.s_port = htons((u_short)atoi(p)); + serv.s_proto = cp; + q = serv.s_aliases = serv_aliases; + cp = strpbrk(cp, " \t"); + if (cp != NULL) + *cp++ = '\0'; + while (cp && *cp) { + if (*cp == ' ' || *cp == '\t') { + cp++; + continue; + } + if (q < &serv_aliases[MAXALIASES - 1]) + *q++ = cp; + cp = strpbrk(cp, " \t"); + if (cp != NULL) + *cp++ = '\0'; + } + *q = NULL; + return (&serv); +} diff --git a/missing/pcap_dump_ftell.c b/missing/pcap_dump_ftell.c new file mode 100644 index 000000000000..ddc516672e85 --- /dev/null +++ b/missing/pcap_dump_ftell.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998 + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Computer Systems + * Engineering Group at Lawrence Berkeley Laboratory. + * 4. Neither the name of the University nor of the Laboratory 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. + */ +#include <stdio.h> +#include <pcap.h> + +#include "pcap-missing.h" + +long +pcap_dump_ftell(pcap_dumper_t *p) +{ + /* FIXME: Using pcap_dump_file(p) would be a better style. That would + * require to test if pcap_dump_file() is available, and to substitute it, + * if it is not. + */ + return (ftell((FILE *)p)); +} diff --git a/missing/snprintf.c b/missing/snprintf.c index 921b74c1df3f..dfff6ee08861 100644 --- a/missing/snprintf.c +++ b/missing/snprintf.c @@ -67,25 +67,6 @@ struct state { /* XXX - methods */ }; -#ifndef HAVE_VSNPRINTF -static int -sn_reserve (struct state *state, size_t n) -{ - return state->s + n > state->theend; -} - -static int -sn_append_char (struct state *state, unsigned char c) -{ - if (sn_reserve (state, 1)) { - return 1; - } else { - *state->s++ = c; - return 0; - } -} -#endif - #if 0 static int as_reserve (struct state *state, size_t n) @@ -430,7 +411,7 @@ xyzprintf (struct state *state, const char *char_format, va_list ap) break; } case 'n' : { - int *arg = va_arg(ap, int*); + int *arg = va_arg(ap, int *); *arg = state->s - state->str; break; } @@ -454,37 +435,6 @@ xyzprintf (struct state *state, const char *char_format, va_list ap) return 0; } -#ifndef HAVE_SNPRINTF -int -snprintf (char *str, size_t sz, const char *format, ...) -{ - va_list args; - int ret; - - va_start(args, format); - ret = vsnprintf (str, sz, format, args); - -#ifdef PARANOIA - { - int ret2; - char *tmp; - - tmp = malloc (sz); - if (tmp == NULL) - abort (); - - ret2 = vsprintf (tmp, format, args); - if (ret != ret2 || strcmp(str, tmp)) - abort (); - free (tmp); - } -#endif - - va_end(args); - return ret; -} -#endif - #if 0 #ifndef HAVE_ASPRINTF int @@ -516,48 +466,9 @@ asprintf (char **ret, const char *format, ...) } #endif -#ifndef HAVE_ASNPRINTF -int -asnprintf (char **ret, size_t max_sz, const char *format, ...) -{ - va_list args; - int val; - - va_start(args, format); - val = vasnprintf (ret, max_sz, format, args); - -#ifdef PARANOIA - { - int ret2; - char *tmp; - tmp = malloc (val + 1); - if (tmp == NULL) - abort (); - - ret2 = vsprintf (tmp, format, args); - if (val != ret2 || strcmp(*ret, tmp)) - abort (); - free (tmp); - } -#endif - - va_end(args); - return val; -} -#endif - -#ifndef HAVE_VASPRINTF -int -vasprintf (char **ret, const char *format, va_list args) -{ - return vasnprintf (ret, 0, format, args); -} -#endif - - #ifndef HAVE_VASNPRINTF int -vasnprintf (char **ret, size_t max_sz, const char *format, va_list args) +nd_vasnprintf (char **ret, size_t max_sz, const char *format, va_list args) { int st; size_t len; @@ -597,29 +508,3 @@ vasnprintf (char **ret, size_t max_sz, const char *format, va_list args) } #endif #endif - -#ifndef HAVE_VSNPRINTF -int -vsnprintf (char *str, size_t sz, const char *format, va_list args) -{ - struct state state; - int ret; - unsigned char *ustr = (unsigned char *)str; - - state.max_sz = 0; - state.sz = sz; - state.str = ustr; - state.s = ustr; - state.theend = ustr + sz - 1; - state.append_char = sn_append_char; - state.reserve = sn_reserve; - - ret = xyzprintf (&state, format, args); - *state.s = '\0'; - if (ret) - return sz; - else - return state.s - state.str; -} -#endif - diff --git a/missing/strlcat.c b/missing/strlcat.c index 405493545b51..fab7d04f3e8e 100644 --- a/missing/strlcat.c +++ b/missing/strlcat.c @@ -1,5 +1,5 @@ /* $NetBSD: strlcat.c,v 1.5 1999/09/20 04:39:47 lukem Exp $ */ -/* from OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp */ +/* from OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp */ /* * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> @@ -47,9 +47,9 @@ size_t strlcat(char *dst, const char *src, size_t siz) { - register char *d = dst; - register const char *s = src; - register size_t n = siz; + char *d = dst; + const char *s = src; + size_t n = siz; size_t dlen; /* Find the end of dst and adjust bytes left but don't go past end */ diff --git a/missing/strlcpy.c b/missing/strlcpy.c index 24dcca67667f..9a0b6e6a54b7 100644 --- a/missing/strlcpy.c +++ b/missing/strlcpy.c @@ -1,5 +1,5 @@ /* $NetBSD: strlcpy.c,v 1.5 1999/09/20 04:39:47 lukem Exp $ */ -/* from OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp */ +/* from OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp */ /* * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> @@ -46,9 +46,9 @@ size_t strlcpy(char *dst, const char *src, size_t siz) { - register char *d = dst; - register const char *s = src; - register size_t n = siz; + char *d = dst; + const char *s = src; + size_t n = siz; /* Copy as many bytes as will fit */ if (n != 0 && --n != 0) { diff --git a/missing/strsep.c b/missing/strsep.c index 2c17275f3391..05f10bccff92 100644 --- a/missing/strsep.c +++ b/missing/strsep.c @@ -55,9 +55,9 @@ char * strsep(char **stringp, const char *delim) { - register char *s; - register const char *spanp; - register int c, sc; + char *s; + const char *spanp; + int c, sc; char *tok; if ((s = *stringp) == NULL) |
