|
From: <ljs...@us...> - 2006-09-14 02:04:18
|
Revision: 352
http://svn.sourceforge.net/cadcdev/?rev=352&view=rev
Author: ljsebald
Date: 2006-09-13 19:04:08 -0700 (Wed, 13 Sep 2006)
Log Message:
-----------
Adding in the first of the big network changes that I have been working on.
Modified Paths:
--------------
kos/kernel/libc/koslib/Makefile
Added Paths:
-----------
kos/include/arpa/
kos/include/arpa/inet.h
kos/include/netinet/
kos/include/netinet/in.h
kos/kernel/libc/koslib/inet_addr.c
Added: kos/include/arpa/inet.h
===================================================================
--- kos/include/arpa/inet.h (rev 0)
+++ kos/include/arpa/inet.h 2006-09-14 02:04:08 UTC (rev 352)
@@ -0,0 +1,26 @@
+/* KallistiOS ##version##
+
+ arpa/inet.h
+ Copyright (C)2006 Lawrence Sebald
+
+*/
+
+#ifndef __ARPA_INET_H
+#define __ARPA_INET_H
+
+#include <sys/cdefs.h>
+#include <netinet/in.h>
+
+__BEGIN_DECLS
+
+uint32 htonl(uint32 value);
+uint32 ntohl(uint32 value);
+
+uint16 htons(uint16 value);
+uint16 ntohs(uint16 value);
+
+in_addr_t inet_addr(const char *cp);
+
+__END_DECLS
+
+#endif /* __ARPA_INET_H */
Added: kos/include/netinet/in.h
===================================================================
--- kos/include/netinet/in.h (rev 0)
+++ kos/include/netinet/in.h 2006-09-14 02:04:08 UTC (rev 352)
@@ -0,0 +1,44 @@
+/* KallistiOS ##version##
+
+ netinet/in.h
+ Copyright (C)2006 Lawrence Sebald
+
+*/
+
+#ifndef __NETINET_IN_H
+#define __NETINET_IN_H
+
+#include <sys/cdefs.h>
+#include <arch/types.h>
+
+__BEGIN_DECLS
+
+typedef uint16 in_port_t;
+typedef uint32 in_addr_t;
+
+#ifndef __SA_FAMILY_T_DEFINED
+#define __SA_FAMILY_T_DEFINED
+typedef uint32 sa_family_t;
+#endif
+
+struct in_addr {
+ in_addr_t s_addr;
+};
+
+struct sockaddr_in {
+ sa_family_t sin_family;
+ in_port_t sin_port;
+ struct in_addr sin_addr;
+ unsigned char sin_zero[8];
+};
+
+#define INADDR_ANY 0x00000000
+#define INADDR_BROADCAST 0xFFFFFFFF
+
+/* IP Protocols */
+#define IPPROTO_IP 0
+#define IPPROTO_UDP 17
+
+__END_DECLS
+
+#endif /* __NETINET_IN_H */
Modified: kos/kernel/libc/koslib/Makefile
===================================================================
--- kos/kernel/libc/koslib/Makefile 2006-09-14 01:38:50 UTC (rev 351)
+++ kos/kernel/libc/koslib/Makefile 2006-09-14 02:04:08 UTC (rev 352)
@@ -10,6 +10,6 @@
OBJS = abort.o byteorder.o memset2.o memset4.o memcpy2.o memcpy4.o \
assert.o dbglog.o malloc.o crtbegin.o crtend.o atexit.o \
opendir.o readdir.o closedir.o rewinddir.o scandir.o seekdir.o \
- telldir.o usleep.o
+ telldir.o usleep.o inet_addr.o
include $(KOS_BASE)/Makefile.prefab
Added: kos/kernel/libc/koslib/inet_addr.c
===================================================================
--- kos/kernel/libc/koslib/inet_addr.c (rev 0)
+++ kos/kernel/libc/koslib/inet_addr.c 2006-09-14 02:04:08 UTC (rev 352)
@@ -0,0 +1,49 @@
+/* KallistiOS ##version##
+
+ inet_addr.c
+ Copyright (C)2006 Lawrence Sebald
+
+*/
+
+#include <arpa/inet.h>
+#include <stdlib.h>
+
+in_addr_t inet_addr(const char *cp) {
+ in_addr_t result = 0;
+ long tmp;
+ char *ptr;
+
+ tmp = strtoul(cp, &ptr, 10);
+ if(tmp > 0xFF || cp == ptr) {
+ return (in_addr_t) -1;
+ }
+ else {
+ result = tmp << 24;
+ }
+
+ tmp = strtoul(ptr + 1, &ptr, 10);
+ if(tmp > 0xFF || cp == ptr) {
+ return (in_addr_t) -1;
+ }
+ else {
+ result |= tmp << 16;
+ }
+
+ tmp = strtoul(ptr + 1, &ptr, 10);
+ if(tmp > 0xFF || cp == ptr) {
+ return (in_addr_t) -1;
+ }
+ else {
+ result |= tmp << 8;
+ }
+
+ tmp = strtoul(ptr + 1, &ptr, 10);
+ if(tmp > 0xFF || cp == ptr) {
+ return (in_addr_t) -1;
+ }
+ else {
+ result |= tmp;
+ }
+
+ return (in_addr_t) htonl(result);
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|