diff --git a/Makefile b/Makefile index 00fbb72..389a8f0 100644 --- a/Makefile +++ b/Makefile @@ -2,12 +2,12 @@ all: t byte.a fmt.a scan.a str.a uint.a open.a stralloc.a unix.a socket.a buffer VPATH=str:byte:fmt:scan:uint:open:stralloc:unix:socket:buffer:mmap +# comment out the following line if you don't want to build with the +# diet libc (http://www.fefe.de/dietlibc/). +DIET=diet -Os CC=gcc CFLAGS=-I. -pipe -Wall -O2 -pipe -fomit-frame-pointer -#CFLAGS=-I. -pipe -Wall -Os -march=pentiumpro -fomit-frame-pointer -fschedule-insns2 -Wall -#CFLAGS=-I. -I../dietlibc/include -pipe -Wall -Os -malign-functions=2 -fschedule-insns2 -g -#CFLAGS=-I../dietlibc/include -I. -pipe -Wall -Os -march=pentiumpro -mcpu=athlon -fomit-frame-pointer -fschedule-insns2 -Wall -#CFLAGS=-I../dietlibc/include -pipe -Os -march=pentiumpro -mcpu=pentiumpro -fomit-frame-pointer -fschedule-insns2 -Wall +#CFLAGS=-pipe -Os -march=pentiumpro -mcpu=pentiumpro -fomit-frame-pointer -fschedule-insns2 -Wall BYTE_OBJS=$(patsubst byte/%.c,%.o,$(wildcard byte/*.c)) FMT_OBJS=$(patsubst fmt/%.c,%.o,$(wildcard fmt/*.c)) @@ -49,14 +49,40 @@ $(BUFFER_OBJS) $(MMAP_OBJS) %.a: ar cr $@ $^ + -ranlib $@ t: t.o socket.a stralloc.a buffer.a scan.a uint.a mmap.a open.a fmt.a \ str.a byte.a - $(DIET)$(CC) -g -o $@ $^ + $(DIET) $(CC) -g -o $@ $^ .PHONY: clean tar clean: - rm -f *.o *.a core t + rm -f *.o *.a core t haveip6.h haven2i.h + +VERSION=libowfat-$(shell head -1 CHANGES|sed 's/://') +CURNAME=$(notdir $(shell pwd)) + +tar: clean rename + cd ..; tar cvvf $(VERSION).tar.bz2 $(VERSION) --use=bzip2 --exclude CVS + +rename: + if test $(CURNAME) != $(VERSION); then cd .. && mv $(CURNAME) $(VERSION); fi + +haveip6.h: + -rm -f $@ + if $(DIET) $(CC) -c tryip6.c >/dev/null 2>&1; then echo "#define LIBC_HAS_IP6"; fi > $@ + +haven2i.h: + -rm -f $@ + if $(DIET) $(CC) -o t tryn2i.c >/dev/null 2>&1; then echo "#define HAVE_N2I"; fi > $@ + +havesl.h: + -rm -f $@ + if $(DIET) $(CC) -o t trysl.c >/dev/null 2>&1; then echo "#define HAVE_SOCKLEN_T"; fi > $@ + +socket_accept6.o socket_connect6.o socket_local6.o socket_mchopcount6.o \ +socket_mcjoin6.o socket_mcleave6.o socket_mcloop6.o socket_recv6.o \ +socket_remote6.o socket_send6.o socket_tcp6.o socket_udp6.o: haveip6.h + +socket_getifidx.o socket_getifname.o: haven2i.h -tar: - cd .. && tar cf libowfat.tar.bz2 libowfat --use=bzip2 --exclude CVS diff --git a/haveip6.h b/haveip6.h deleted file mode 100644 index 87b5bd2..0000000 --- a/haveip6.h +++ /dev/null @@ -1,2 +0,0 @@ - -#define LIBC_HAS_IP6 diff --git a/haven2i.h b/haven2i.h deleted file mode 100644 index fd50644..0000000 --- a/haven2i.h +++ /dev/null @@ -1 +0,0 @@ -#define HAVE_N2I diff --git a/socket/socket_tcp6.c b/socket/socket_tcp6.c index 3fc7825..845cb5e 100644 --- a/socket/socket_tcp6.c +++ b/socket/socket_tcp6.c @@ -1,9 +1,33 @@ #include #include #include - +#include +#include "haveip6.h" #include "socket.h" -int socket_tcp6(void) { - return socket(PF_INET6,SOCK_STREAM,IPPROTO_TCP); +#ifndef EAFNOSUPPORT +#define EAFNOSUPPORT EINVAL +#endif + +int socket_tcp6(void) +{ +#ifdef LIBC_HAS_IP6 + int s; + + if (noipv6) goto compat; + s = socket(PF_INET6,SOCK_STREAM,0); + if (s == -1) { + if (errno == EINVAL || errno == EAFNOSUPPORT) { +compat: + s=socket(AF_INET,SOCK_STREAM,0); + noipv6=1; + if (s==-1) return -1; + } else + return -1; + } + return s; +#else + return socket_tcp(); +#endif } + diff --git a/socket/socket_udp6.c b/socket/socket_udp6.c index 82de50f..6c27d15 100644 --- a/socket/socket_udp6.c +++ b/socket/socket_udp6.c @@ -1,9 +1,32 @@ #include #include #include - +#include +#include "haveip6.h" #include "socket.h" -int socket_udp6(void) { - return socket(PF_INET6,SOCK_DGRAM,IPPROTO_UDP); +#ifndef EAFNOSUPPORT +#define EAFNOSUPPORT EINVAL +#endif + +int socket_udp6(void) +{ +#ifdef LIBC_HAS_IP6 + int s; + + if (noipv6) goto compat; + s = socket(PF_INET6,SOCK_DGRAM,0); + if (s == -1) { + if (errno == EINVAL || errno == EAFNOSUPPORT) { +compat: + s=socket(AF_INET,SOCK_DGRAM,0); + noipv6=1; + if (s==-1) return -1; + } else + return -1; + } + return s; +#else + return socket_udp(); +#endif } diff --git a/t.c b/t.c index b44fa53..a37bfb7 100644 --- a/t.c +++ b/t.c @@ -14,12 +14,11 @@ __asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx") int main(int argc,char* argv[]) { - char buf[100]; - buf[fmt_ulong(buf,0)]=0; - puts(buf); -#if 0 - buffer_putspace(buffer_1); - buffer_flush(buffer_1); +#if 1 + buffer_putulong(buffer_1,23); +// buffer_putspace(buffer_1); + buffer_putsflush(buffer_1,"\n"); +// buffer_flush(buffer_1); #endif #if 0 long a,b,c; diff --git a/tryip6.c b/tryip6.c new file mode 100644 index 0000000..e0d7cfb --- /dev/null +++ b/tryip6.c @@ -0,0 +1,8 @@ +#include +#include +#include + +main() { + struct sockaddr_in6 sa; + sa.sin6_family = PF_INET6; +} diff --git a/tryn2i.c b/tryn2i.c new file mode 100644 index 0000000..84c3a08 --- /dev/null +++ b/tryn2i.c @@ -0,0 +1,8 @@ +#include +#include +#include + +int main() { + static char ifname[IFNAMSIZ]; + char *tmp=if_indextoname(0,ifname); +} diff --git a/trysl.c b/trysl.c new file mode 100644 index 0000000..5a5b355 --- /dev/null +++ b/trysl.c @@ -0,0 +1,7 @@ +#include +#include +#include + +main() { + socklen_t t; +}