diff options
author | John Denker <jsd@av8n.com> | 2012-07-31 22:34:58 -0700 |
---|---|---|
committer | John Denker <jsd@av8n.com> | 2012-07-31 22:36:28 -0700 |
commit | ef6722750b4518fcb29bf983755b5f02451ef224 (patch) | |
tree | 966e94ffd01cd8abb59e16a6992e142db345aa9f /ucspi-tcp-0.88/socket_conn6.c | |
parent | b95f5ec1d83519c603f6e2145865c14932c4a813 (diff) |
a bunch of files added by the ipv6 patch
Diffstat (limited to 'ucspi-tcp-0.88/socket_conn6.c')
-rw-r--r-- | ucspi-tcp-0.88/socket_conn6.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/ucspi-tcp-0.88/socket_conn6.c b/ucspi-tcp-0.88/socket_conn6.c new file mode 100644 index 0000000..0ad886d --- /dev/null +++ b/ucspi-tcp-0.88/socket_conn6.c @@ -0,0 +1,38 @@ +#include <sys/param.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <errno.h> +#include "byte.h" +#include "socket.h" +#include "ip6.h" +#include "haveip6.h" +#include "uint32.h" +#include "ip4.h" + +int socket_connect6(int s,const char ip[16],uint16 port,uint32 scope_id) +{ +#ifdef LIBC_HAS_IP6 + struct sockaddr_in6 sa; + + if (noipv6) { +#endif + if (ip6_isv4mapped(ip)) + return socket_connect4(s,ip+12,port); + if (byte_equal(ip,16,V6loopback)) + return socket_connect4(s,ip4loopback,port); +#ifdef LIBC_HAS_IP6 + } + byte_zero(&sa,sizeof sa); + sa.sin6_family = PF_INET6; + uint16_pack_big((char *) &sa.sin6_port,port); + sa.sin6_flowinfo = 0; + sa.sin6_scope_id = scope_id; + byte_copy((char *) &sa.sin6_addr,16,ip); + + return connect(s,(struct sockaddr *) &sa,sizeof sa); +#else + errno=EPROTONOSUPPORT; + return -1; +#endif +} |