From 6e8fc23e34b991beaa8da50be8425697d35122ad Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Thu, 3 Mar 2016 13:46:41 +0000 Subject: [PATCH] inet: First pass fixing up the inet_ functions --- Library/include/arpa/inet.h | 5 +++-- Library/include/netinet/in.h | 2 ++ Library/libs/Makefile | 12 ++++++++---- Library/libs/inet_aton.c | 2 +- Library/libs/inet_ntoa.c | 9 +++++---- Library/libs/inet_ntop.c | 5 +++-- Library/libs/inet_pton.c | 8 ++++---- 7 files changed, 26 insertions(+), 17 deletions(-) diff --git a/Library/include/arpa/inet.h b/Library/include/arpa/inet.h index 2c52f331..b30cca77 100644 --- a/Library/include/arpa/inet.h +++ b/Library/include/arpa/inet.h @@ -23,8 +23,9 @@ extern uint16_t htons(uint16_t __hostshort); extern int inet_aton(const char *__cp, struct in_addr *__inp); extern in_addr_t inet_addr(const char *__cp); extern in_addr_t inet_network(const char *__cp); -/* Awkward - struct argument .. may need hacks for 6502 ?? */ -extern char *inet_ntoa(struct in_addr __in); +/* Awkward - struct argument .. hacks needed */ +extern char *_inet_ntoa(uint32_t a); +#define inet_ntoa(x) (_inet_ntoa((x).s_addr)) /* Modern APIs */ extern const char *inet_ntop(int __af, const void *__src, char *__dst, diff --git a/Library/include/netinet/in.h b/Library/include/netinet/in.h index 20885c2f..ec538b12 100644 --- a/Library/include/netinet/in.h +++ b/Library/include/netinet/in.h @@ -1,6 +1,8 @@ #ifndef _NETINET_IN_H #define _NETINET_IN_H +#include + typedef uint16_t in_port_t; typedef uint32_t in_addr_t; diff --git a/Library/libs/Makefile b/Library/libs/Makefile index f2b3c6b3..0fb47b23 100644 --- a/Library/libs/Makefile +++ b/Library/libs/Makefile @@ -1,4 +1,4 @@ -CC = sdcc +CC = fcc ASM = sdasz80 AR = sdar LINKER = sdldz80 @@ -8,9 +8,11 @@ export MAKE = make PLATFORM = export PLATFORM #CC_OPT = -mz80 -c --opt-code-size --std-c99 --max-allocs-per-node 2000000 -I../include -CC_OPT = -mz80 --std-c99 -c --opt-code-size --max-allocs-per-node 20000 -I../include +#CC_OPT = -mz80 --std-c99 -c --opt-code-size --max-allocs-per-node 20000 -I../include -I../../Kernel/include # for stuff that gives sdcc nightmares -CC_NOOPT = -mz80 --std-c99 -c --opt-code-size --max-allocs-per-node 1000 -I../include +#CC_NOOPT = -mz80 --std-c99 -c --opt-code-size --max-allocs-per-node 1000 -I../include +CC_OPT = -O2 -c +CC_NOOPT = -c ASM_OPT = -l -o -s LINKER_OPT = -m -i -o SRC_CRT0 = crt0$(PLATFORM).s @@ -31,7 +33,9 @@ SRC_C += free.c fsetpos.c ftell.c fwrite.c getcwd.c SRC_C += getenv.c __getgrent.c getgrgid.c getgrnam.c getloadavg.c getlogin.c SRC_C += getopt.c SRC_C += getpw.c __getpwent.c getpwnam.c getpwuid.c gets.c gettimeofday.c -SRC_C += getw.c gmtime.c gmtime_r.c grent.c index.c isatty.c killpg.c +SRC_C += getw.c gmtime.c gmtime_r.c grent.c +SRC_C += inet_addr.c inet_aton.c inet_network.c inet_ntoa.c inet_ntop.c inet_pton.c +SRC_C += index.c isatty.c killpg.c SRC_C += libintl.c SRC_C += localtim.c localtim_r.c lseek.c lsearch.c lstat.c ltoa.c ltostr.c SRC_C += malloc.c mkfifo.c mkstemps.c nanosleep.c opendir.c opendir_r.c diff --git a/Library/libs/inet_aton.c b/Library/libs/inet_aton.c index 285abb7f..8d661459 100644 --- a/Library/libs/inet_aton.c +++ b/Library/libs/inet_aton.c @@ -69,7 +69,7 @@ */ int inet_aton(const char *cp, struct in_addr *addr) { - u_int32_t val; + uint32_t val; int base, n; char c; unsigned int parts[4]; diff --git a/Library/libs/inet_ntoa.c b/Library/libs/inet_ntoa.c index dc01fc27..8cb9fab2 100644 --- a/Library/libs/inet_ntoa.c +++ b/Library/libs/inet_ntoa.c @@ -5,15 +5,16 @@ #include #include #include +#include #include -char *inet_ntoa(struct in_addr in) +char *_inet_ntoa(uint32_t in) { static char b[18]; - uint8_t *p = (uint8_t)∈ - uint8_t *o = b; + uint8_t *p = (uint8_t *)∈ + char *o = b; - while(p != ((uint8_t *)&in) + 3) + while(p != ((uint8_t *)&in) + 3) { strcpy(o, _itoa(*p++)); o += strlen(o); *o++ = '.'; diff --git a/Library/libs/inet_ntop.c b/Library/libs/inet_ntop.c index f9b70626..7b153134 100644 --- a/Library/libs/inet_ntop.c +++ b/Library/libs/inet_ntop.c @@ -1,6 +1,7 @@ #include #include -#include +#include +#include #include const char *inet_ntop(int af, const void *src, char *dst, socklen_t size) @@ -16,5 +17,5 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t size) /* This isn't strictly correct because it means we are not re-entrant. Really we need to rework _itoa() to have a re-entrant base form, then rework inet_ntoa to use inet_ntop FIXME */ - return strcpy(dst, inet_ntoa(*(uint32_t *)src); + return strcpy(dst, _inet_ntoa(*(uint32_t *)src)); } diff --git a/Library/libs/inet_pton.c b/Library/libs/inet_pton.c index 96b24daf..26d7579e 100644 --- a/Library/libs/inet_pton.c +++ b/Library/libs/inet_pton.c @@ -46,10 +46,10 @@ int inet_pton(int af, const char *src, void *dst) /* Unlike the legacy interfaces this one requires decimal and four dotted quads */ - src = quad(src, *p++); - src = quad(src, *p++); - src = quad(src, *p++); - src = quad(src, *p); + src = quad(src, p++); + src = quad(src, p++); + src = quad(src, p++); + src = quad(src, p); if (src == NULL || *src) return 0; return 1; -- 2.34.1