diff --git a/.gitignore b/.gitignore index 3908e69..3b59125 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,4 @@ CHANGES.dist c-ares-*.tar.gz.asc ares_parse_mx_reply.pdf /[0-9]*.patch +*.kdev4 diff --git a/Makefile.inc b/Makefile.inc index 22580b7..57ef107 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -46,7 +46,8 @@ CSOURCES = ares__close_sockets.c \ bitncmp.c \ inet_net_pton.c \ inet_ntop.c \ - windows_port.c + windows_port.c \ + amiga_port.c HHEADERS = ares.h \ ares_build.h \ diff --git a/Makefile.m68k b/Makefile.m68k new file mode 100644 index 0000000..d5e285f --- /dev/null +++ b/Makefile.m68k @@ -0,0 +1,72 @@ +LIB = libcares.a +AR = m68k-amigaos-ar +CC = m68k-amigaos-gcc +LD = m68k-amigaos-gcc +RANLIB = m68k-amigaos-ranlib +RM = rm -f +CP = cp -afv +CFLAGS = -O2 -Wall -I. -Iinclude -DHAVE_CONFIG_H -DCARES_STATICLIB -DAOS3 +LDFLAGS = -noixemul -s +LIBS = -lm + +# Makefile.inc provides the CSOURCES and HHEADERS defines +include Makefile.inc + +OBJLIB := $(patsubst %.c,%.o,$(strip $(CSOURCES))) + + +$(LIB): $(OBJLIB) + $(AR) cru $@ $^ + $(RANLIB) $@ + +all: $(LIB) demos doc + +doc: + ./workman1 adig.1 >adig.txt + ./workman2 adig.1 >adig.help + ./workman1 ahost.1 >ahost.txt + ./workman2 ahost.1 >ahost.help + ./workman1 acountry.1 >acountry.txt + ./workman2 acountry.1 >acountry.help + +demos: adig.exe ahost.exe acountry.exe + +tags: + etags *.[ch] + +%.exe: %.o ares_getopt.o $(LIB) + $(LD) $(LDFLAGS) -o $@ $^ $(LIBS) + +$(OBJLIB): ares.h ares_dns.h ares_private.h ares_build.h ares_rules.h + +.c.o: + $(CC) $(CFLAGS) -c $< + +ares_build.h: + $(CP) ares_build.h.dist ares_build.h + +check: + +install: + ${top_srcdir}/mkinstalldirs ${DESTDIR}${libdir} + ${top_srcdir}/mkinstalldirs ${DESTDIR}${includedir} + ${top_srcdir}/mkinstalldirs ${DESTDIR}${mandir}/man3 + ${INSTALL} -m 644 $(LIB) ${DESTDIR}${libdir} + ${RANLIB} ${DESTDIR}${libdir}/$(LIB) + chmod u-w ${DESTDIR}${libdir}/$(LIB) + ${INSTALL} -m 444 ${srcdir}/ares.h ${DESTDIR}${includedir} + ${INSTALL} -m 444 ${srcdir}/ares_build.h ${DESTDIR}${includedir} + ${INSTALL} -m 444 ${srcdir}/ares_rules.h ${DESTDIR}${includedir} + (for man in $(MANPAGES); do \ + ${INSTALL} -m 444 ${srcdir}/$${man} ${DESTDIR}${mandir}/man3; \ + done) + +clean: + $(RM) ares_getopt.o $(OBJLIB) $(LIB) adig.exe ahost.exe acountry.exe adig.txt adig.help ahost.txt ahost.help acountry.txt acountry.help + +distclean: clean + $(RM) config.cache config.log config.status Makefile +ifeq "$(wildcard ares_build.h.dist)" "ares_build.h.dist" + $(RM) ares_build.h +endif + diff --git a/acountry.c b/acountry.c index e157702..f2e4d4b 100644 --- a/acountry.c +++ b/acountry.c @@ -41,8 +41,8 @@ #if defined(WIN32) && !defined(WATT32) #include #else - #include #include + #include #include #endif @@ -94,11 +94,15 @@ static void Abort(const char *fmt, ...) exit(1); } +const char *vers = "\0$VER: acountry 1.11 (01.03.2016) c-ares 1.11.0"; + int main(int argc, char **argv) { ares_channel channel; int ch, status; + prog = argv[0]; + #if defined(WIN32) && !defined(WATT32) WORD wVersionRequested = MAKEWORD(USE_WINSOCK,USE_WINSOCK); WSADATA wsaData; @@ -161,11 +165,12 @@ int main(int argc, char **argv) } } + // NOTICE: Not endian neutral sprintf(buf, nerd_fmt, - (unsigned int)(addr.s_addr >> 24), - (unsigned int)((addr.s_addr >> 16) & 255), + (unsigned int)(addr.s_addr & 255), (unsigned int)((addr.s_addr >> 8) & 255), - (unsigned int)(addr.s_addr & 255)); + (unsigned int)((addr.s_addr >> 16) & 255), + (unsigned int)(addr.s_addr >> 24)); TRACE(("Looking up %s...", buf)); fflush(stdout); ares_gethostbyname(channel, buf, AF_INET, callback, buf); @@ -525,7 +530,7 @@ static int is_addr(char *str, char **end) int a0, a1, a2, a3, num, rc = 0, length = 0; num = sscanf(str,"%3d.%3d.%3d.%3d%n",&a0,&a1,&a2,&a3,&length); - if( (num == 4) && + if( (num == 4 || num == 5) && BYTE_OK(a0) && BYTE_OK(a1) && BYTE_OK(a2) && BYTE_OK(a3) && length >= (3+4)) { diff --git a/adig.c b/adig.c index e112dc0..6905330 100644 --- a/adig.c +++ b/adig.c @@ -178,6 +178,8 @@ static void destroy_addr_list(struct ares_addr_node *head); static void append_addr_list(struct ares_addr_node **head, struct ares_addr_node *node); +const char *vers = "\0$VER: adig 1.11 (01.03.2016) c-ares 1.11.0"; + int main(int argc, char **argv) { ares_channel channel; @@ -195,6 +197,8 @@ int main(int argc, char **argv) WSAStartup(wVersionRequested, &wsaData); #endif + prog = argv[0]; + status = ares_library_init(ARES_LIB_INIT_ALL); if (status != ARES_SUCCESS) { diff --git a/ahost.c b/ahost.c index dec66a9..bc18b84 100644 --- a/ahost.c +++ b/ahost.c @@ -50,6 +50,8 @@ static void callback(void *arg, int status, int timeouts, struct hostent *host); static void usage(void); +const char *vers = "\0$VER: ahost 1.11 (01.03.2016) c-ares 1.11.0"; + int main(int argc, char **argv) { struct ares_options options; @@ -61,6 +63,8 @@ int main(int argc, char **argv) struct in_addr addr4; struct ares_in6_addr addr6; + prog = argv[0]; + #ifdef USE_WINSOCK WORD wVersionRequested = MAKEWORD(USE_WINSOCK,USE_WINSOCK); WSADATA wsaData; diff --git a/amiga_port.c b/amiga_port.c new file mode 100644 index 0000000..5026f58 --- /dev/null +++ b/amiga_port.c @@ -0,0 +1,92 @@ +#include "ares_setup.h" +#if defined(AOS3) || defined(AROS) + + +/* + * Written by Carsten Larsen. + * Public domain. + */ + +#include +#include +#include +#include +#include +#include +#include + +#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 LIB_ERROR 5 + +#ifdef AOS3 +#define IPTR ULONG +#endif + +#ifdef AOS3 +int h_errno; +#endif + +struct Library* DOSBase = NULL; +struct Library* SocketBase = NULL; +struct Library* UtilityBase = NULL; +struct Device* TimerBase = NULL; +struct timerequest* TimeRequest = NULL; + +char *prog; + +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 ares_amiga_cleanup() +{ + if (SocketBase != NULL) { + CloseLibrary(SocketBase); + SocketBase = NULL; + } + + if (DOSBase != NULL) { + CloseLibrary(DOSBase); + DOSBase = NULL; + } +} + +int ares_amiga_init() +{ + struct timeval tv; + + if(!(DOSBase = OpenLibrary((STRPTR)DOSLIB_NAME, DOSLIB_REV))) { + amiga_open_lib_error(DOSLIB_NAME, DOSLIB_REV); + return LIB_ERROR; + } + + if(!(SocketBase = OpenLibrary((STRPTR)BSDLIB_NAME, BSDLIB_REV))) { + amiga_open_lib_error(BSDLIB_NAME, BSDLIB_REV); + return LIB_ERROR; + } else { + SocketBaseTags( + SBTM_SETVAL(SBTC_ERRNOPTR(sizeof(errno))), (IPTR) &errno, + SBTM_SETVAL(SBTC_HERRNOLONGPTR), (IPTR) &h_errno, + SBTM_SETVAL(SBTC_LOGTAGPTR), (IPTR) &prog, + TAG_DONE ); + } + + gettimeofday(&tv, NULL); + srand(tv.tv_sec); + + return 0; +} + +#endif + diff --git a/appveyor.yml b/appveyor.yml index 9111ac9..985fb53 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,13 +1,11 @@ platform: - x64 - x86 - - mingw build_script: - if "%platform%" == "x86" call "%VS120COMNTOOLS%\..\..\VC\vcvarsall.bat" - if "%platform%" == "x64" "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64 - if "%platform%" == "x64" call "%VS120COMNTOOLS%\..\..\VC\vcvarsall.bat" x86_amd64 - - if "%platform%" == "mingw" set PATH=%PATH%;C:\MinGW\bin;C:\MinGW\MSYS\1.0\local\bin;C:\MinGW\MSYS\1.0\bin - copy ares_build.h.dist ares_build.h - - if "%platform%" == "mingw" ( make -f Makefile.m32 demos ) else ( nmake /f Makefile.msvc ) + - nmake /f Makefile.msvc - cd test - - if "%platform%" == "mingw" ( make -f Makefile.m32 vtest ) else ( nmake /f Makefile.msvc vtest ) + - nmake /f Makefile.msvc vtest diff --git a/ares.h b/ares.h index cd94d4f..3d57760 100644 --- a/ares.h +++ b/ares.h @@ -203,7 +203,8 @@ extern "C" { /* c-ares library initialization flag values */ #define ARES_LIB_INIT_NONE (0) #define ARES_LIB_INIT_WIN32 (1 << 0) -#define ARES_LIB_INIT_ALL (ARES_LIB_INIT_WIN32) +#define ARES_LIB_INIT_AMIGA (2 << 0) +#define ARES_LIB_INIT_ALL (ARES_LIB_INIT_WIN32 | ARES_LIB_INIT_AMIGA) /* diff --git a/ares_dns.h b/ares_dns.h index 79f993b..374954d 100644 --- a/ares_dns.h +++ b/ares_dns.h @@ -16,6 +16,9 @@ * without express or implied warranty. */ +#include + +#if 0 /* * Macro DNS__16BIT reads a network short (16 bit) given in network * byte order, and returns its value as an unsigned short. @@ -40,16 +43,35 @@ ((p)[1] = (unsigned char)(((v) >> 16) & 0xff)), \ ((p)[2] = (unsigned char)(((v) >> 8) & 0xff)), \ ((p)[3] = (unsigned char)((v) & 0xff))) +#endif + #if 0 /* we cannot use this approach on systems where we can't access 16/32 bit data on un-aligned addresses */ +// align recieve buffer with memcpy instead #define DNS__16BIT(p) ntohs(*(unsigned short*)(p)) #define DNS__32BIT(p) ntohl(*(unsigned long*)(p)) #define DNS__SET16BIT(p, v) *(unsigned short*)(p) = htons(v) #define DNS__SET32BIT(p, v) *(unsigned long*)(p) = htonl(v) #endif + +/* use use this approach on systems where we can't access 16/32 bit + data on un-aligned addresses */ +#ifdef ARES_BIG_ENDIAN +#define DNS__16BIT(p) be16dec(p) +#define DNS__32BIT(p) be32dec(p) +#define DNS__SET16BIT(p, v) be16enc(p,v) +#define DNS__SET32BIT(p, v) be32enc +#else +#define DNS__16BIT(p) le16dec(p) +#define DNS__32BIT(p) le32dec(p) +#define DNS__SET16BIT(p, v) le16enc(p,v) +#define DNS__SET32BIT(p, v) le32enc +#endif + + /* Macros for parsing a DNS header */ #define DNS_HEADER_QID(h) DNS__16BIT(h) #define DNS_HEADER_QR(h) (((h)[2] >> 7) & 0x1) diff --git a/ares_init.c b/ares_init.c index 55d9327..47180cd 100644 --- a/ares_init.c +++ b/ares_init.c @@ -1302,6 +1302,8 @@ static int init_by_resolv_conf(ares_channel channel) } } + config_nameserver(&servers, &nservers, "8.8.8.8"); + if ((status == ARES_EOF) && (!channel->lookups)) { /* Many systems (Solaris, Linux, BSD's) use nsswitch.conf */ fp = fopen("/etc/nsswitch.conf", "r"); diff --git a/ares_library_init.c b/ares_library_init.c index c2bfb09..964a02a 100644 --- a/ares_library_init.c +++ b/ares_library_init.c @@ -119,6 +119,13 @@ int ares_library_init(int flags) return res; /* LCOV_EXCL_LINE: can't test Win32 init failure */ } + if (flags & ARES_LIB_INIT_AMIGA) + { + res = ares_amiga_init(); + if (res != ARES_SUCCESS) + return res; + } + ares_init_flags = flags; return ARES_SUCCESS; @@ -150,6 +157,9 @@ void ares_library_cleanup(void) if (ares_init_flags & ARES_LIB_INIT_WIN32) ares_win32_cleanup(); + if (ares_init_flags & ARES_LIB_INIT_WIN32) + ares_amiga_cleanup(); + ares_init_flags = ARES_LIB_INIT_NONE; ares_malloc = malloc; ares_free = free; @@ -161,6 +171,10 @@ int ares_library_initialized(void) #ifdef USE_WINSOCK if (!ares_initialized) return ARES_ENOTINITIALIZED; +#endif +#ifdef AOS3 + if (!ares_initialized) + return ARES_ENOTINITIALIZED; #endif return ARES_SUCCESS; } diff --git a/ares_process.c b/ares_process.c index 0325f51..edfb9cb 100644 --- a/ares_process.c +++ b/ares_process.c @@ -909,8 +909,8 @@ static int configure_socket(ares_socket_t s, int family, ares_channel channel) #if defined(FD_CLOEXEC) && !defined(MSDOS) /* Configure the socket fd as close-on-exec. */ - if (fcntl(s, F_SETFD, FD_CLOEXEC) == -1) - return -1; /* LCOV_EXCL_LINE */ + //if (fcntl(s, F_SETFD, FD_CLOEXEC) == -1) + // return -1; /* LCOV_EXCL_LINE */ #endif /* Set the socket's send and receive buffer sizes. */ @@ -927,13 +927,13 @@ static int configure_socket(ares_socket_t s, int family, ares_channel channel) return -1; #ifdef SO_BINDTODEVICE - if (channel->local_dev_name[0]) { - if (setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, - channel->local_dev_name, sizeof(channel->local_dev_name))) { +// if (channel->local_dev_name[0]) { +// if (setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, +// channel->local_dev_name, sizeof(channel->local_dev_name))) { /* Only root can do this, and usually not fatal if it doesn't work, so */ /* just continue on. */ - } - } +// } +// } #endif if (family == AF_INET) { diff --git a/ares_setup.h b/ares_setup.h index 4df7961..30863ba 100644 --- a/ares_setup.h +++ b/ares_setup.h @@ -28,6 +28,16 @@ * configuration file for platforms which lack config tool. */ +/* amiga */ +#ifdef AOS3 +#include +#include +int ares_amiga_init(void); +void ares_amiga_cleanup(void); +extern struct Library *SocketBase; +extern char *prog; +#endif + #ifdef HAVE_CONFIG_H #include "ares_config.h" #else diff --git a/include/clib/amitcp_protos.h b/include/clib/amitcp_protos.h new file mode 100644 index 0000000..856a082 --- /dev/null +++ b/include/clib/amitcp_protos.h @@ -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 diff --git a/include/inline/amitcp.h b/include/inline/amitcp.h new file mode 100644 index 0000000..1ee4f30 --- /dev/null +++ b/include/inline/amitcp.h @@ -0,0 +1,203 @@ +/* Automatically generated header! Do not edit! */ + +#ifndef _INLINE_AMITCP_H +#define _INLINE_AMITCP_H + +#ifndef __INLINE_MACROS_H +#include +#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 */ diff --git a/include/sys/endian.h b/include/sys/endian.h new file mode 100644 index 0000000..00dc602 --- /dev/null +++ b/include/sys/endian.h @@ -0,0 +1,351 @@ +/* $NetBSD: endian.h,v 1.30 2016/02/27 21:37:35 christos Exp $ */ + +/* + * Copyright (c) 1987, 1991, 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. + * + * @(#)endian.h 8.1 (Berkeley) 6/11/93 + */ + +#ifndef _SYS_ENDIAN_H_ +#define _SYS_ENDIAN_H_ + +//#include + +/* + * Definitions for byte order, according to byte significance from low + * address to high. + */ +#define _LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ +#define _BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ +#define _PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */ + + +#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) +#ifndef _LOCORE + +/* C-family endian-ness definitions */ + +#include +#include +#include + +#ifndef in_addr_t +typedef __in_addr_t in_addr_t; +#define in_addr_t __in_addr_t +#endif + +#ifndef in_port_t +typedef __in_port_t in_port_t; +#define in_port_t __in_port_t +#endif + +__BEGIN_DECLS +uint32_t htonl(uint32_t) __constfunc; +uint16_t htons(uint16_t) __constfunc; +uint32_t ntohl(uint32_t) __constfunc; +uint16_t ntohs(uint16_t) __constfunc; +__END_DECLS + +#endif /* !_LOCORE */ +#endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */ + +//#include +#include + +/* + * Define the order of 32-bit words in 64-bit words. + */ +#if _BYTE_ORDER == _LITTLE_ENDIAN +#define _QUAD_HIGHWORD 1 +#define _QUAD_LOWWORD 0 +#endif + +#if _BYTE_ORDER == _BIG_ENDIAN +#define _QUAD_HIGHWORD 0 +#define _QUAD_LOWWORD 1 +#endif + + +//#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) +/* + * Traditional names for byteorder. These are defined as the numeric + * sequences so that third party code can "#define XXX_ENDIAN" and not + * cause errors. + */ +#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ +#define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ +#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */ +//#define BYTE_ORDER _BYTE_ORDER + +#ifndef _LOCORE + +//#include + +#if 0 +/* + * Macros for network/external number representation conversion. + */ +#if BYTE_ORDER == BIG_ENDIAN && !defined(__lint__) +#define ntohl(x) (x) +#define ntohs(x) (x) +#define htonl(x) (x) +#define htons(x) (x) + +#define NTOHL(x) (void) (x) +#define NTOHS(x) (void) (x) +#define HTONL(x) (void) (x) +#define HTONS(x) (void) (x) + +#else /* LITTLE_ENDIAN || !defined(__lint__) */ + +#define ntohl(x) bswap32(__CAST(uint32_t, (x))) +#define ntohs(x) bswap16(__CAST(uint16_t, (x))) +#define htonl(x) bswap32(__CAST(uint32_t, (x))) +#define htons(x) bswap16(__CAST(uint16_t, (x))) + +#define NTOHL(x) (x) = ntohl(__CAST(uint32_t, (x))) +#define NTOHS(x) (x) = ntohs(__CAST(uint16_t, (x))) +#define HTONL(x) (x) = htonl(__CAST(uint32_t, (x))) +#define HTONS(x) (x) = htons(__CAST(uint16_t, (x))) +#endif /* LITTLE_ENDIAN || !defined(__lint__) */ +#endif + +/* + * Macros to convert to a specific endianness. + */ + +#if BYTE_ORDER == BIG_ENDIAN + +#define htobe16(x) (x) +#define htobe32(x) (x) +#define htobe64(x) (x) +#define htole16(x) bswap16(__CAST(uint16_t, (x))) +#define htole32(x) bswap32(__CAST(uint32_t, (x))) +#define htole64(x) bswap64(__CAST(uint64_t, (x))) + +#define HTOBE16(x) __CAST(void, (x)) +#define HTOBE32(x) __CAST(void, (x)) +#define HTOBE64(x) __CAST(void, (x)) +#define HTOLE16(x) (x) = bswap16(__CAST(uint16_t, (x))) +#define HTOLE32(x) (x) = bswap32(__CAST(uint32_t, (x))) +#define HTOLE64(x) (x) = bswap64(__CAST(uint64_t, (x))) + +#else /* LITTLE_ENDIAN */ + +#define htobe16(x) bswap16(__CAST(uint16_t, (x))) +#define htobe32(x) bswap32(__CAST(uint32_t, (x))) +#define htobe64(x) bswap64(__CAST(uint64_t, (x))) +#define htole16(x) (x) +#define htole32(x) (x) +#define htole64(x) (x) + +#define HTOBE16(x) (x) = bswap16(__CAST(uint16_t, (x))) +#define HTOBE32(x) (x) = bswap32(__CAST(uint32_t, (x))) +#define HTOBE64(x) (x) = bswap64(__CAST(uint64_t, (x))) +#define HTOLE16(x) __CAST(void, (x)) +#define HTOLE32(x) __CAST(void, (x)) +#define HTOLE64(x) __CAST(void, (x)) + +#endif /* LITTLE_ENDIAN */ + +#define be16toh(x) htobe16(x) +#define be32toh(x) htobe32(x) +#define be64toh(x) htobe64(x) +#define le16toh(x) htole16(x) +#define le32toh(x) htole32(x) +#define le64toh(x) htole64(x) + +#define BE16TOH(x) HTOBE16(x) +#define BE32TOH(x) HTOBE32(x) +#define BE64TOH(x) HTOBE64(x) +#define LE16TOH(x) HTOLE16(x) +#define LE32TOH(x) HTOLE32(x) +#define LE64TOH(x) HTOLE64(x) + +/* + * Routines to encode/decode big- and little-endian multi-octet values + * to/from an octet stream. + */ + +#include +#define uint8_t u_int8_t +#define uint16_t u_int16_t +#define uint32_t u_int32_t +#define uint64_t u_int64_t +#define __CAST(x,y) (x)(y) +// TODO: Change to correct macro +#define __unused +#if 0 +//#if __GNUC_PREREQ__(2, 95) + +#define __GEN_ENDIAN_ENC(bits, endian) \ +static __inline void __unused \ +endian ## bits ## enc(void *dst, uint ## bits ## _t u) \ +{ \ + u = hto ## endian ## bits (u); \ + __builtin_memcpy(dst, &u, sizeof(u)); \ +} + +__GEN_ENDIAN_ENC(16, be) +__GEN_ENDIAN_ENC(32, be) +__GEN_ENDIAN_ENC(64, be) +__GEN_ENDIAN_ENC(16, le) +__GEN_ENDIAN_ENC(32, le) +__GEN_ENDIAN_ENC(64, le) +#undef __GEN_ENDIAN_ENC + +#define __GEN_ENDIAN_DEC(bits, endian) \ +static __inline uint ## bits ## _t __unused \ +endian ## bits ## dec(const void *buf) \ +{ \ + uint ## bits ## _t u; \ + __builtin_memcpy(&u, buf, sizeof(u)); \ + return endian ## bits ## toh (u); \ +} + +__GEN_ENDIAN_DEC(16, be) +__GEN_ENDIAN_DEC(32, be) +__GEN_ENDIAN_DEC(64, be) +__GEN_ENDIAN_DEC(16, le) +__GEN_ENDIAN_DEC(32, le) +__GEN_ENDIAN_DEC(64, le) +#undef __GEN_ENDIAN_DEC + +#else /* !(GCC >= 2.95) */ + +static __inline void __unused +be16enc(void *buf, uint16_t u) +{ + uint8_t *p = __CAST(uint8_t *, buf); + + p[0] = __CAST(uint8_t, ((__CAST(unsigned, u) >> 8) & 0xff)); + p[1] = __CAST(uint8_t, (u & 0xff)); +} + +static __inline void __unused +le16enc(void *buf, uint16_t u) +{ + uint8_t *p = __CAST(uint8_t *, buf); + + p[0] = __CAST(uint8_t, (u & 0xff)); + p[1] = __CAST(uint8_t, ((__CAST(unsigned, u) >> 8) & 0xff)); +} + +static __inline uint16_t __unused +be16dec(const void *buf) +{ + const uint8_t *p = __CAST(const uint8_t *, buf); + + return ((__CAST(uint16_t, p[0]) << 8) | p[1]); +} + +static __inline uint16_t __unused +le16dec(const void *buf) +{ + const uint8_t *p = __CAST(const uint8_t *, buf); + + return (p[0] | (__CAST(uint16_t, p[1]) << 8)); +} + +static __inline void __unused +be32enc(void *buf, uint32_t u) +{ + uint8_t *p = __CAST(uint8_t *, buf); + + p[0] = __CAST(uint8_t, ((u >> 24) & 0xff)); + p[1] = __CAST(uint8_t, ((u >> 16) & 0xff)); + p[2] = __CAST(uint8_t, ((u >> 8) & 0xff)); + p[3] = __CAST(uint8_t, (u & 0xff)); +} + +static __inline void __unused +le32enc(void *buf, uint32_t u) +{ + uint8_t *p = __CAST(uint8_t *, buf); + + p[0] = __CAST(uint8_t, (u & 0xff)); + p[1] = __CAST(uint8_t, ((u >> 8) & 0xff)); + p[2] = __CAST(uint8_t, ((u >> 16) & 0xff)); + p[3] = __CAST(uint8_t, ((u >> 24) & 0xff)); +} + +static __inline uint32_t __unused +be32dec(const void *buf) +{ + const uint8_t *p = __CAST(const uint8_t *, buf); + + return ((__CAST(uint32_t, be16dec(p)) << 16) | be16dec(p + 2)); +} + +static __inline uint32_t __unused +le32dec(const void *buf) +{ + const uint8_t *p = __CAST(const uint8_t *, buf); + + return (le16dec(p) | (__CAST(uint32_t, le16dec(p + 2)) << 16)); +} + +static __inline void __unused +be64enc(void *buf, uint64_t u) +{ + uint8_t *p = __CAST(uint8_t *, buf); + + be32enc(p, __CAST(uint32_t, (u >> 32))); + be32enc(p + 4, __CAST(uint32_t, (u & 0xffffffffULL))); +} + +static __inline void __unused +le64enc(void *buf, uint64_t u) +{ + uint8_t *p = __CAST(uint8_t *, buf); + + le32enc(p, __CAST(uint32_t, (u & 0xffffffffULL))); + le32enc(p + 4, __CAST(uint32_t, (u >> 32))); +} + +static __inline uint64_t __unused +be64dec(const void *buf) +{ + const uint8_t *p = (const uint8_t *)buf; + + return ((__CAST(uint64_t, be32dec(p)) << 32) | be32dec(p + 4)); +} + +static __inline uint64_t __unused +le64dec(const void *buf) +{ + const uint8_t *p = (const uint8_t *)buf; + + return (le32dec(p) | (__CAST(uint64_t, le32dec(p + 4)) << 32)); +} + +#endif /* GCC >= 2.95 */ + +#endif /* !_LOCORE */ +//#endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */ +#endif /* !_SYS_ENDIAN_H_ */ diff --git a/workman1 b/workman1 new file mode 100755 index 0000000..818e9e8 --- /dev/null +++ b/workman1 @@ -0,0 +1,37 @@ +#! /bin/sh + +# This file is in the public domain, so clarified as of +# 2009-05-17 by Arthur David Olson. + +# Tell groff not to emit SGR escape sequences (ANSI color escapes). +GROFF_NO_SGR=1 +export GROFF_NO_SGR + +# Tell groff to emit SGR escape sequences (ANSI color escapes). +#GROFF_SGR=1 +#export GROFF_SGR + +echo ".am TH +.hy 0 +.na +.. +.rm }H +.rm }F" | nroff -man - ${1+"$@"} | perl -ne ' + binmode STDIN, '\'':encoding(utf8)'\''; + binmode STDOUT, '\'':encoding(utf8)'\''; + chomp; + s/.\010//g; + s/\s*$//; + if (/^$/) { + $sawblank = 1; + next; + } else { + if ($sawblank && $didprint) { + print "\n"; + $sawblank = 0; + } + print "$_\n"; + $didprint = 1; + } +' + diff --git a/workman2 b/workman2 new file mode 100755 index 0000000..bd0c508 --- /dev/null +++ b/workman2 @@ -0,0 +1,37 @@ +#! /bin/sh + +# This file is in the public domain, so clarified as of +# 2009-05-17 by Arthur David Olson. + +# Tell groff not to emit SGR escape sequences (ANSI color escapes). +#GROFF_NO_SGR=1 +#export GROFF_NO_SGR + +# Tell groff to emit SGR escape sequences (ANSI color escapes). +GROFF_SGR=1 +export GROFF_SGR + +echo ".am TH +.hy 0 +.na +.. +.rm }H +.rm }F" | nroff -man - ${1+"$@"} | perl -ne ' + binmode STDIN, '\'':encoding(utf8)'\''; + binmode STDOUT, '\'':encoding(utf8)'\''; + chomp; + s/.\010//g; + s/\s*$//; + if (/^$/) { + $sawblank = 1; + next; + } else { + if ($sawblank && $didprint) { + print "\n"; + $sawblank = 0; + } + print "$_\n"; + $didprint = 1; + } +' +