From ef6722750b4518fcb29bf983755b5f02451ef224 Mon Sep 17 00:00:00 2001 From: John Denker Date: Tue, 31 Jul 2012 22:34:58 -0700 Subject: a bunch of files added by the ipv6 patch --- ucspi-tcp-0.88/socket_bind6.c | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 ucspi-tcp-0.88/socket_bind6.c (limited to 'ucspi-tcp-0.88/socket_bind6.c') diff --git a/ucspi-tcp-0.88/socket_bind6.c b/ucspi-tcp-0.88/socket_bind6.c new file mode 100644 index 0000000..8a5a7cd --- /dev/null +++ b/ucspi-tcp-0.88/socket_bind6.c @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include "byte.h" +#include "socket.h" +#include "ip6.h" +#include "haveip6.h" +#include "error.h" + +int socket_bind6(int s,const char ip[16],uint16 port,uint32 scope_id) +{ +#ifdef LIBC_HAS_IP6 + struct sockaddr_in6 sa; + + if (noipv6) { +#endif + int i; + for (i=0; i<16; i++) + if (ip[i]!=0) break; + if (i==16 || ip6_isv4mapped(ip)) + return socket_bind4(s,ip+12,port); +#ifdef LIBC_HAS_IP6 + } + byte_zero(&sa,sizeof sa); + sa.sin6_family = AF_INET6; + uint16_pack_big((char *) &sa.sin6_port,port); +/* implicit: sa.sin6_flowinfo = 0; */ + byte_copy((char *) &sa.sin6_addr,16,ip); + sa.sin6_scope_id=scope_id; + + return bind(s,(struct sockaddr *) &sa,sizeof sa); +#else + errno=error_proto; + return -1; +#endif +} + +int socket_bind6_reuse(int s,const char ip[16],uint16 port,uint32 scope_id) +{ + int opt = 1; + setsockopt(s,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof opt); + return socket_bind6(s,ip,port,scope_id); +} + -- cgit v1.2.3