1 #include <sys/param.h>
2 #include <sys/types.h>
3 #include <sys/socket.h>
4 #include <netinet/in.h>
5 #include <errno.h>
6 #include "byte.h"
7 #include "socket.h"
8 #include "ip6.h"
9 #include "haveip6.h"
10 #include "uint32.h"
11 #include "ip4.h"
12
socket_connect6(int s,const char ip[16],uint16 port,uint32 scope_id)13 int socket_connect6(int s,const char ip[16],uint16 port,uint32 scope_id)
14 {
15 #ifdef LIBC_HAS_IP6
16 struct sockaddr_in6 sa;
17
18 if (noipv6) {
19 #endif
20 if (ip6_isv4mapped(ip))
21 return socket_connect4(s,ip+12,port);
22 if (byte_equal(ip,16,V6loopback))
23 return socket_connect4(s,ip4loopback,port);
24 #ifdef LIBC_HAS_IP6
25 }
26 byte_zero(&sa,sizeof sa);
27 sa.sin6_family = PF_INET6;
28 uint16_pack_big((char *) &sa.sin6_port,port);
29 sa.sin6_flowinfo = 0;
30 sa.sin6_scope_id = scope_id;
31 byte_copy((char *) &sa.sin6_addr,16,ip);
32
33 return connect(s,(struct sockaddr *) &sa,sizeof sa);
34 #else
35 errno=EPROTONOSUPPORT;
36 return -1;
37 #endif
38 }
39