ucspi-ssl  0.99e
TLS encryption for IPv6 communication
socket_conn6.c
Go to the documentation of this file.
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 
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 (ipv4) {
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 }
void byte_copy(void *, unsigned int, const void *)
void uint16_pack_big(char *, uint16)
#define ip6_isv4mapped(ip)
Definition: ip6.h:28
const unsigned char V6loopback[16]
int ipv4
Definition: socket_tcp6.c:15
int socket_connect6(int s, const char ip[16], uint16 port, uint32 scope_id)
Definition: socket_conn6.c:13
void byte_zero(void *, unsigned int)
int socket_connect4(int, const char *, uint16)
const char ip4loopback[4]
unsigned short uint16
Definition: uint16.h:4
#define byte_equal(s, n, t)
Definition: byte.h:13