diff --git a/.gitignore b/.gitignore index c842452..5d7d30d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,30 +1,3 @@ -.*.swp -*.tar.gz -*~ -src/*.gcno -src/*.gcda -src/*.gcov -.deps Makefile -Makefile.in -aclocal.m4 -autom4te.cache -compile -config.guess -config.h -config.h.in -config.log -config.status -config.sub -configure -depcomp -install-sh -missing -src/*.o -src/fping -src/fping6 -stamp-h1 -doc/fping.8 -doc/fping6.8 -ci/build +*.o *.kdev4 diff --git a/src/Makefile.aros b/src/Makefile.aros index f8ae677..b844916 100644 --- a/src/Makefile.aros +++ b/src/Makefile.aros @@ -3,34 +3,46 @@ all: fping CC = gcc -CFLAGS = -O2 -DAROS -I. -Iinclude -Wall -Werror +CFLAGS = -O2 -DAROS -I. -D_DEBUG -Wall -Werror LDLIBS = -lm -config.h: inet_getaddrinfo.h - touch config.h +build_date.h: + echo "#define BUILD_DATE \"$$(date -u)"\" >build_date.h -fping.o: fping.c config.h fping.h options.h seqmap.h +fping.h: mem.h + touch fping.h -fping_amiga.o: fping_amiga.c config.h +getaddrinfo.h: fping.h + touch getaddrinfo.h -inet_getaddrinfo.o: inet_getaddrinfo.c fping.h inet_getaddrinfo.h +fping.o: fping.c build_date.h fping.h getaddrinfo.h options.h seqmap.h -inet_ntop.o: inet_ntop.c +fping_amiga.o: fping_amiga.c fping.h getaddrinfo.h -inet_pton.o: inet_pton.c +getaddrinfo.o: getaddrinfo.c fping.h getaddrinfo.h + +ntop.o: ntop.c + +pton.o: pton.c seqmap.o: seqmap.c options.h seqmap.h -socket.o: socket.c config.h fping.h +socket.o: socket.c fping.h -socket4.o: socket4.c config.h fping.h +socket4.o: socket4.c fping.h + +mem.o: mem.c mem.h + +getopt.o: getopt.c getopt.h + +rand.o: rand.c -fping: fping.o fping_amiga.o inet_getaddrinfo.o inet_ntop.o inet_pton.o seqmap.o socket.o socket4.o - ${CC} ${CFLAGS} -s -o fping fping.o fping_amiga.o inet_getaddrinfo.o inet_ntop.o inet_pton.o seqmap.o socket.o socket4.o ${LDLIBS} +fping: fping.o fping_amiga.o getaddrinfo.o ntop.o pton.o seqmap.o socket.o socket4.o mem.o getopt.o rand.o + ${CC} ${CFLAGS} -s -o fping fping.o fping_amiga.o getaddrinfo.o ntop.o pton.o seqmap.o socket.o socket4.o mem.o getopt.o rand.o ${LDLIBS} clean: - rm -f fping.o fping_amiga.o inet_getaddrinfo.o inet_ntop.o inet_pton.o seqmap.o socket.o socket4.o fping + rm -f fping.o fping_amiga.o getaddrinfo.o ntop.o pton.o seqmap.o socket.o socket4.o mem.o getopt.o rand.o build_date.h fping depend: @echo Dependencies already done diff --git a/src/Makefile.m68k b/src/Makefile.m68k index dc6bb01..50571e7 100644 --- a/src/Makefile.m68k +++ b/src/Makefile.m68k @@ -3,45 +3,46 @@ all: fping CC = m68k-amigaos-gcc -CFLAGS = -O2 -noixemul -DAOS3 -I. -I.. -Iinclude -Wall -Werror -LDLIBS = -liberty -lm +CFLAGS = -O2 -noixemul -DAOS3 -D_DEBUG -I. -I.. -Iinclude -Wall -Werror +LDLIBS = -lm build_date.h: echo "#define BUILD_DATE \"$$(date -u)"\" >build_date.h -config.h: inet_getaddrinfo.h - touch config.h - fping.h: mem.h touch fping.h -inet_getaddrinfo.h: fping.h - touch inet_getaddrinfo.h +getaddrinfo.h: fping.h + touch getaddrinfo.h -fping.o: fping.c build_date.h config.h fping.h options.h seqmap.h +fping.o: fping.c build_date.h fping.h getaddrinfo.h options.h seqmap.h -fping_amiga.o: fping_amiga.c config.h +fping_amiga.o: fping_amiga.c fping.h getaddrinfo.h -inet_getaddrinfo.o: inet_getaddrinfo.c fping.h inet_getaddrinfo.h +getaddrinfo.o: getaddrinfo.c fping.h getaddrinfo.h -inet_ntop.o: inet_ntop.c +ntop.o: ntop.c -inet_pton.o: inet_pton.c config.h +pton.o: pton.c seqmap.o: seqmap.c options.h seqmap.h -socket.o: socket.c config.h fping.h +socket.o: socket.c fping.h -socket4.o: socket4.c config.h fping.h +socket4.o: socket4.c fping.h mem.o: mem.c mem.h +getopt.o: getopt.c getopt.h -fping: fping.o fping_amiga.o inet_getaddrinfo.o inet_ntop.o inet_pton.o seqmap.o socket.o socket4.o mem.o - ${CC} ${CFLAGS} -s -o fping fping.o fping_amiga.o inet_getaddrinfo.o inet_ntop.o inet_pton.o seqmap.o socket.o socket4.o mem.o ${LDLIBS} +rand.o: rand.c + + +fping: fping.o fping_amiga.o getaddrinfo.o ntop.o pton.o seqmap.o socket.o socket4.o mem.o getopt.o rand.o + ${CC} ${CFLAGS} -s -o fping fping.o fping_amiga.o getaddrinfo.o ntop.o pton.o seqmap.o socket.o socket4.o mem.o getopt.o rand.o ${LDLIBS} clean: - rm -f fping.o fping_amiga.o inet_getaddrinfo.o inet_ntop.o inet_pton.o seqmap.o socket.o socket4.o mem.o build_date.h fping + rm -f fping.o fping_amiga.o getaddrinfo.o ntop.o pton.o seqmap.o socket.o socket4.o mem.o getopt.o rand.o build_date.h fping depend: @echo Dependencies already done diff --git a/src/config.h b/src/config.h deleted file mode 100644 index 46756a7..0000000 --- a/src/config.h +++ /dev/null @@ -1,85 +0,0 @@ -/* config.h. Generated from config.h.in by configure. */ -/* config.h.in. Generated from configure.ac by autoheader. */ - -#ifndef CONFIG_H -#define CONFIG_H - -#ifdef AROS -/* Define to 1 if you have the header file. */ -# define HAVE_INTTYPES_H 1 -#endif - -#include "inet_getaddrinfo.h" - -/* Define to 1 if you have the header file. */ -#define HAVE_MEMORY_H 1 - -#ifdef AROS -/* Define to 1 if you have the header file. */ -# define HAVE_STDINT_H 1 -#endif - -/* Define to 1 if you have the header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRINGS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_FILE_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_SELECT_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_UNISTD_H 1 - -/* Name of package */ -#define PACKAGE "fping" - -/* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "" - -/* Define to the full name of this package. */ -#define PACKAGE_NAME "fping" - -/* Define to the full name and version of this package. */ -#define PACKAGE_STRING "fping 3.13" - -/* Define to the one symbol short name of this package. */ -#define PACKAGE_TARNAME "fping" - -/* Define to the home page for this package. */ -#define PACKAGE_URL "" - -/* Define to the version of this package. */ -#define PACKAGE_VERSION "3.13" - -/* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Version number of package */ -#define VERSION "3.13" - -/* some OSes do not define this ... lets take a wild guess */ - -#ifndef INADDR_NONE -# define INADDR_NONE 0xffffffffU -#endif - -/* No TTL (time to live) in socket options */ -#define NOTTL 1 - -/* No TOS (type of service) in socket options */ -#define NOTOS 1 - -#endif /* CONFIG_H */ diff --git a/src/configure b/src/configure index 783103f..74bb07f 100755 --- a/src/configure +++ b/src/configure @@ -29,24 +29,26 @@ set -e HDRS=' - config.h fping.h - inet_getaddrinfo.h + getaddrinfo.h options.h seqmap.h mem.h + getopt.h ' SRCS=' fping.c fping_amiga.c - inet_getaddrinfo.c - inet_ntop.c - inet_pton.c + getaddrinfo.c + ntop.c + pton.c seqmap.c socket.c socket4.c mem.c + getopt.c + rand.c ' if make -v 2>&1 | grep GNU > /dev/null 2>&1 ; then @@ -69,10 +71,10 @@ if $VALID ; then if [ -n "$1" ] && [ $1 = "AMIGA" ] ; then echo 'CC = m68k-amigaos-gcc' echo "CFLAGS = -O2 -noixemul -DAOS3 ${DEBUG}-I. -I.. -Iinclude -Wall -Werror" - echo "LDLIBS = -liberty -lm" + echo "LDLIBS = -lm" elif [ -n "$1" ] && [ $1 = "AROS" ] ; then echo 'CC = gcc' - echo "CFLAGS = -O2 -DAROS -I. -Iinclude -Wall -Werror" + echo "CFLAGS = -O2 -DAROS -I. ${DEBUG}-Wall -Werror" echo "LDLIBS = -lm" else echo "CFLAGS = -O2 -Wall -Werror" diff --git a/src/fping.c b/src/fping.c index db0710e..9d024d1 100644 --- a/src/fping.c +++ b/src/fping.c @@ -37,47 +37,9 @@ extern "C" #include "fping.h" #include "options.h" -#include "build_date.h" - -/* if compiling for Windows, use this separate set - (too difficult to ifdef all the autoconf defines) */ -#ifdef WIN32 - -/*** Windows includes ***/ - - -#else - -/*** autoconf includes ***/ - - -#include -#include -#include -#include -#include - -#include "config.h" #include "seqmap.h" - -#ifdef HAVE_UNISTD_H -#include -#endif /* HAVE_UNISTD_H */ - -#ifdef HAVE_STDLIB_H -#include -#endif /* HAVE_STDLIB_H */ - -#include -#include - -#include -#include -#include - -#if HAVE_SYS_FILE_H -#include -#endif /* HAVE_SYS_FILE_H */ +#include "build_date.h" +#include "getaddrinfo.h" #ifdef IPV6 #include @@ -86,22 +48,11 @@ extern "C" #include #include - #include #include -/* RS6000 has sys/select.h */ -#ifdef HAVE_SYS_SELECT_H -#include -#endif /* HAVE_SYS_SELECT_H */ - -#endif /* WIN32 */ - -/*** externals ***/ - extern char *optarg; extern int optind,opterr; -extern int h_errno; #ifdef __cplusplus } @@ -368,6 +319,8 @@ int main( int argc, char **argv ) int res; HOST_ENTRY *cursor; + prog = argv[0]; + if((res = open_libs()) != 0) return res; @@ -378,7 +331,6 @@ int main( int argc, char **argv ) setuid( getuid() ); } - prog = argv[0]; ident = getpid() & 0xFFFF; verbose_flag = 1; backoff_flag = 1; @@ -512,7 +464,7 @@ int main( int argc, char **argv ) #endif /* DEBUG || _DEBUG */ case 'v': - printf( "%s: Version %s%s\n", argv[0], VERSION, DEBUG_TEXT ); + printf( "%s: Version %s%s\n", argv[0], PACKAGE_VERSION, DEBUG_TEXT ); printf( "%s: Build %s\n", argv[0], BUILD_DATE ); printf( "%s: Comments to %s\n", argv[0], EMAIL ); exit( 0 ); @@ -1158,7 +1110,7 @@ void finish() print_global_stats(); if ( cancelled ) - exit( 10 ); + exit( 5 ); if( num_noaddress ) exit( 2 ); @@ -1846,7 +1798,6 @@ void add_name( char *name ) { struct addrinfo *res0, *res, hints; int ret_ga; - size_t len; char *printname; char namebuf[256]; char addrbuf[256]; @@ -1877,7 +1828,6 @@ void add_name( char *name ) // (need to implement a separate option for this) for (res = res0; res; res = 0) { - len = res->ai_addrlen; /* name_flag: addr -> name lookup requested) */ if(!name_flag) { printname = name; @@ -2198,7 +2148,7 @@ int recvfrom_wto( int s, char *buf, int len, struct sockaddr *saddr, socklen_t * int nfound, n; struct timeval to; fd_set readset, writeset; - long signal = SIGBREAKF_CTRL_C; + SIGNAL signal = SIGBREAKF_CTRL_C; select_again: if(timo < 100000) { @@ -2235,7 +2185,7 @@ select_again: return -1; /* timeout */ // recvfrom(int socket, void *restrict buffer, size_t length, int flags, struct sockaddr *restrict address, socklen_t *restrict address_len); - n = RecvFrom( s, buf, len, 0, saddr, saddr_len ); + n = RecvFrom( s, buf, len, 0, saddr, (int*)saddr_len ); if( n < 0 ) errno_crash_and_burn( "recvfrom" ); @@ -2292,7 +2242,7 @@ void ev_enqueue(HOST_ENTRY *h) #if defined( DEBUG ) || defined( _DEBUG ) if( trace_flag ) { long st = timeval_diff(&h->ev_time, ¤t_time); - fprintf(stderr, "Enqueue: host=%s, when=%ld ms (%ld, %ld)\n", h->host, st/100, h->ev_time.tv_sec, h->ev_time.tv_usec); + fprintf(stderr, "Enqueue: host=%s, when=%ld ms (%ld, %ld)\n", h->host, st/100, (long)h->ev_time.tv_sec, (long)h->ev_time.tv_usec); } #endif @@ -2398,7 +2348,11 @@ void ev_remove(HOST_ENTRY *h) void usage(int is_error) { FILE *out = is_error ? stderr : stdout; - fprintf(out, "\33[33mfping version " VERSION DEBUG_TEXT "\33[31m\n" ); +#ifdef ANSI_CONSOLE + fprintf(out, "\33[33mfping version " PACKAGE_VERSION DEBUG_TEXT "\33[31m\n" ); +#else + fprintf(out, "fping version " PACKAGE_VERSION DEBUG_TEXT "\n" ); +#endif fprintf(out, "Usage: %s [options] [targets...]\n", prog ); fprintf(out, " -a show targets that are alive\n" ); fprintf(out, " -A show targets by address\n" ); diff --git a/src/fping.h b/src/fping.h index c3324b1..dc97353 100644 --- a/src/fping.h +++ b/src/fping.h @@ -6,38 +6,57 @@ #ifndef _FPING_H #define _FPING_H -#define __APPLE_USE_RFC_3542 1 +#include +#include +#include +#include +#include +#include +#include #include #include #include +#include + +#include +#include +#include +#include +#include +#include +#include +#include #include "mem.h" #define calloc(x, y) allocmem(x*y) #define malloc(x) allocmem(x) #define free(x) freemem(x) -#if defined(__AMIGA__) -#include -#include -#include -#include -#include -#include -#include -#include -#define uint16_t u_int16_t -#define IPTR ULONG +#ifdef AOS3 +# include +# include +# include +# define uint16_t u_int16_t +# define IPTR ULONG +# define ANSI_CONSOLE 1 +# define gettimeofday(x, y) getsystime(x) +typedef unsigned int socklen_t; +typedef unsigned int sa_family_t; #endif -typedef unsigned int socklen_t; typedef u_int16_t in_port_t; -typedef unsigned int sa_family_t; + +#ifdef AROS +# include +# include +# define Socket(a,b,c) socket(a,b,c) +# define Bind(a,b,c) bind(a,b,c) +# define RecvFrom(a,b,c,d,e,f) recvfrom(a,b,c,d,e,f) +# define SendTo(a,b,c,d,e,f) sendto(a,b,c,d,e,f) +#endif #ifdef AOS3 -/* - * struct addrinfo. - */ struct addrinfo { int ai_flags; int ai_family; @@ -60,6 +79,10 @@ struct addrinfo { # define FPING_ICMPHDR struct icmp6_hdr #endif +#ifndef INADDR_NONE +# define INADDR_NONE 0xffffffffU +#endif + #ifndef PF_INET6 # define PF_INET6 10 #endif @@ -80,7 +103,21 @@ struct addrinfo { # define DEBUG_TEXT "" #endif -#define gettimeofday(x, y) getsystime(x) +#ifdef AOS3 +# define random() rand() +# define srandom() srand() +#endif + +#define PACKAGE_NAME "fping" +#define PACKAGE_VERSION "3.13" + +/* No TTL (time to live) in socket options */ +#define NOTTL 1 + +/* No TOS (type of service) in socket options */ +#define NOTOS 1 + +#define SIGNAL ULONG /* fping.c */ void crash_and_burn( char *message ); diff --git a/src/fping_amiga.c b/src/fping_amiga.c index 9433ba7..eda916d 100644 --- a/src/fping_amiga.c +++ b/src/fping_amiga.c @@ -3,25 +3,20 @@ * Public domain. */ -#include -#include -#include -#include -#include -#include -#include +#include "fping.h" +#include "getaddrinfo.h" #define OPEN_ERROR "Cannot open %s.\n" #define OPEN_VER_ERROR "Cannot open %s (%d.0)\n" -#define DOSLIB_NAME "dos.library" -#define DOSLIB_REV 37L -#define BSDLIB_NAME "bsdsocket.library" -#define BSDLIB_REV 03L -#define UTILLIB_NAME "utility.library" -#define UTILLIB_REV 37L +#define DOSLIB_NAME "dos.library" +#define DOSLIB_REV 37L +#define BSDLIB_NAME "bsdsocket.library" +#define BSDLIB_REV 03L +#define UTILLIB_NAME "utility.library" +#define UTILLIB_REV 37L #define TIMER_NAME TIMERNAME +#define LIB_ERROR 4 -#include "config.h" const char *vers = "\0$VER: " PACKAGE_NAME " " PACKAGE_VERSION " (21.02.2016)"; #include @@ -75,27 +70,29 @@ void close_libs() SocketBase = NULL; } + freeall(); + if (DOSBase != NULL) { CloseLibrary(DOSBase); DOSBase = NULL; } - - freeall(); } int open_libs() { + struct timeval tv; + atexit(close_libs); InitSemaphore(&GetaddrinfoSemaphore); if(!(DOSBase = OpenLibrary((STRPTR)DOSLIB_NAME, DOSLIB_REV))) { amiga_open_lib_error(DOSLIB_NAME, DOSLIB_REV); - return 5; + return LIB_ERROR; } if(!(SocketBase = OpenLibrary((STRPTR)BSDLIB_NAME, BSDLIB_REV))) { amiga_open_lib_error(BSDLIB_NAME, BSDLIB_REV); - return 5; + return LIB_ERROR; } else { SocketBaseTags( SBTM_SETVAL(SBTC_ERRNOPTR(sizeof(errno))), (IPTR) &errno, @@ -106,17 +103,21 @@ int open_libs() if(!(UtilityBase = OpenLibrary((STRPTR)UTILLIB_NAME, UTILLIB_REV))) { amiga_open_lib_error(UTILLIB_NAME, UTILLIB_REV); - return 5; + return LIB_ERROR; } if (create_timer() != 0) { amiga_open_error(TIMER_NAME); - return 10; + return LIB_ERROR; } + gettimeofday(&tv, NULL); + srand(tv.tv_usec); + return 0; } +#ifdef AOS3 int create_timer() { LONG error; @@ -171,3 +172,7 @@ int getsystime(struct timeval *tv) return 0; } +#else +int create_timer() { return 0; } +void delete_timer() { } +#endif diff --git a/src/inet_getaddrinfo.c b/src/getaddrinfo.c similarity index 99% rename from src/inet_getaddrinfo.c rename to src/getaddrinfo.c index 2d7f4bd..71fb857 100644 --- a/src/inet_getaddrinfo.c +++ b/src/getaddrinfo.c @@ -60,7 +60,7 @@ #include #include "fping.h" -#include "inet_getaddrinfo.h" +#include "getaddrinfo.h" #ifdef ENABLE_NLS #include diff --git a/src/inet_getaddrinfo.h b/src/getaddrinfo.h similarity index 100% rename from src/inet_getaddrinfo.h rename to src/getaddrinfo.h diff --git a/src/getopt.c b/src/getopt.c new file mode 100644 index 0000000..aaf840f --- /dev/null +++ b/src/getopt.c @@ -0,0 +1,117 @@ +/* + * getopt.c -- + * + * Standard UNIX getopt function. Code is from BSD. + * + * Copyright (c) 1987-2002 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: + * + * A. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * B. 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. + * C. Neither the names of the copyright holders 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 COPYRIGHT HOLDERS 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. + */ + +/* #if !defined(lint) + * static char sccsid[] = "@(#)getopt.c 8.2 (Berkeley) 4/2/94"; + * #endif + */ +#include +#include +#include + +#include "getopt.h" + +int opterr = 1, /* if error message should be printed */ + optind = 1, /* index into parent argv vector */ + optopt, /* character checked for validity */ + optreset; /* reset getopt */ +char *optarg; /* argument associated with option */ + +#define BADCH (int)'?' +#define BADARG (int)':' +#define EMSG "" + +/* + * getopt -- + * Parse argc/argv argument vector. + */ +int +getopt( int nargc, + char * const *nargv, + const char *ostr) +{ + static char *place = EMSG; /* option letter processing */ + char *oli; /* option letter list index */ + + if (optreset || !*place) { /* update scanning pointer */ + optreset = 0; + if (optind >= nargc || *(place = nargv[optind]) != '-') { + place = EMSG; + return (EOF); + } + if (place[1] && *++place == '-') { /* found "--" */ + ++optind; + place = EMSG; + return (EOF); + } + } /* option letter okay? */ + if ((optopt = (int)*place++) == (int)':' || + !(oli = (char*) strchr(ostr, optopt))) { + /* + * if the user didn't specify '-' as an option, + * assume it means EOF. + */ + if (optopt == (int)'-') + return (EOF); + if (!*place) + ++optind; + if (opterr && *ostr != ':') + (void)fprintf(stderr, + "illegal option -- %c\n", optopt); + return (BADCH); + } + if (*++oli != ':') { /* don't need argument */ + optarg = NULL; + if (!*place) + ++optind; + } + else { /* need an argument */ + if (*place) /* no white space */ + optarg = place; + else if (nargc <= ++optind) { /* no arg */ + place = EMSG; + if (*ostr == ':') + return (BADARG); + if (opterr) + (void)fprintf(stderr, + "option requires an argument -- %c\n", + optopt); + return (BADCH); + } + else /* white space */ + optarg = nargv[optind]; + place = EMSG; + ++optind; + } + return (optopt); /* dump back option letter */ +} diff --git a/src/getopt.h b/src/getopt.h new file mode 100644 index 0000000..5bcb06f --- /dev/null +++ b/src/getopt.h @@ -0,0 +1,51 @@ +#ifndef _HAD_GETOPT_H +#define _HAD_GETOPT_H + +/* + getopt.h -- header for getopt() replacement function + Copyright (C) 1999-2011 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + 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. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``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 AUTHORS 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 __cplusplus +extern "C" { +#endif + +extern char *optarg; +extern int optind; +extern int opterr; + +extern int getopt(int, char * const *, const char *); + +#ifdef __cplusplus +} +#endif + +#endif /* _HAD_GETOPT_H */ diff --git a/src/mem.c b/src/mem.c index 6d33a5f..8cc1eed 100644 --- a/src/mem.c +++ b/src/mem.c @@ -2,6 +2,7 @@ // This file is in the public domain. // //--------------------------------------------------------------------------// #include +#include #include #include #include diff --git a/src/inet_ntop.c b/src/ntop.c similarity index 99% rename from src/inet_ntop.c rename to src/ntop.c index 0aab4d2..73cc22a 100644 --- a/src/inet_ntop.c +++ b/src/ntop.c @@ -36,8 +36,6 @@ * */ -# include - #include #include #include diff --git a/src/inet_pton.c b/src/pton.c similarity index 99% rename from src/inet_pton.c rename to src/pton.c index c13f9ad..80424a9 100644 --- a/src/inet_pton.c +++ b/src/pton.c @@ -21,8 +21,6 @@ * */ -#include "config.h" - #include #include #include diff --git a/src/rand.c b/src/rand.c new file mode 100644 index 0000000..f07417c --- /dev/null +++ b/src/rand.c @@ -0,0 +1,61 @@ +/* $NetBSD: rand.c,v 1.12 2012/06/25 22:32:45 abs Exp $ */ + +/*- + * Copyright (c) 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. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +#if 1 +static char sccsid[] = "@(#)rand.c 8.1 (Berkeley) 6/14/93"; +#else +__RCSID("$NetBSD: rand.c,v 1.12 2012/06/25 22:32:45 abs Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +#ifndef RAND_MAX +#define RAND_MAX 2147483647 +#endif + +static u_long next = 1; + +int +rand(void) +{ + /* LINTED integer overflow */ + return (int)((next = next * 1103515245 + 12345) % ((u_long)RAND_MAX + 1)); +} + +void +srand(u_int seed) +{ + next = seed; +} diff --git a/src/socket.c b/src/socket.c index 33c9e60..9e3d5dd 100644 --- a/src/socket.c +++ b/src/socket.c @@ -31,7 +31,6 @@ */ #include "fping.h" -#include "config.h" int open_ping_socket_ipv4(); int open_ping_socket_ipv6(); diff --git a/src/socket4.c b/src/socket4.c index fb84fbf..1c4dc46 100644 --- a/src/socket4.c +++ b/src/socket4.c @@ -31,7 +31,6 @@ */ #include "fping.h" -#include "config.h" #include #include diff --git a/src/socket6.c b/src/socket6.c index 66a246a..c7d3a41 100644 --- a/src/socket6.c +++ b/src/socket6.c @@ -31,7 +31,6 @@ */ #include "fping.h" -#include "config.h" #include #include