ucspi-ssl  0.99e
TLS encryption for IPv6 communication
socket_accept6.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 "ip6.h"
8 #include "haveip6.h"
9 #include "error.h"
10 
11 int socket_accept6(int s,char ip[16],uint16 *port,uint32 *scope_id)
12 {
13 #ifdef LIBC_HAS_IP6
14  struct sockaddr_in6 sa;
15 #else
16  struct sockaddr_in sa;
17 #endif
18  unsigned int dummy = sizeof sa;
19  int fd;
20 
21  fd = accept(s,(struct sockaddr *) &sa,&dummy);
22  if (fd == -1) return -1;
23 
24 #ifdef LIBC_HAS_IP6
25  if (sa.sin6_family==AF_INET) {
26  struct sockaddr_in *sa4=(struct sockaddr_in*)&sa;
28  byte_copy(ip+12,4,(char *) &sa4->sin_addr);
29  uint16_unpack_big((char *) &sa4->sin_port,port);
30  return fd;
31  }
32  byte_copy(ip,16,(char *) &sa.sin6_addr);
33  uint16_unpack_big((char *) &sa.sin6_port,port);
34  if (scope_id) *scope_id=sa.sin6_scope_id;
35 
36  return fd;
37 #else
39  byte_copy(ip+12,4,(char *) &sa.sin_addr);
40  uint16_unpack_big((char *) &sa.sin_port,port);
41  if (scope_id) *scope_id=0;
42  return fd;
43 #endif
44 }
void byte_copy(void *, unsigned int, const void *)
int socket_accept6(int s, char ip[16], uint16 *port, uint32 *scope_id)
const unsigned char V4mappedprefix[12]
unsigned short uint16
Definition: uint16.h:4
void uint16_unpack_big(const char *, uint16 *)