ucspi-ssl  0.99e
TLS encryption for IPv6 communication
socket_send6.c
Go to the documentation of this file.
1 #include <sys/types.h>
2 #include <sys/param.h>
3 #include <sys/socket.h>
4 #include <netinet/in.h>
5 #include "byte.h"
6 #include "socket.h"
7 #include "ip4.h"
8 #include "ip6.h"
9 #include "haveip6.h"
10 #include "error.h"
11 
12 int socket_send6(int s,const char *buf,unsigned int len,const char ip[16],uint16 port,uint32 scope_id)
13 {
14 #ifdef LIBC_HAS_IP6
15  struct sockaddr_in6 sa;
16 #else
17  struct sockaddr_in sa;
18 #endif
19 
20  byte_zero(&sa,sizeof sa);
21 #ifdef LIBC_HAS_IP6
22  if (ipv4) {
23 #endif
24  if (ip6_isv4mapped(ip))
25  return socket_send4(s,buf,len,ip+12,port);
26  if (byte_equal(ip,16,V6loopback))
27  return socket_send4(s,buf,len,ip4loopback,port);
28 #ifdef LIBC_HAS_IP6
29  errno=error_proto;
30  return -1;
31  }
32  sa.sin6_family = AF_INET6;
33  uint16_pack_big((char *) &sa.sin6_port,port);
34  byte_copy((char *) &sa.sin6_addr,16,ip);
35  return sendto(s,buf,len,0,(struct sockaddr *) &sa,sizeof sa);
36 #else
37  errno=error_proto;
38  return -1;
39 #endif
40 }
int socket_send4(int, const char *, int, const char *, uint16)
void byte_copy(void *, unsigned int, const void *)
char buf[SSL_NAME_LEN]
Definition: sslhandle.c:125
int error_proto
Definition: error.c:106
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
void byte_zero(void *, unsigned int)
int socket_send6(int s, const char *buf, unsigned int len, const char ip[16], uint16 port, uint32 scope_id)
Definition: socket_send6.c:12
const char ip4loopback[4]
unsigned short uint16
Definition: uint16.h:4
#define byte_equal(s, n, t)
Definition: byte.h:13