ucspi-ssl  0.99e
TLS encryption for IPv6 communication
socket_local6.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_local6(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 
20  if (getsockname(s,(struct sockaddr *) &sa,&dummy) == -1) return -1;
21 #ifdef LIBC_HAS_IP6
22  if (sa.sin6_family==AF_INET) {
23  struct sockaddr_in *sa4=(struct sockaddr_in*)&sa;
25  byte_copy(ip+12,4,(char *) &sa4->sin_addr);
26  uint16_unpack_big((char *) &sa4->sin_port,port);
27  return 0;
28  }
29  byte_copy(ip,16,(char *) &sa.sin6_addr);
30  uint16_unpack_big((char *) &sa.sin6_port,port);
31  if (scope_id) *scope_id=sa.sin6_scope_id;
32 #else
34  byte_copy(ip+12,4,(char *) &sa.sin_addr);
35  uint16_unpack_big((char *) &sa.sin_port,port);
36  if (scope_id) *scope_id=0;
37 #endif
38  return 0;
39 }
void byte_copy(void *, unsigned int, const void *)
int socket_local6(int s, char ip[16], uint16 *port, uint32 *scope_id)
Definition: socket_local6.c:11
const unsigned char V4mappedprefix[12]
unsigned short uint16
Definition: uint16.h:4
void uint16_unpack_big(const char *, uint16 *)