diff --git a/CHANGES b/CHANGES index b1a5fdb..1458fef 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ 0.6: - changed name to libowfat - fixed fmt_ulong (did not output 0 correctly) + changed name to libowfat. + fixed fmt_ulong (did not output 0 correctly). + added buffer. + extended buffer API to include buffer_putulong() and friends. 0.5: made subdirectories for the different libraries. diff --git a/socket.h b/socket.h index 3cc73b4..f82c16a 100644 --- a/socket.h +++ b/socket.h @@ -20,8 +20,8 @@ extern int socket_bind4_reuse(int s,const char *ip,uint16 port); extern int socket_bind6(int s,const char *ip,uint16 port,uint32 scope_id); extern int socket_bind6_reuse(int s,const char *ip,uint16 port,uint32 scope_id); extern int socket_listen(int s,unsigned int backlog); -extern int socket_accept4(int s,char *ip,uint16 *); -extern int socket_accept6(int s,char *ip,uint16 *,uint32 *scope_id); +extern int socket_accept4(int s,char *ip,uint16 *port); +extern int socket_accept6(int s,char *ip,uint16 *port,uint32 *scope_id); extern int socket_recv4(int s,char *buf,unsigned int len,char *ip,uint16 *port); extern int socket_recv6(int s,char *buf,unsigned int len,char *ip,uint16 *port,uint32 *scope_id); extern int socket_send4(int s,const char *buf,unsigned int len,const char *ip,uint16 port); diff --git a/socket/socket_accept4.c b/socket/socket_accept4.c new file mode 100644 index 0000000..ff1189a --- /dev/null +++ b/socket/socket_accept4.c @@ -0,0 +1,13 @@ +#include +#include +#include "socket.h" + +int socket_accept4(int s,char *ip,uint16 *port) { + struct sockaddr_in si; + unsigned int len = sizeof si; + int fd; + if ((fd=accept(s,(struct sockaddr*) &si,&len))<0) return -1; + *(uint32*)ip = *(uint32*)&si.sin_addr; + uint16_unpack_big((char *) &si.sin_port,port); + return fd; +} diff --git a/socket/socket_accept6.c b/socket/socket_accept6.c new file mode 100644 index 0000000..48a0b6d --- /dev/null +++ b/socket/socket_accept6.c @@ -0,0 +1,43 @@ +#include +#include +#include +#include "byte.h" +#include "socket.h" +#include "ip6.h" +#include "haveip6.h" +#include "error.h" + +int socket_accept6(int s,char ip[16],uint16 *port,uint32 *scope_id) +{ +#ifdef LIBC_HAS_IP6 + struct sockaddr_in6 sa; +#else + struct sockaddr_in sa; +#endif + unsigned int dummy = sizeof sa; + int fd; + + fd = accept(s,(struct sockaddr *) &sa,&dummy); + if (fd == -1) return -1; + +#ifdef LIBC_HAS_IP6 + if (sa.sin6_family==AF_INET) { + struct sockaddr_in *sa4=(struct sockaddr_in*)&sa; + byte_copy(ip,12,V4mappedprefix); + byte_copy(ip+12,4,(char *) &sa4->sin_addr); + uint16_unpack_big((char *) &sa4->sin_port,port); + return fd; + } + byte_copy(ip,16,(char *) &sa.sin6_addr); + uint16_unpack_big((char *) &sa.sin6_port,port); + if (scope_id) *scope_id=sa.sin6_scope_id; + + return fd; +#else + byte_copy(ip,12,V4mappedprefix); + byte_copy(ip+12,4,(char *) &sa.sin_addr); + uint16_unpack_big((char *) &sa.sin_port,port); + if (scope_id) *scope_id=0; + return fd; +#endif +}