Cleanup
This commit is contained in:
parent
005624f44f
commit
32cd7febe0
85
config.h
85
config.h
|
@ -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
|
||||
|
||||
#include "net_getaddrinfo.h"
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
/* #undef HAVE_INTTYPES_H */
|
||||
|
||||
/* Define to 1 if you have the `nsl' library (-lnsl). */
|
||||
/* #undef HAVE_LIBNSL */
|
||||
|
||||
/* Define to 1 if you have the `socket' library (-lsocket). */
|
||||
#define HAVE_LIBSOCKET 1
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
/* #undef HAVE_STDINT_H */
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/file.h> header file. */
|
||||
#define HAVE_SYS_FILE_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/select.h> header file. */
|
||||
/* #undef HAVE_SYS_SELECT_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> 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.10"
|
||||
|
||||
/* 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.10"
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "3.10"
|
||||
|
||||
|
||||
/* some OSes do not define this ... lets take a wild guess */
|
||||
|
||||
#ifndef INADDR_NONE
|
||||
# define INADDR_NONE 0xffffffffU
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_H */
|
||||
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
# Portable Makefile generated by configure
|
||||
|
||||
all: fping
|
||||
|
||||
CC = m68k-amigaos-gcc
|
||||
CFLAGS = -O2 -noixemul -I. -I.. -Iinclude -Wall -Werror
|
||||
LDLIBS = -liberty -lm
|
||||
|
||||
config.h: inet_getaddrinfo.h
|
||||
touch config.h
|
||||
|
||||
fping.o: fping.c config.h fping.h options.h seqmap.h
|
||||
|
||||
fping_amiga.o: fping_amiga.c
|
||||
|
||||
inet_getaddrinfo.o: inet_getaddrinfo.c fping.h inet_getaddrinfo.h
|
||||
|
||||
inet_ntop.o: inet_ntop.c
|
||||
|
||||
inet_pton.o: inet_pton.c
|
||||
|
||||
seqmap.o: seqmap.c options.h seqmap.h
|
||||
|
||||
socket.o: socket.c config.h fping.h
|
||||
|
||||
socket4.o: socket4.c config.h fping.h
|
||||
|
||||
|
||||
fping: fping.o fping_amiga.o inet_getaddrinfo.o inet_ntop.o inet_pton.o seqmap.o socket.o socket4.o
|
||||
${CC} ${CFLAGS} -o fping fping.o fping_amiga.o inet_getaddrinfo.o inet_ntop.o inet_pton.o seqmap.o socket.o socket4.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
|
||||
|
||||
depend:
|
||||
@echo Dependencies already done
|
|
@ -1,16 +0,0 @@
|
|||
prog =
|
||||
|
||||
if IPV4
|
||||
prog += fping
|
||||
endif
|
||||
if IPV6
|
||||
prog += fping6
|
||||
endif
|
||||
|
||||
sbin_PROGRAMS = ${prog}
|
||||
|
||||
fping_SOURCES = fping.c seqmap.c socket.c socket4.c fping.h options.h seqmap.h
|
||||
fping_DEPENDENCIES = ../config.h
|
||||
fping6_SOURCES = fping.c seqmap.c socket.c socket6.c fping.h options.h seqmap.h
|
||||
fping6_DEPENDENCIES = ../config.h
|
||||
fping6_CFLAGS = $(AM_CFLAGS) -DIPV6
|
|
@ -0,0 +1,119 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2015 Carsten Larsen
|
||||
# Copyright (c) 2014 Poul-Henning Kamp
|
||||
# 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.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
#
|
||||
|
||||
set -e
|
||||
|
||||
HDRS='
|
||||
config.h
|
||||
fping.h
|
||||
inet_getaddrinfo.h
|
||||
options.h
|
||||
seqmap.h
|
||||
'
|
||||
|
||||
SRCS='
|
||||
fping.c
|
||||
fping_amiga.c
|
||||
inet_getaddrinfo.c
|
||||
inet_ntop.c
|
||||
inet_pton.c
|
||||
seqmap.c
|
||||
socket.c
|
||||
socket4.c
|
||||
'
|
||||
|
||||
if make -v 2>&1 | grep GNU > /dev/null 2>&1 ; then
|
||||
echo "make is GNU make."
|
||||
VALID=true
|
||||
#else
|
||||
# echo "Wrong version of make."
|
||||
# VALID=false
|
||||
fi
|
||||
|
||||
if $VALID ; then
|
||||
(
|
||||
echo '# Portable Makefile generated by configure'
|
||||
echo ''
|
||||
echo 'all: fping'
|
||||
echo ''
|
||||
if [ -n "$1" ] && [ $1 = "AMIGA" ] ; then
|
||||
echo 'CC = m68k-amigaos-gcc'
|
||||
echo "CFLAGS = -O2 -noixemul -I. -I.. -Iinclude -Wall -Werror"
|
||||
echo "LDLIBS = -liberty -lm"
|
||||
elif [ -n "$1" ] && [ $1 = "AROS" ] ; then
|
||||
echo 'CC = gcc'
|
||||
echo "CFLAGS = -O2 -DAROS -I. -Iinclude -Wall -Werror"
|
||||
echo "LDLIBS = -lm"
|
||||
else
|
||||
echo "CFLAGS = -O2 -Wall -Werror"
|
||||
echo "LDLIBS = -lm"
|
||||
fi
|
||||
echo ''
|
||||
|
||||
for f in ${HDRS}
|
||||
do
|
||||
b=`basename $f .h`
|
||||
i=`sed -n -e '/#include.*"/{
|
||||
s/"$//
|
||||
s/.*"//
|
||||
p
|
||||
}' $f | sort -u`
|
||||
if [ "x${i}" != "x" ] ; then
|
||||
echo "${b}.h: " ${i}
|
||||
echo " touch ${b}.h"
|
||||
echo
|
||||
fi
|
||||
done
|
||||
|
||||
l=""
|
||||
for f in ${SRCS}
|
||||
do
|
||||
b=`basename $f .c`
|
||||
i=`sed -n -e '/#include.*"/{
|
||||
s/"$//
|
||||
s/.*"//
|
||||
p
|
||||
}' $f | sort -u`
|
||||
echo "${b}.o: ${b}.c" ${i}
|
||||
echo
|
||||
l="${l} ${b}.o"
|
||||
done
|
||||
|
||||
echo
|
||||
echo "fping: ${l}"
|
||||
echo " \${CC} \${CFLAGS} -o fping ${l} \${LDLIBS}"
|
||||
echo
|
||||
echo "clean:"
|
||||
echo " rm -f ${l} fping"
|
||||
echo
|
||||
echo "depend:"
|
||||
echo " @echo Dependencies already done"
|
||||
) > Makefile
|
||||
|
||||
echo "Makefile generated"
|
||||
fi
|
597
src/fping.c
597
src/fping.c
File diff suppressed because it is too large
Load Diff
13
src/fping.h
13
src/fping.h
|
@ -6,6 +6,8 @@
|
|||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <clib/exec_protos.h>
|
||||
#include <clib/amitcp_protos.h>
|
||||
|
||||
#ifndef IPV6
|
||||
#define FPING_SOCKADDR struct sockaddr_in
|
||||
|
@ -25,9 +27,14 @@ void errno_crash_and_burn( char *message );
|
|||
int open_ping_socket();
|
||||
void socket_set_src_addr(int s, FPING_INADDR src_addr);
|
||||
|
||||
// NOTE: Quickfix
|
||||
#include "clib/exec_protos.h"
|
||||
/* inet_ntop.c */
|
||||
const char *inet_ntop(int af, const void *src, char *dst, size_t size);
|
||||
|
||||
/* inet_pton.c */
|
||||
int inet_pton(int af, const char *src, void *dst);
|
||||
|
||||
/* fping_amiga.c */
|
||||
int open_libs();
|
||||
extern struct Library *SocketBase;
|
||||
#include "clib/amitcp_protos.h"
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Written by Carsten Larsen.
|
||||
* Public domain.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <clib/exec_protos.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
|
||||
|
||||
#include <unistd.h>
|
||||
uid_t getuid () {
|
||||
return 1;
|
||||
}
|
||||
int setuid (uid_t id) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int h_errno;
|
||||
|
||||
struct Library *DOSBase;
|
||||
struct Library *SocketBase;
|
||||
|
||||
void amiga_open_error(char *name)
|
||||
{
|
||||
printf(OPEN_ERROR, name);
|
||||
}
|
||||
|
||||
void amiga_open_lib_error(char *name, int version)
|
||||
{
|
||||
printf(OPEN_VER_ERROR, name, version);
|
||||
}
|
||||
|
||||
void close_libs()
|
||||
{
|
||||
if (DOSBase != NULL) {
|
||||
CloseLibrary(DOSBase);
|
||||
DOSBase = NULL;
|
||||
}
|
||||
|
||||
if (SocketBase != NULL) {
|
||||
CloseLibrary(SocketBase);
|
||||
SocketBase = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int open_libs()
|
||||
{
|
||||
atexit(close_libs);
|
||||
|
||||
if(!(DOSBase = OpenLibrary((STRPTR)DOSLIB_NAME, DOSLIB_REV))) {
|
||||
amiga_open_lib_error(DOSLIB_NAME, DOSLIB_REV);
|
||||
return 5;
|
||||
}
|
||||
|
||||
if(!(SocketBase = OpenLibrary((STRPTR)BSDLIB_NAME, BSDLIB_REV))) {
|
||||
amiga_open_lib_error(BSDLIB_NAME, BSDLIB_REV);
|
||||
return 5;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* Copyright (c) 2015 Carsten Larsen
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 _SOCKET_AMITCP_H
|
||||
#define _SOCKET_AMITCP_H
|
||||
//--------------------------------------------------------------------------//
|
||||
#define AMITCP_BASE_NAME SocketBase
|
||||
#include "inline/amitcp.h"
|
||||
//--------------------------------------------------------------------------//
|
||||
#define socket Socket
|
||||
#define bind Bind
|
||||
#define listen Listen
|
||||
#define accept Accept
|
||||
#define connect Connect
|
||||
#define send Send
|
||||
#define sendto SendTo
|
||||
#define sendmsg SendMsg
|
||||
#define recv Recv
|
||||
#define recvfrom RecvFrom
|
||||
#define recvmsg RecvMsg
|
||||
#define select Select
|
||||
#define shutdown ShutDown
|
||||
#define setsockopt SetSockOpt
|
||||
#define getsockopt GetSockOpt
|
||||
#define getsockname GetSockName
|
||||
#define getpeername GetPeerName
|
||||
#define inet_addr Inet_Addr
|
||||
#define inet_network Inet_Network
|
||||
#define inet_ntoa Inet_NtoA
|
||||
#define gethostbyname GetHostByName
|
||||
#define gethostbyaddr GetHostByAddr
|
||||
#define getnetbyname GetNetByName
|
||||
#define getnetbyaddr GetNetByAddr
|
||||
#define getservbyname GetServByName
|
||||
#define getservbyport GetServByPort
|
||||
#define getprotobyname GetProtoByName
|
||||
#define getprotobynumber GetProtoByNumber
|
||||
#define getdtablesize GetDTableSize
|
||||
#define gethostname GetHostName
|
||||
#define gethostid GetHostId
|
||||
#define vsyslog SyslogA
|
||||
#define syslog Syslog
|
||||
//--------------------------------------------------------------------------//
|
||||
#define Accept TCP_Accept
|
||||
#define Bind TCP_Bind
|
||||
#define CloseSocket TCP_CloseSocket
|
||||
#define Connect TCP_Connect
|
||||
#define Dup2Socket TCP_Dup2Socket
|
||||
#define Errno TCP_Errno
|
||||
#define GetDTableSize TCP_GetDTableSize
|
||||
#define GetHostByAddr TCP_GetHostByAddr
|
||||
#define GetHostByName TCP_GetHostByName
|
||||
#define GetHostId TCP_GetHostId
|
||||
#define GetHostName TCP_GetHostName
|
||||
#define GetNetByAddr TCP_GetNetByAddr
|
||||
#define GetNetByName TCP_GetNetByName
|
||||
#define GetPeerName TCP_GetPeerName
|
||||
#define GetProtoByName TCP_GetProtoByName
|
||||
#define GetProtoByNumber TCP_GetProtoByNumber
|
||||
#define GetServByName TCP_GetServByName
|
||||
#define GetServByPort TCP_GetServByPort
|
||||
#define GetSockName TCP_GetSockName
|
||||
#define GetSockOpt TCP_GetSockOpt
|
||||
#define GetSocketEvents TCP_GetSocketEvents
|
||||
#define Inet_Addr TCP_Inet_Addr
|
||||
#define Inet_LnaOf TCP_Inet_LnaOf
|
||||
#define Inet_MakeAddr TCP_Inet_MakeAddr
|
||||
#define Inet_NetOf TCP_Inet_NetOf
|
||||
#define Inet_Network TCP_Inet_Network
|
||||
#define Inet_NtoA(x) TCP_Inet_NtoA((x).s_addr)
|
||||
#define IoctlSocket TCP_IoctlSocket
|
||||
#define Listen TCP_Listen
|
||||
#define ObtainSocket TCP_ObtainSocket
|
||||
#define Recv TCP_Recv
|
||||
#define RecvFrom TCP_RecvFrom
|
||||
#define RecvMsg TCP_RecvMsg
|
||||
#define ReleaseCopyOfSocket TCP_ReleaseCopyOfSocket
|
||||
#define ReleaseSocket TCP_ReleaseSocket
|
||||
#define Send TCP_Send
|
||||
#define SendMsg TCP_SendMsg
|
||||
#define SendTo TCP_SendTo
|
||||
#define SetErrnoPtr TCP_SetErrnoPtr
|
||||
#define SetSockOpt TCP_SetSockOpt
|
||||
#define SetSocketSignals TCP_SetSocketSignals
|
||||
#define ShutDown TCP_ShutDown
|
||||
#define Socket TCP_Socket
|
||||
#define SocketBaseTagList TCP_SocketBaseTagList
|
||||
#define SocketBaseTags TCP_SocketBaseTags
|
||||
#define SyslogA TCP_SyslogA
|
||||
#define WaitSelect TCP_WaitSelect
|
||||
#define Select(n,r,w,e,t) TCP_WaitSelect(n,r,w,e,t,0)
|
||||
//--------------------------------------------------------------------------//
|
||||
#endif
|
|
@ -0,0 +1,203 @@
|
|||
/* Automatically generated header! Do not edit! */
|
||||
|
||||
#ifndef _INLINE_AMITCP_H
|
||||
#define _INLINE_AMITCP_H
|
||||
|
||||
#ifndef __INLINE_MACROS_H
|
||||
#include <inline/macros.h>
|
||||
#endif /* !__INLINE_MACROS_H */
|
||||
|
||||
#ifndef AMITCP_BASE_NAME
|
||||
#define AMITCP_BASE_NAME lss->lx_BsdSocketBase
|
||||
#endif /* !AMITCP_BASE_NAME */
|
||||
|
||||
#define TCP_Accept(s, addr, addrlen) \
|
||||
LP3(0x30, LONG, TCP_Accept, LONG, s, d0, struct sockaddr *, addr, a0, int *, addrlen, a1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Bind(s, name, namelen) \
|
||||
LP3(0x24, LONG, TCP_Bind, LONG, s, d0, const struct sockaddr *, name, a0, LONG, namelen, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_CloseSocket(d) \
|
||||
LP1(0x78, LONG, TCP_CloseSocket, LONG, d, d0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Connect(s, name, namelen) \
|
||||
LP3(0x36, LONG, TCP_Connect, LONG, s, d0, const struct sockaddr *, name, a0, LONG, namelen, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Dup2Socket(fd1, fd2) \
|
||||
LP2(0x108, LONG, TCP_Dup2Socket, LONG, fd1, d0, LONG, fd2, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Errno() \
|
||||
LP0(0xa2, LONG, TCP_Errno, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetDTableSize() \
|
||||
LP0(0x8a, LONG, TCP_GetDTableSize, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetHostByAddr(addr, len, type) \
|
||||
LP3(0xd8, struct hostent *, TCP_GetHostByAddr, const UBYTE *, addr, a0, LONG, len, d0, LONG, type, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetHostByName(name) \
|
||||
LP1(0xd2, struct hostent *, TCP_GetHostByName, const UBYTE *, name, a0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetHostId() \
|
||||
LP0(0x120, ULONG, TCP_GetHostId, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetHostName(hostname, size) \
|
||||
LP2(0x11a, LONG, TCP_GetHostName, STRPTR, hostname, a0, LONG, size, d0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetNetByAddr(net, type) \
|
||||
LP2(0xe4, struct netent *, TCP_GetNetByAddr, LONG, net, d0, LONG, type, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetNetByName(name) \
|
||||
LP1(0xde, struct netent *, TCP_GetNetByName, const UBYTE *, name, a0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetPeerName(s, hostname, namelen) \
|
||||
LP3(0x6c, LONG, TCP_GetPeerName, LONG, s, d0, struct sockaddr *, hostname, a0, int *, namelen, a1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetProtoByName(name) \
|
||||
LP1(0xf6, struct protoent *, TCP_GetProtoByName, const UBYTE *, name, a0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetProtoByNumber(proto) \
|
||||
LP1(0xfc, struct protoent *, TCP_GetProtoByNumber, LONG, proto, d0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetServByName(name, proto) \
|
||||
LP2(0xea, struct servent *, TCP_GetServByName, const UBYTE *, name, a0, const UBYTE *, proto, a1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetServByPort(port, proto) \
|
||||
LP2(0xf0, struct servent *, TCP_GetServByPort, LONG, port, d0, const UBYTE *, proto, a0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetSockName(s, hostname, namelen) \
|
||||
LP3(0x66, LONG, TCP_GetSockName, LONG, s, d0, struct sockaddr *, hostname, a0, int *, namelen, a1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetSockOpt(s, level, optname, optval, optlen) \
|
||||
LP5(0x60, LONG, TCP_GetSockOpt, LONG, s, d0, LONG, level, d1, LONG, optname, d2, void *, optval, a0, int *, optlen, a1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetSocketEvents(eventmaskp) \
|
||||
LP1(0x12c, LONG, TCP_GetSocketEvents, ULONG *, eventmaskp, a0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Inet_Addr(cp) \
|
||||
LP1(0xb4, ULONG, TCP_Inet_Addr, const UBYTE *, cp, a0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Inet_LnaOf(in) \
|
||||
LP1(0xba, ULONG, TCP_Inet_LnaOf, LONG, in, d0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Inet_MakeAddr(net, host) \
|
||||
LP2(0xc6, ULONG, TCP_Inet_MakeAddr, ULONG, net, d0, ULONG, host, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Inet_NetOf(in) \
|
||||
LP1(0xc0, ULONG, TCP_Inet_NetOf, LONG, in, d0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Inet_Network(cp) \
|
||||
LP1(0xcc, ULONG, TCP_Inet_Network, const UBYTE *, cp, a0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Inet_NtoA(in) \
|
||||
LP1(0xae, char *, TCP_Inet_NtoA, ULONG, in, d0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_IoctlSocket(d, request, argp) \
|
||||
LP3(0x72, LONG, TCP_IoctlSocket, LONG, d, d0, ULONG, request, d1, char *, argp, a0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Listen(s, backlog) \
|
||||
LP2(0x2a, LONG, TCP_Listen, LONG, s, d0, LONG, backlog, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_ObtainSocket(id, domain, type, protocol) \
|
||||
LP4(0x90, LONG, TCP_ObtainSocket, LONG, id, d0, LONG, domain, d1, LONG, type, d2, LONG, protocol, d3, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Recv(s, buf, len, flags) \
|
||||
LP4(0x4e, LONG, TCP_Recv, LONG, s, d0, UBYTE *, buf, a0, LONG, len, d1, LONG, flags, d2, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_RecvFrom(s, buf, len, flags, from, fromlen) \
|
||||
LP6(0x48, LONG, TCP_RecvFrom, LONG, s, d0, UBYTE *, buf, a0, LONG, len, d1, LONG, flags, d2, struct sockaddr *, from, a1, int *, fromlen, a2, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_RecvMsg(s, msg, flags) \
|
||||
LP3(0x114, LONG, TCP_RecvMsg, LONG, s, d0, struct msghdr *, msg, a0, LONG, flags, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_ReleaseCopyOfSocket(fd, id) \
|
||||
LP2(0x9c, LONG, TCP_ReleaseCopyOfSocket, LONG, fd, d0, LONG, id, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_ReleaseSocket(fd, id) \
|
||||
LP2(0x96, LONG, TCP_ReleaseSocket, LONG, fd, d0, LONG, id, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Send(s, msg, len, flags) \
|
||||
LP4(0x42, LONG, TCP_Send, LONG, s, d0, const UBYTE *, msg, a0, LONG, len, d1, LONG, flags, d2, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_SendMsg(s, msg, flags) \
|
||||
LP3(0x10e, LONG, TCP_SendMsg, LONG, s, d0, const struct msghdr *, msg, a0, LONG, flags, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_SendTo(s, msg, len, flags, to, tolen) \
|
||||
LP6(0x3c, LONG, TCP_SendTo, LONG, s, d0, const UBYTE *, msg, a0, LONG, len, d1, LONG, flags, d2, const struct sockaddr *, to, a1, LONG, tolen, d3, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_SetErrnoPtr(errno_p, size) \
|
||||
LP2(0xa8, LONG, TCP_SetErrnoPtr, void *, errno_p, a0, LONG, size, d0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_SetSockOpt(s, level, optname, optval, optlen) \
|
||||
LP5(0x5a, LONG, TCP_SetSockOpt, LONG, s, d0, LONG, level, d1, LONG, optname, d2, const void *, optval, a0, LONG, optlen, d3, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_SetSocketSignals(SIGINTR, SIGIO, SIGURG) \
|
||||
LP3NR(0x84, TCP_SetSocketSignals, ULONG, SIGINTR, d0, ULONG, SIGIO, d1, ULONG, SIGURG, d2, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_ShutDown(s, how) \
|
||||
LP2(0x54, LONG, TCP_ShutDown, LONG, s, d0, LONG, how, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Socket(domain, type, protocol) \
|
||||
LP3(0x1e, LONG, TCP_Socket, LONG, domain, d0, LONG, type, d1, LONG, protocol, d2, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_SocketBaseTagList(taglist) \
|
||||
LP1(0x126, LONG, TCP_SocketBaseTagList, struct TagItem *, taglist, a0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#ifndef NO_INLINE_STDARG
|
||||
#define TCP_SocketBaseTags(tags...) \
|
||||
({ULONG _tags[] = { tags }; TCP_SocketBaseTagList((struct TagItem *)_tags);})
|
||||
#endif
|
||||
|
||||
#define TCP_SyslogA(level, format, ap) \
|
||||
LP3NR(0x102, TCP_SyslogA, ULONG, level, d0, const char *, format, a0, va_list, ap, a1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_WaitSelect(nfds, readfds, writefds, execptfds, timeout, maskp) \
|
||||
LP6(0x7e, LONG, TCP_WaitSelect, LONG, nfds, d0, fd_set *, readfds, a0, fd_set *, writefds, a1, fd_set *, execptfds, a2, struct timeval *, timeout, a3, ULONG *, maskp, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#endif /* !_INLINE_AMITCP_H */
|
|
@ -59,7 +59,8 @@
|
|||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include "net_getaddrinfo.h"
|
||||
#include "fping.h"
|
||||
#include "inet_getaddrinfo.h"
|
||||
|
||||
#ifdef ENABLE_PTHREAD
|
||||
#include <pthread.h>
|
||||
|
@ -82,11 +83,6 @@
|
|||
#define N_(string) (string)
|
||||
#endif
|
||||
|
||||
// NOTE: Quickfix
|
||||
#include "clib/exec_protos.h"
|
||||
extern struct Library *SocketBase;
|
||||
#include "clib/amitcp_protos.h"
|
||||
|
||||
/*
|
||||
* Error messages for gai_strerror().
|
||||
*/
|
|
@ -27,8 +27,8 @@
|
|||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef GETADDRINFO_H
|
||||
#define GETADDRINFO_H
|
||||
#ifndef INET_GETADDRINFO_H
|
||||
#define INET_GETADDRINFO_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <netdb.h>
|
||||
|
@ -207,8 +207,6 @@ struct addrinfo {
|
|||
};
|
||||
#endif
|
||||
|
||||
// NOTE: Quickfix
|
||||
#include <sys/types.h>
|
||||
typedef u_int16_t in_port_t;
|
||||
typedef unsigned int sa_family_t;
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
/* $NetBSD: ntohl.c,v 1.3 2012/03/21 20:02:56 he Exp $ */
|
||||
|
||||
/*
|
||||
* Written by J.T. Conklin <jtc@NetBSD.org>.
|
||||
* Public domain.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: ntohl.c,v 1.3 2012/03/21 20:02:56 he Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifndef uint32_t
|
||||
# define uint32_t u_int32_t
|
||||
#endif
|
||||
|
||||
#undef ntohl
|
||||
|
||||
uint32_t
|
||||
ntohl(uint32_t x)
|
||||
{
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
u_char *s = (void *)&x;
|
||||
return (uint32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]);
|
||||
#else
|
||||
return x;
|
||||
#endif
|
||||
}
|
102
src/inet_ntop.c
102
src/inet_ntop.c
|
@ -2,22 +2,22 @@
|
|||
* Copyright (c) 1999 - 2001 Kungliga Tekniska Högskolan
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
* 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 Institute 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 INSTITUTE 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
|
||||
|
@ -29,12 +29,14 @@
|
|||
* 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.
|
||||
*
|
||||
* $Heimdal: inet_ntop.c 21005 2007-06-08 01:54:35Z lha $
|
||||
* $NetBSD: inet_ntop.c,v 1.2 2008/03/22 08:37:21 mlelstv Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
__RCSID("$Heimdal: inet_ntop.c 21005 2007-06-08 01:54:35Z lha $"
|
||||
"$NetBSD: inet_ntop.c,v 1.2 2008/03/22 08:37:21 mlelstv Exp $");
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -49,10 +51,6 @@ __RCSID("$Heimdal: inet_ntop.c 21005 2007-06-08 01:54:35Z lha $"
|
|||
# define INET_ADDRSTRLEN 16
|
||||
#endif
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
static const char *
|
||||
inet_ntop_v4 (const void *src, char *dst, size_t size)
|
||||
{
|
||||
|
@ -63,26 +61,26 @@ inet_ntop_v4 (const void *src, char *dst, size_t size)
|
|||
const char *orig_dst = dst;
|
||||
|
||||
if (size < INET_ADDRSTRLEN) {
|
||||
errno = ENOSPC;
|
||||
return NULL;
|
||||
errno = ENOSPC;
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < 4; ++i) {
|
||||
int n = (a >> (24 - i * 8)) & 0xFF;
|
||||
int non_zerop = 0;
|
||||
int n = (a >> (24 - i * 8)) & 0xFF;
|
||||
int non_zerop = 0;
|
||||
|
||||
if (non_zerop || n / 100 > 0) {
|
||||
*dst++ = digits[n / 100];
|
||||
n %= 100;
|
||||
non_zerop = 1;
|
||||
}
|
||||
if (non_zerop || n / 10 > 0) {
|
||||
*dst++ = digits[n / 10];
|
||||
n %= 10;
|
||||
non_zerop = 1;
|
||||
}
|
||||
*dst++ = digits[n];
|
||||
if (i != 3)
|
||||
*dst++ = '.';
|
||||
if (non_zerop || n / 100 > 0) {
|
||||
*dst++ = digits[n / 100];
|
||||
n %= 100;
|
||||
non_zerop = 1;
|
||||
}
|
||||
if (non_zerop || n / 10 > 0) {
|
||||
*dst++ = digits[n / 10];
|
||||
n %= 10;
|
||||
non_zerop = 1;
|
||||
}
|
||||
*dst++ = digits[n];
|
||||
if (i != 3)
|
||||
*dst++ = '.';
|
||||
}
|
||||
*dst++ = '\0';
|
||||
return orig_dst;
|
||||
|
@ -99,28 +97,28 @@ inet_ntop_v6 (const void *src, char *dst, size_t size)
|
|||
const char *orig_dst = dst;
|
||||
|
||||
if (size < INET6_ADDRSTRLEN) {
|
||||
errno = ENOSPC;
|
||||
return NULL;
|
||||
errno = ENOSPC;
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < 8; ++i) {
|
||||
int non_zerop = 0;
|
||||
int non_zerop = 0;
|
||||
|
||||
if (non_zerop || (ptr[0] >> 4)) {
|
||||
*dst++ = xdigits[ptr[0] >> 4];
|
||||
non_zerop = 1;
|
||||
}
|
||||
if (non_zerop || (ptr[0] & 0x0F)) {
|
||||
*dst++ = xdigits[ptr[0] & 0x0F];
|
||||
non_zerop = 1;
|
||||
}
|
||||
if (non_zerop || (ptr[1] >> 4)) {
|
||||
*dst++ = xdigits[ptr[1] >> 4];
|
||||
non_zerop = 1;
|
||||
}
|
||||
*dst++ = xdigits[ptr[1] & 0x0F];
|
||||
if (i != 7)
|
||||
*dst++ = ':';
|
||||
ptr += 2;
|
||||
if (non_zerop || (ptr[0] >> 4)) {
|
||||
*dst++ = xdigits[ptr[0] >> 4];
|
||||
non_zerop = 1;
|
||||
}
|
||||
if (non_zerop || (ptr[0] & 0x0F)) {
|
||||
*dst++ = xdigits[ptr[0] & 0x0F];
|
||||
non_zerop = 1;
|
||||
}
|
||||
if (non_zerop || (ptr[1] >> 4)) {
|
||||
*dst++ = xdigits[ptr[1] >> 4];
|
||||
non_zerop = 1;
|
||||
}
|
||||
*dst++ = xdigits[ptr[1] & 0x0F];
|
||||
if (i != 7)
|
||||
*dst++ = ':';
|
||||
ptr += 2;
|
||||
}
|
||||
*dst++ = '\0';
|
||||
return orig_dst;
|
||||
|
@ -132,13 +130,13 @@ inet_ntop(int af, const void *src, char *dst, size_t size)
|
|||
{
|
||||
switch (af) {
|
||||
case AF_INET :
|
||||
return inet_ntop_v4 (src, dst, size);
|
||||
return inet_ntop_v4 (src, dst, size);
|
||||
#ifdef HAVE_IPV6
|
||||
case AF_INET6 :
|
||||
return inet_ntop_v6 (src, dst, size);
|
||||
return inet_ntop_v6 (src, dst, size);
|
||||
#endif
|
||||
default :
|
||||
errno = EAFNOSUPPORT;
|
||||
return NULL;
|
||||
errno = EAFNOSUPPORT;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
|
378
src/inet_pton.c
378
src/inet_pton.c
|
@ -1,6 +1,3 @@
|
|||
/* $NetBSD: inet_pton.c,v 1.9 2007/07/23 11:45:52 lukem Exp $ */
|
||||
/* from NetBSD: inet_pton.c,v 1.3 2006/09/26 05:59:18 lukem Exp */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
|
||||
* Copyright (c) 1996,1999 by Internet Software Consortium.
|
||||
|
@ -16,9 +13,15 @@
|
|||
* 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.
|
||||
*
|
||||
*
|
||||
* $NetBSD: inet_pton.c,v 1.9 2007/07/23 11:45:52 lukem Exp $
|
||||
* from NetBSD: inet_pton.c,v 1.3 2006/09/26 05:59:18 lukem Exp
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
@ -65,18 +68,18 @@ int
|
|||
inet_pton(int af, const char *src, void *dst)
|
||||
{
|
||||
|
||||
switch (af) {
|
||||
case AF_INET:
|
||||
return (inet_pton4(src, dst, 1));
|
||||
switch (af) {
|
||||
case AF_INET:
|
||||
return (inet_pton4(src, dst, 1));
|
||||
#ifdef INET6
|
||||
case AF_INET6:
|
||||
return (inet_pton6(src, dst));
|
||||
case AF_INET6:
|
||||
return (inet_pton6(src, dst));
|
||||
#endif /* INET6 */
|
||||
default:
|
||||
errno = EAFNOSUPPORT;
|
||||
return (-1);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
default:
|
||||
errno = EAFNOSUPPORT;
|
||||
return (-1);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
/* int
|
||||
|
@ -93,108 +96,109 @@ inet_pton(int af, const char *src, void *dst)
|
|||
static int
|
||||
inet_pton4(const char *src, unsigned char *dst, int pton)
|
||||
{
|
||||
uint32_t val;
|
||||
unsigned int digit, base;
|
||||
int n;
|
||||
unsigned char c;
|
||||
unsigned int parts[4];
|
||||
register unsigned int *pp = parts;
|
||||
uint32_t val;
|
||||
unsigned int digit, base;
|
||||
int n;
|
||||
unsigned char c;
|
||||
unsigned int parts[4];
|
||||
register unsigned int *pp = parts;
|
||||
|
||||
c = *src;
|
||||
for (;;) {
|
||||
/*
|
||||
* Collect number up to ``.''.
|
||||
* Values are specified as for C:
|
||||
* 0x=hex, 0=octal, isdigit=decimal.
|
||||
*/
|
||||
if (!isdigit(c))
|
||||
return (0);
|
||||
val = 0; base = 10;
|
||||
if (c == '0') {
|
||||
c = *++src;
|
||||
if (c == 'x' || c == 'X')
|
||||
base = 16, c = *++src;
|
||||
else if (isdigit(c) && c != '9')
|
||||
base = 8;
|
||||
}
|
||||
/* inet_pton() takes decimal only */
|
||||
if (pton && base != 10)
|
||||
return (0);
|
||||
for (;;) {
|
||||
if (isdigit(c)) {
|
||||
digit = c - '0';
|
||||
if (digit >= base)
|
||||
break;
|
||||
val = (val * base) + digit;
|
||||
c = *++src;
|
||||
} else if (base == 16 && isxdigit(c)) {
|
||||
digit = c + 10 - (islower(c) ? 'a' : 'A');
|
||||
if (digit >= 16)
|
||||
break;
|
||||
val = (val << 4) | digit;
|
||||
c = *++src;
|
||||
} 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)
|
||||
* a (with a treated as 32 bits)
|
||||
*/
|
||||
if (pp >= parts + 3)
|
||||
return (0);
|
||||
*pp++ = val;
|
||||
c = *++src;
|
||||
} else
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Check for trailing characters.
|
||||
*/
|
||||
if (c != '\0' && !isspace(c))
|
||||
return (0);
|
||||
/*
|
||||
* Concoct the address according to
|
||||
* the number of parts specified.
|
||||
*/
|
||||
n = pp - parts + 1;
|
||||
/* inet_pton() takes dotted-quad only. it does not take shorthand. */
|
||||
if (pton && n != 4)
|
||||
return (0);
|
||||
switch (n) {
|
||||
c = *src;
|
||||
for (;;) {
|
||||
/*
|
||||
* Collect number up to ``.''.
|
||||
* Values are specified as for C:
|
||||
* 0x=hex, 0=octal, isdigit=decimal.
|
||||
*/
|
||||
if (!isdigit(c))
|
||||
return (0);
|
||||
val = 0;
|
||||
base = 10;
|
||||
if (c == '0') {
|
||||
c = *++src;
|
||||
if (c == 'x' || c == 'X')
|
||||
base = 16, c = *++src;
|
||||
else if (isdigit(c) && c != '9')
|
||||
base = 8;
|
||||
}
|
||||
/* inet_pton() takes decimal only */
|
||||
if (pton && base != 10)
|
||||
return (0);
|
||||
for (;;) {
|
||||
if (isdigit(c)) {
|
||||
digit = c - '0';
|
||||
if (digit >= base)
|
||||
break;
|
||||
val = (val * base) + digit;
|
||||
c = *++src;
|
||||
} else if (base == 16 && isxdigit(c)) {
|
||||
digit = c + 10 - (islower(c) ? 'a' : 'A');
|
||||
if (digit >= 16)
|
||||
break;
|
||||
val = (val << 4) | digit;
|
||||
c = *++src;
|
||||
} 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)
|
||||
* a (with a treated as 32 bits)
|
||||
*/
|
||||
if (pp >= parts + 3)
|
||||
return (0);
|
||||
*pp++ = val;
|
||||
c = *++src;
|
||||
} else
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Check for trailing characters.
|
||||
*/
|
||||
if (c != '\0' && !isspace(c))
|
||||
return (0);
|
||||
/*
|
||||
* Concoct the address according to
|
||||
* the number of parts specified.
|
||||
*/
|
||||
n = pp - parts + 1;
|
||||
/* inet_pton() takes dotted-quad only. it does not take shorthand. */
|
||||
if (pton && n != 4)
|
||||
return (0);
|
||||
switch (n) {
|
||||
|
||||
case 0:
|
||||
return (0); /* initial nondigit */
|
||||
case 0:
|
||||
return (0); /* initial nondigit */
|
||||
|
||||
case 1: /* a -- 32 bits */
|
||||
break;
|
||||
case 1: /* a -- 32 bits */
|
||||
break;
|
||||
|
||||
case 2: /* a.b -- 8.24 bits */
|
||||
if (parts[0] > 0xff || val > 0xffffff)
|
||||
return (0);
|
||||
val |= parts[0] << 24;
|
||||
break;
|
||||
case 2: /* a.b -- 8.24 bits */
|
||||
if (parts[0] > 0xff || val > 0xffffff)
|
||||
return (0);
|
||||
val |= parts[0] << 24;
|
||||
break;
|
||||
|
||||
case 3: /* a.b.c -- 8.8.16 bits */
|
||||
if ((parts[0] | parts[1]) > 0xff || val > 0xffff)
|
||||
return (0);
|
||||
val |= (parts[0] << 24) | (parts[1] << 16);
|
||||
break;
|
||||
case 3: /* a.b.c -- 8.8.16 bits */
|
||||
if ((parts[0] | parts[1]) > 0xff || val > 0xffff)
|
||||
return (0);
|
||||
val |= (parts[0] << 24) | (parts[1] << 16);
|
||||
break;
|
||||
|
||||
case 4: /* a.b.c.d -- 8.8.8.8 bits */
|
||||
if ((parts[0] | parts[1] | parts[2] | val) > 0xff)
|
||||
return (0);
|
||||
val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
|
||||
break;
|
||||
}
|
||||
if (dst) {
|
||||
val = htonl(val);
|
||||
memcpy(dst, &val, NS_INADDRSZ);
|
||||
}
|
||||
return (1);
|
||||
case 4: /* a.b.c.d -- 8.8.8.8 bits */
|
||||
if ((parts[0] | parts[1] | parts[2] | val) > 0xff)
|
||||
return (0);
|
||||
val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
|
||||
break;
|
||||
}
|
||||
if (dst) {
|
||||
val = htonl(val);
|
||||
memcpy(dst, &val, NS_INADDRSZ);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
#ifdef INET6
|
||||
|
@ -214,86 +218,86 @@ inet_pton4(const char *src, unsigned char *dst, int pton)
|
|||
static int
|
||||
inet_pton6(const char *src, unsigned char *dst)
|
||||
{
|
||||
static const char xdigits_l[] = "0123456789abcdef",
|
||||
xdigits_u[] = "0123456789ABCDEF";
|
||||
unsigned char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
|
||||
const char *xdigits, *curtok;
|
||||
int ch, saw_xdigit;
|
||||
unsigned int val;
|
||||
static const char xdigits_l[] = "0123456789abcdef",
|
||||
xdigits_u[] = "0123456789ABCDEF";
|
||||
unsigned char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
|
||||
const char *xdigits, *curtok;
|
||||
int ch, saw_xdigit;
|
||||
unsigned int val;
|
||||
|
||||
memset((tp = tmp), '\0', NS_IN6ADDRSZ);
|
||||
endp = tp + NS_IN6ADDRSZ;
|
||||
colonp = NULL;
|
||||
/* Leading :: requires some special handling. */
|
||||
if (*src == ':')
|
||||
if (*++src != ':')
|
||||
return (0);
|
||||
curtok = src;
|
||||
saw_xdigit = 0;
|
||||
val = 0;
|
||||
while ((ch = *src++) != '\0') {
|
||||
const char *pch;
|
||||
memset((tp = tmp), '\0', NS_IN6ADDRSZ);
|
||||
endp = tp + NS_IN6ADDRSZ;
|
||||
colonp = NULL;
|
||||
/* Leading :: requires some special handling. */
|
||||
if (*src == ':')
|
||||
if (*++src != ':')
|
||||
return (0);
|
||||
curtok = src;
|
||||
saw_xdigit = 0;
|
||||
val = 0;
|
||||
while ((ch = *src++) != '\0') {
|
||||
const char *pch;
|
||||
|
||||
if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
|
||||
pch = strchr((xdigits = xdigits_u), ch);
|
||||
if (pch != NULL) {
|
||||
val <<= 4;
|
||||
val |= (pch - xdigits);
|
||||
if (val > 0xffff)
|
||||
return (0);
|
||||
saw_xdigit = 1;
|
||||
continue;
|
||||
}
|
||||
if (ch == ':') {
|
||||
curtok = src;
|
||||
if (!saw_xdigit) {
|
||||
if (colonp)
|
||||
return (0);
|
||||
colonp = tp;
|
||||
continue;
|
||||
} else if (*src == '\0')
|
||||
return (0);
|
||||
if (tp + NS_INT16SZ > endp)
|
||||
return (0);
|
||||
*tp++ = (unsigned char) (val >> 8) & 0xff;
|
||||
*tp++ = (unsigned char) val & 0xff;
|
||||
saw_xdigit = 0;
|
||||
val = 0;
|
||||
continue;
|
||||
}
|
||||
if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
|
||||
inet_pton4(curtok, tp, 1) > 0) {
|
||||
tp += NS_INADDRSZ;
|
||||
saw_xdigit = 0;
|
||||
break; /* '\0' was seen by inet_pton4(). */
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
if (saw_xdigit) {
|
||||
if (tp + NS_INT16SZ > endp)
|
||||
return (0);
|
||||
*tp++ = (unsigned char) (val >> 8) & 0xff;
|
||||
*tp++ = (unsigned char) val & 0xff;
|
||||
}
|
||||
if (colonp != NULL) {
|
||||
/*
|
||||
* Since some memmove()'s erroneously fail to handle
|
||||
* overlapping regions, we'll do the shift by hand.
|
||||
*/
|
||||
const int n = tp - colonp;
|
||||
int i;
|
||||
if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
|
||||
pch = strchr((xdigits = xdigits_u), ch);
|
||||
if (pch != NULL) {
|
||||
val <<= 4;
|
||||
val |= (pch - xdigits);
|
||||
if (val > 0xffff)
|
||||
return (0);
|
||||
saw_xdigit = 1;
|
||||
continue;
|
||||
}
|
||||
if (ch == ':') {
|
||||
curtok = src;
|
||||
if (!saw_xdigit) {
|
||||
if (colonp)
|
||||
return (0);
|
||||
colonp = tp;
|
||||
continue;
|
||||
} else if (*src == '\0')
|
||||
return (0);
|
||||
if (tp + NS_INT16SZ > endp)
|
||||
return (0);
|
||||
*tp++ = (unsigned char) (val >> 8) & 0xff;
|
||||
*tp++ = (unsigned char) val & 0xff;
|
||||
saw_xdigit = 0;
|
||||
val = 0;
|
||||
continue;
|
||||
}
|
||||
if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
|
||||
inet_pton4(curtok, tp, 1) > 0) {
|
||||
tp += NS_INADDRSZ;
|
||||
saw_xdigit = 0;
|
||||
break; /* '\0' was seen by inet_pton4(). */
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
if (saw_xdigit) {
|
||||
if (tp + NS_INT16SZ > endp)
|
||||
return (0);
|
||||
*tp++ = (unsigned char) (val >> 8) & 0xff;
|
||||
*tp++ = (unsigned char) val & 0xff;
|
||||
}
|
||||
if (colonp != NULL) {
|
||||
/*
|
||||
* Since some memmove()'s erroneously fail to handle
|
||||
* overlapping regions, we'll do the shift by hand.
|
||||
*/
|
||||
const int n = tp - colonp;
|
||||
int i;
|
||||
|
||||
if (tp == endp)
|
||||
return (0);
|
||||
for (i = 1; i <= n; i++) {
|
||||
endp[- i] = colonp[n - i];
|
||||
colonp[n - i] = 0;
|
||||
}
|
||||
tp = endp;
|
||||
}
|
||||
if (tp != endp)
|
||||
return (0);
|
||||
memcpy(dst, tmp, NS_IN6ADDRSZ);
|
||||
return (1);
|
||||
if (tp == endp)
|
||||
return (0);
|
||||
for (i = 1; i <= n; i++) {
|
||||
endp[- i] = colonp[n - i];
|
||||
colonp[n - i] = 0;
|
||||
}
|
||||
tp = endp;
|
||||
}
|
||||
if (tp != endp)
|
||||
return (0);
|
||||
memcpy(dst, tmp, NS_IN6ADDRSZ);
|
||||
return (1);
|
||||
}
|
||||
#endif /* INET6 */
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
|
||||
/*
|
||||
* Interval is the minimum amount of time between sending a ping packet to
|
||||
/*
|
||||
* Interval is the minimum amount of time between sending a ping packet to
|
||||
* any host.
|
||||
*
|
||||
* Perhost_interval is the minimum amount of time between sending a ping
|
||||
*
|
||||
* Perhost_interval is the minimum amount of time between sending a ping
|
||||
* packet to a particular responding host (when count is > 1)
|
||||
*
|
||||
*
|
||||
* Timeout is the initial amount of time between sending a ping packet to
|
||||
* a particular non-responding host.
|
||||
*
|
||||
*
|
||||
* Retry is the number of ping packets to send to a non-responding host
|
||||
* before giving up (in is-it-alive mode).
|
||||
*
|
||||
*
|
||||
* Backoff factor is how much longer to wait on successive retries.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/* constants */
|
||||
|
@ -32,7 +32,7 @@
|
|||
#endif
|
||||
|
||||
|
||||
#ifndef DEFAULT_RETRY
|
||||
#ifndef DEFAULT_RETRY
|
||||
#define DEFAULT_RETRY 3 /* number of times to retry a host */
|
||||
#endif
|
||||
|
||||
|
|
14
src/seqmap.c
14
src/seqmap.c
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* fping: fast-ping, file-ping, favorite-ping, funky-ping
|
||||
*
|
||||
* Ping a list of target hosts in a round robin fashion.
|
||||
|
@ -22,8 +22,8 @@
|
|||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by Stanford University. The name of the University may not be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* by Stanford University. The name of the University may not be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
|
@ -37,7 +37,7 @@
|
|||
|
||||
#include "seqmap.h"
|
||||
#include "options.h"
|
||||
#include "limits.h"
|
||||
#include <limits.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
@ -53,15 +53,13 @@
|
|||
|
||||
static SEQMAP_VALUE *seqmap_map = NULL;
|
||||
static unsigned int seqmap_next_id = 0;
|
||||
static SEQMAP_VALUE *seqmap_free_list;
|
||||
//static SEQMAP_VALUE *seqmap_free_list;
|
||||
|
||||
#define SEQMAP_TIMEOUT_IN_S 10
|
||||
#define SEQMAP_UNASSIGNED_HOST_NR UINT_MAX
|
||||
|
||||
void seqmap_init()
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
seqmap_map = calloc(SEQMAP_MAXSEQ, sizeof(SEQMAP_VALUE));
|
||||
if(seqmap_map == NULL) {
|
||||
perror("malloc error (can't allocate seqmap_map)");
|
||||
|
@ -83,7 +81,7 @@ unsigned int seqmap_add(unsigned int host_nr, unsigned int ping_count, struct ti
|
|||
next_value = &seqmap_map[seqmap_next_id];
|
||||
if(next_value->ping_ts.tv_sec != 0 && (now->tv_sec - next_value->ping_ts.tv_sec) < SEQMAP_TIMEOUT_IN_S) {
|
||||
fprintf(stderr, "fping error: not enough sequence numbers available! (expire_timeout=%d, host_nr=%d, ping_count=%d, seqmap_next_id=%d)\n",
|
||||
SEQMAP_TIMEOUT_IN_S, host_nr, ping_count, seqmap_next_id);
|
||||
SEQMAP_TIMEOUT_IN_S, host_nr, ping_count, seqmap_next_id);
|
||||
exit(4);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* fping: fast-ping, file-ping, favorite-ping, funky-ping
|
||||
*
|
||||
* Ping a list of target hosts in a round robin fashion.
|
||||
|
@ -22,8 +22,8 @@
|
|||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by Stanford University. The name of the University may not be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* by Stanford University. The name of the University may not be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* fping: fast-ping, file-ping, favorite-ping, funky-ping
|
||||
*
|
||||
* Ping a list of target hosts in a round robin fashion.
|
||||
|
@ -22,8 +22,8 @@
|
|||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by Stanford University. The name of the University may not be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* by Stanford University. The name of the University may not be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
|
@ -45,7 +45,7 @@ int open_ping_socket_ipv4()
|
|||
int s;
|
||||
|
||||
/* confirm that ICMP is available on this machine */
|
||||
if( ( proto = getprotobyname( "icmp" ) ) == NULL )
|
||||
if( ( proto = getprotobyname( "icmp" ) ) == NULL )
|
||||
crash_and_burn( "icmp: unknown protocol" );
|
||||
|
||||
/* create raw socket for ICMP calls (ping) */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* fping: fast-ping, file-ping, favorite-ping, funky-ping
|
||||
*
|
||||
* Ping a list of target hosts in a round robin fashion.
|
||||
|
@ -22,8 +22,8 @@
|
|||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by Stanford University. The name of the University may not be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* by Stanford University. The name of the University may not be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
|
@ -48,7 +48,7 @@ int open_ping_socket_ipv6()
|
|||
int s;
|
||||
|
||||
/* confirm that ICMP is available on this machine */
|
||||
if( ( proto = getprotobyname( "ipv6-icmp" ) ) == NULL )
|
||||
if( ( proto = getprotobyname( "ipv6-icmp" ) ) == NULL )
|
||||
crash_and_burn( "icmp: unknown protocol" );
|
||||
|
||||
/* create raw socket for ICMP calls (ping) */
|
||||
|
|
Loading…
Reference in New Issue