ported socket enumerator to raw-socket.c

some cleanups in socket.c
This commit is contained in:
Martin Willi
2008-11-13 07:15:45 +00:00
parent 84bec926a3
commit 8120943583
2 changed files with 80 additions and 87 deletions
+14 -15
View File
@@ -96,18 +96,6 @@ struct private_socket_t {
int ipv6_natt;
};
/**
* enumerator for underlying sockets
*/
typedef struct {
/** implements enumerator_t */
enumerator_t public;
/** sockets we enumerate */
private_socket_t *socket;
/** counter */
u_int8_t index;
} socket_enumerator_t;
/**
* implementation of socket_t.receive
*/
@@ -482,6 +470,18 @@ static int open_socket(private_socket_t *this, int family, u_int16_t port)
return skt;
}
/**
* enumerator for underlying sockets
*/
typedef struct {
/** implements enumerator_t */
enumerator_t public;
/** sockets we enumerate */
private_socket_t *socket;
/** counter */
int index;
} socket_enumerator_t;
/**
* enumerate function for socket_enumerator_t
*/
@@ -492,14 +492,13 @@ static bool enumerate(socket_enumerator_t *this, int *fd, int *family, int *port
int family;
int port;
} sockets[] = {
{ 0, 0, 0 },
{ offsetof(private_socket_t, ipv4), AF_INET, IKEV2_UDP_PORT },
{ offsetof(private_socket_t, ipv6), AF_INET6, IKEV2_UDP_PORT },
{ offsetof(private_socket_t, ipv4_natt), AF_INET, IKEV2_NATT_PORT },
{ offsetof(private_socket_t, ipv6_natt), AF_INET6, IKEV2_NATT_PORT }
};
while(++this->index <= 4)
while(++this->index < countof(sockets))
{
int sock = *(int*)((char*)this->socket + sockets[this->index].fd_offset);
if (!sock)
@@ -522,7 +521,7 @@ static enumerator_t *create_enumerator(private_socket_t *this)
socket_enumerator_t *enumerator;
enumerator = malloc_thing(socket_enumerator_t);
enumerator->index = 0;
enumerator->index = -1;
enumerator->socket = this;
enumerator->public.enumerate = (void*)enumerate;
enumerator->public.destroy = (void*)free;