ported some hard-to-merge cherries back to trunk :-/
shame, svn, shame: this was ways to complicated we should consider a switch to git...
This commit is contained in:
@@ -504,38 +504,56 @@ host_t *host_create_from_dns(char *string, int af, u_int16_t port)
|
||||
*/
|
||||
host_t *host_create_from_chunk(int family, chunk_t address, u_int16_t port)
|
||||
{
|
||||
private_host_t *this = host_create_empty();
|
||||
private_host_t *this;
|
||||
|
||||
switch (family)
|
||||
{
|
||||
case AF_INET:
|
||||
if (address.len < IPV4_LEN)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
address.len = IPV4_LEN;
|
||||
break;
|
||||
case AF_INET6:
|
||||
if (address.len < IPV6_LEN)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
address.len = IPV6_LEN;
|
||||
break;
|
||||
case AF_UNSPEC:
|
||||
switch (address.len)
|
||||
{
|
||||
case IPV4_LEN:
|
||||
family = AF_INET;
|
||||
break;
|
||||
case IPV6_LEN:
|
||||
family = AF_INET6;
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
this = host_create_empty();
|
||||
this->address.sa_family = family;
|
||||
switch (family)
|
||||
{
|
||||
case AF_INET:
|
||||
{
|
||||
if (address.len != IPV4_LEN)
|
||||
{
|
||||
break;
|
||||
}
|
||||
memcpy(&(this->address4.sin_addr.s_addr), address.ptr, IPV4_LEN);
|
||||
memcpy(&this->address4.sin_addr.s_addr, address.ptr, address.len);
|
||||
this->address4.sin_port = htons(port);
|
||||
this->socklen = sizeof(struct sockaddr_in);
|
||||
return &(this->public);
|
||||
}
|
||||
break;
|
||||
case AF_INET6:
|
||||
{
|
||||
if (address.len != IPV6_LEN)
|
||||
{
|
||||
break;
|
||||
}
|
||||
memcpy(&(this->address6.sin6_addr.s6_addr), address.ptr, IPV6_LEN);
|
||||
memcpy(&this->address6.sin6_addr.s6_addr, address.ptr, address.len);
|
||||
this->address6.sin6_port = htons(port);
|
||||
this->socklen = sizeof(struct sockaddr_in6);
|
||||
return &this->public;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
free(this);
|
||||
return NULL;
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -170,7 +170,9 @@ host_t *host_create_from_string(char *string, u_int16_t port);
|
||||
host_t *host_create_from_dns(char *string, int family, u_int16_t port);
|
||||
|
||||
/**
|
||||
* Constructor to create a host_t object from an address chunk
|
||||
* Constructor to create a host_t object from an address chunk.
|
||||
*
|
||||
* If family is AF_UNSPEC, it is guessed using address.len.
|
||||
*
|
||||
* @param family Address family, such as AF_INET or AF_INET6
|
||||
* @param address address as chunk_t in network order
|
||||
|
||||
Reference in New Issue
Block a user