created identification_create_from_sockaddr() function
This commit is contained in:
@@ -819,6 +819,9 @@ int identification_printf_hook(char *dst, size_t len, printf_hook_spec_t *spec,
|
|||||||
snprintf(buf, sizeof(buf), "%#B", &this->encoded);
|
snprintf(buf, sizeof(buf), "%#B", &this->encoded);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case ID_MYID:
|
||||||
|
snprintf(buf, sizeof(buf), "%%myid");
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
snprintf(buf, sizeof(buf), "(unknown ID type: %d)", this->type);
|
snprintf(buf, sizeof(buf), "(unknown ID type: %d)", this->type);
|
||||||
break;
|
break;
|
||||||
@@ -1022,3 +1025,33 @@ identification_t *identification_create_from_encoding(id_type_t type,
|
|||||||
return &(this->public);
|
return &(this->public);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Described in header.
|
||||||
|
*/
|
||||||
|
identification_t *identification_create_from_sockaddr(sockaddr_t *sockaddr)
|
||||||
|
{
|
||||||
|
switch (sockaddr->sa_family)
|
||||||
|
{
|
||||||
|
case AF_INET:
|
||||||
|
{
|
||||||
|
struct in_addr *addr = &(((struct sockaddr_in*)sockaddr)->sin_addr);
|
||||||
|
|
||||||
|
return identification_create_from_encoding(ID_IPV4_ADDR,
|
||||||
|
chunk_create((u_char*)addr, sizeof(struct in_addr)));
|
||||||
|
}
|
||||||
|
case AF_INET6:
|
||||||
|
{
|
||||||
|
struct in6_addr *addr = &(((struct sockaddr_in6*)sockaddr)->sin6_addr);
|
||||||
|
|
||||||
|
return identification_create_from_encoding(ID_IPV6_ADDR,
|
||||||
|
chunk_create((u_char*)addr, sizeof(struct in6_addr)));
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
private_identification_t *this = identification_create(ID_ANY);
|
||||||
|
|
||||||
|
return &(this->public);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -322,6 +322,14 @@ identification_t * identification_create_from_string(char *string);
|
|||||||
*/
|
*/
|
||||||
identification_t * identification_create_from_encoding(id_type_t type, chunk_t encoded);
|
identification_t * identification_create_from_encoding(id_type_t type, chunk_t encoded);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to create a host_t object from a sockaddr struct
|
||||||
|
*
|
||||||
|
* @param sockaddr sockaddr struct which contains family and address
|
||||||
|
* @return identification_t
|
||||||
|
*/
|
||||||
|
identification_t * identification_create_from_sockaddr(sockaddr_t *sockaddr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* printf hook function for identification_t.
|
* printf hook function for identification_t.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user