18 struct sockaddr_in6 sa;
19 unsigned int dummy =
sizeof(sa);
21 if (getsockname(s,(
struct sockaddr *)&sa,&dummy) == -1)
return -1;
23 if (sa.sin6_family == AF_INET) {
24 struct sockaddr_in *sa4 = (
struct sockaddr_in*)&sa;
26 byte_copy(ip + 12,4,(
char *)&sa4->sin_addr);
28 if (scope_id) *scope_id = 0;
32 if (scope_id) *scope_id = sa.sin6_scope_id;
40 struct sockaddr_in6 sa;
41 unsigned int dummy =
sizeof(sa);
43 if (getpeername(s,(
struct sockaddr *)&sa,&dummy) == -1)
return -1;
45 if (sa.sin6_family == AF_INET) {
46 struct sockaddr_in *sa4 = (
struct sockaddr_in*)&sa;
48 byte_copy(ip + 12,4,(
char *)&sa4->sin_addr);
54 *scope_id = sa.sin6_scope_id;
const unsigned char V4mappedprefix[12]
int socket_local(int s, char ip[16], uint16 *port, uint32 *scope_id)
int socket_remote(int s, char ip[16], uint16 *port, uint32 *scope_id)
void uint16_unpack_big(char[16], uint16 *)
void byte_copy(void *, unsigned int, const void *)