inet: First pass fixing up the inet_ functions
authorAlan Cox <alan@linux.intel.com>
Thu, 3 Mar 2016 13:46:41 +0000 (13:46 +0000)
committerAlan Cox <alan@linux.intel.com>
Thu, 3 Mar 2016 13:46:41 +0000 (13:46 +0000)
Library/include/arpa/inet.h
Library/include/netinet/in.h
Library/libs/Makefile
Library/libs/inet_aton.c
Library/libs/inet_ntoa.c
Library/libs/inet_ntop.c
Library/libs/inet_pton.c

index 2c52f33..b30cca7 100644 (file)
@@ -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,
index 20885c2..ec538b1 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef _NETINET_IN_H
 #define _NETINET_IN_H
 
+#include <sys/socket.h>
+
 typedef uint16_t in_port_t;
 typedef uint32_t in_addr_t;
 
index f2b3c6b..0fb47b2 100644 (file)
@@ -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
index 285abb7..8d66145 100644 (file)
@@ -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];
index dc01fc2..8cb9fab 100644 (file)
@@ -5,15 +5,16 @@
 #include <sys/types.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <string.h>
 #include <stdlib.h>
 
-char *inet_ntoa(struct in_addr in)
+char *_inet_ntoa(uint32_t in)
 {
   static char b[18];
-  uint8_t *p = (uint8_t)&in;
-  uint8_t *o = b;
+  uint8_t *p = (uint8_t *)&in;
+  char *o = b;
   
-  while(p != ((uint8_t *)&in) + 3)
+  while(p != ((uint8_t *)&in) + 3) {
     strcpy(o, _itoa(*p++));
     o += strlen(o);
     *o++ = '.';
index f9b7062..7b15313 100644 (file)
@@ -1,6 +1,7 @@
 #include <sys/types.h>
 #include <netinet/in.h>
-#include <arap/inet.h>
+#include <arpa/inet.h>
+#include <string.h>
 #include <errno.h>
 
 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));
 }
index 96b24da..26d7579 100644 (file)
@@ -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;