net: Socket implementations report the address families they support
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2006-2012 Tobias Brunner
|
||||
* Copyright (C) 2006-2013 Tobias Brunner
|
||||
* Copyright (C) 2005-2010 Martin Willi
|
||||
* Copyright (C) 2006 Daniel Roethlisberger
|
||||
* Copyright (C) 2005 Jan Hutter
|
||||
@@ -25,6 +25,7 @@
|
||||
#define SOCKET_H_
|
||||
|
||||
typedef struct socket_t socket_t;
|
||||
typedef enum socket_family_t socket_family_t;
|
||||
|
||||
#include <library.h>
|
||||
#include <networking/packet.h>
|
||||
@@ -36,6 +37,31 @@ typedef struct socket_t socket_t;
|
||||
*/
|
||||
typedef socket_t *(*socket_constructor_t)();
|
||||
|
||||
/**
|
||||
* Address families supported by socket implementations.
|
||||
*/
|
||||
enum socket_family_t {
|
||||
/**
|
||||
* No address families supported
|
||||
*/
|
||||
SOCKET_FAMILY_NONE = 0,
|
||||
|
||||
/**
|
||||
* IPv4
|
||||
*/
|
||||
SOCKET_FAMILY_IPV4 = (1 << 0),
|
||||
|
||||
/**
|
||||
* IPv6
|
||||
*/
|
||||
SOCKET_FAMILY_IPV6 = (1 << 1),
|
||||
|
||||
/**
|
||||
* Both address families supported
|
||||
*/
|
||||
SOCKET_FAMILY_BOTH = (1 << 2) - 1,
|
||||
};
|
||||
|
||||
/**
|
||||
* Socket interface definition.
|
||||
*/
|
||||
@@ -75,6 +101,13 @@ struct socket_t {
|
||||
*/
|
||||
u_int16_t (*get_port)(socket_t *this, bool nat_t);
|
||||
|
||||
/**
|
||||
* Get the address families this socket is listening on.
|
||||
*
|
||||
* @return supported families
|
||||
*/
|
||||
socket_family_t (*supported_families)(socket_t *this);
|
||||
|
||||
/**
|
||||
* Destroy a socket implementation.
|
||||
*/
|
||||
|
||||
@@ -102,6 +102,19 @@ METHOD(socket_manager_t, get_port, u_int16_t,
|
||||
return port;
|
||||
}
|
||||
|
||||
METHOD(socket_manager_t, supported_families, socket_family_t,
|
||||
private_socket_manager_t *this)
|
||||
{
|
||||
socket_family_t families = SOCKET_FAMILY_NONE;
|
||||
this->lock->read_lock(this->lock);
|
||||
if (this->socket)
|
||||
{
|
||||
families = this->socket->supported_families(this->socket);
|
||||
}
|
||||
this->lock->unlock(this->lock);
|
||||
return families;
|
||||
}
|
||||
|
||||
static void create_socket(private_socket_manager_t *this)
|
||||
{
|
||||
socket_constructor_t create;
|
||||
@@ -167,6 +180,7 @@ socket_manager_t *socket_manager_create()
|
||||
.send = _sender,
|
||||
.receive = _receiver,
|
||||
.get_port = _get_port,
|
||||
.supported_families = _supported_families,
|
||||
.add_socket = _add_socket,
|
||||
.remove_socket = _remove_socket,
|
||||
.destroy = _destroy,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2012 Tobias Brunner
|
||||
* Copyright (C) 2010-2013 Tobias Brunner
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
* Copyright (C) 2010 Martin Willi
|
||||
* Copyright (C) 2010 revosec AG
|
||||
@@ -60,6 +60,13 @@ struct socket_manager_t {
|
||||
*/
|
||||
u_int16_t (*get_port)(socket_manager_t *this, bool nat_t);
|
||||
|
||||
/**
|
||||
* Get the address families the registered socket is listening on.
|
||||
*
|
||||
* @return address families
|
||||
*/
|
||||
socket_family_t (*supported_families)(socket_manager_t *this);
|
||||
|
||||
/**
|
||||
* Register a socket constructor.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2006-2012 Tobias Brunner
|
||||
* Copyright (C) 2006-2013 Tobias Brunner
|
||||
* Copyright (C) 2006 Daniel Roethlisberger
|
||||
* Copyright (C) 2005-2010 Martin Willi
|
||||
* Copyright (C) 2005 Jan Hutter
|
||||
@@ -501,6 +501,22 @@ METHOD(socket_t, get_port, u_int16_t,
|
||||
return nat_t ? this->natt : this->port;
|
||||
}
|
||||
|
||||
METHOD(socket_t, supported_families, socket_family_t,
|
||||
private_socket_default_socket_t *this)
|
||||
{
|
||||
socket_family_t families = SOCKET_FAMILY_NONE;
|
||||
|
||||
if (this->ipv4 != -1 || this->ipv4_natt != -1)
|
||||
{
|
||||
families |= SOCKET_FAMILY_IPV4;
|
||||
}
|
||||
if (this->ipv6 != -1 || this->ipv6_natt != -1)
|
||||
{
|
||||
families |= SOCKET_FAMILY_IPV6;
|
||||
}
|
||||
return families;
|
||||
}
|
||||
|
||||
/**
|
||||
* open a socket to send and receive packets
|
||||
*/
|
||||
@@ -671,6 +687,7 @@ socket_default_socket_t *socket_default_socket_create()
|
||||
.send = _sender,
|
||||
.receive = _receiver,
|
||||
.get_port = _get_port,
|
||||
.supported_families = _supported_families,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2006-2012 Tobias Brunner
|
||||
* Copyright (C) 2006-2013 Tobias Brunner
|
||||
* Copyright (C) 2006 Daniel Roethlisberger
|
||||
* Copyright (C) 2005-2010 Martin Willi
|
||||
* Copyright (C) 2005 Jan Hutter
|
||||
@@ -620,6 +620,14 @@ METHOD(socket_t, get_port, u_int16_t,
|
||||
return 0;
|
||||
}
|
||||
|
||||
METHOD(socket_t, supported_families, socket_family_t,
|
||||
private_socket_dynamic_socket_t *this)
|
||||
{
|
||||
/* we could return only the families of the opened sockets, but it could
|
||||
* be that both families are supported even if no socket is yet open */
|
||||
return SOCKET_FAMILY_BOTH;
|
||||
}
|
||||
|
||||
METHOD(socket_t, destroy, void,
|
||||
private_socket_dynamic_socket_t *this)
|
||||
{
|
||||
@@ -654,6 +662,7 @@ socket_dynamic_socket_t *socket_dynamic_socket_create()
|
||||
.send = _sender,
|
||||
.receive = _receiver,
|
||||
.get_port = _get_port,
|
||||
.supported_families = _supported_families,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user