mirror of
https://github.com/ntop/n2n.git
synced 2024-09-19 16:41:11 +02:00
generalized sockaddr usage in edge (#1026)
This commit is contained in:
parent
ffb4e31b8a
commit
439dfc6886
|
@ -191,7 +191,7 @@ int fill_sockaddr (struct sockaddr * addr,
|
||||||
const n2n_sock_t * sock);
|
const n2n_sock_t * sock);
|
||||||
|
|
||||||
int fill_n2nsock (n2n_sock_t* sock,
|
int fill_n2nsock (n2n_sock_t* sock,
|
||||||
struct sockaddr* sa);
|
const struct sockaddr* sa);
|
||||||
|
|
||||||
int encode_PACKET (uint8_t * base,
|
int encode_PACKET (uint8_t * base,
|
||||||
size_t * idx,
|
size_t * idx,
|
||||||
|
|
|
@ -2160,7 +2160,7 @@ void edge_read_from_tap (n2n_edge_t * eee) {
|
||||||
|
|
||||||
|
|
||||||
/** handle a datagram from the main UDP socket to the internet. */
|
/** handle a datagram from the main UDP socket to the internet. */
|
||||||
void process_udp (n2n_edge_t *eee, const struct sockaddr_in *sender_sock, const SOCKET in_sock,
|
void process_udp (n2n_edge_t *eee, const struct sockaddr *sender_sock, const SOCKET in_sock,
|
||||||
uint8_t *udp_buf, size_t udp_size, time_t now) {
|
uint8_t *udp_buf, size_t udp_size, time_t now) {
|
||||||
|
|
||||||
n2n_common_t cmn; /* common fields in the packet header */
|
n2n_common_t cmn; /* common fields in the packet header */
|
||||||
|
@ -2192,7 +2192,7 @@ void process_udp (n2n_edge_t *eee, const struct sockaddr_in *sender_sock, const
|
||||||
else {
|
else {
|
||||||
// REVISIT: type conversion back and forth, choose a consistent approach throughout whole code,
|
// REVISIT: type conversion back and forth, choose a consistent approach throughout whole code,
|
||||||
// i.e. stick with more general sockaddr as long as possible and narrow only if required
|
// i.e. stick with more general sockaddr as long as possible and narrow only if required
|
||||||
fill_n2nsock(&sender, (struct sockaddr*)sender_sock);
|
fill_n2nsock(&sender, sender_sock);
|
||||||
}
|
}
|
||||||
/* The packet may not have an orig_sender socket spec. So default to last
|
/* The packet may not have an orig_sender socket spec. So default to last
|
||||||
* hop as sender. */
|
* hop as sender. */
|
||||||
|
@ -2703,18 +2703,18 @@ int fetch_and_eventually_process_data (n2n_edge_t *eee, SOCKET sock,
|
||||||
|
|
||||||
ssize_t bread = 0;
|
ssize_t bread = 0;
|
||||||
|
|
||||||
|
struct sockaddr_storage sas;
|
||||||
|
struct sockaddr *sender_sock = (struct sockaddr*)&sas;
|
||||||
|
socklen_t ss_size = sizeof(sas);
|
||||||
|
|
||||||
if((!eee->conf.connect_tcp)
|
if((!eee->conf.connect_tcp)
|
||||||
#ifndef SKIP_MULTICAST_PEERS_DISCOVERY
|
#ifndef SKIP_MULTICAST_PEERS_DISCOVERY
|
||||||
|| (sock == eee->udp_multicast_sock)
|
|| (sock == eee->udp_multicast_sock)
|
||||||
#endif
|
#endif
|
||||||
) {
|
) {
|
||||||
// udp
|
// udp
|
||||||
struct sockaddr_in sender_sock;
|
|
||||||
socklen_t i;
|
|
||||||
|
|
||||||
i = sizeof(sender_sock);
|
|
||||||
bread = recvfrom(sock, pktbuf, N2N_PKT_BUF_SIZE, 0 /*flags*/,
|
bread = recvfrom(sock, pktbuf, N2N_PKT_BUF_SIZE, 0 /*flags*/,
|
||||||
(struct sockaddr *)&sender_sock, (socklen_t *)&i);
|
sender_sock, &ss_size);
|
||||||
|
|
||||||
if((bread < 0)
|
if((bread < 0)
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
@ -2733,18 +2733,14 @@ int fetch_and_eventually_process_data (n2n_edge_t *eee, SOCKET sock,
|
||||||
// we have a datagram to process...
|
// we have a datagram to process...
|
||||||
if(bread > 0) {
|
if(bread > 0) {
|
||||||
// ...and the datagram has data (not just a header)
|
// ...and the datagram has data (not just a header)
|
||||||
process_udp(eee, &sender_sock, sock, pktbuf, bread, now);
|
process_udp(eee, sender_sock, sock, pktbuf, bread, now);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// tcp
|
// tcp
|
||||||
struct sockaddr_in sender_sock;
|
|
||||||
socklen_t i;
|
|
||||||
|
|
||||||
i = sizeof(sender_sock);
|
|
||||||
bread = recvfrom(sock,
|
bread = recvfrom(sock,
|
||||||
pktbuf + *position, *expected - *position, 0 /*flags*/,
|
pktbuf + *position, *expected - *position, 0 /*flags*/,
|
||||||
(struct sockaddr *)&sender_sock, (socklen_t *)&i);
|
sender_sock, &ss_size);
|
||||||
if((bread <= 0) && (errno)) {
|
if((bread <= 0) && (errno)) {
|
||||||
traceEvent(TRACE_ERROR, "recvfrom() failed %d errno %d (%s)", bread, errno, strerror(errno));
|
traceEvent(TRACE_ERROR, "recvfrom() failed %d errno %d (%s)", bread, errno, strerror(errno));
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
@ -2768,7 +2764,7 @@ int fetch_and_eventually_process_data (n2n_edge_t *eee, SOCKET sock,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// full packet read, handle it
|
// full packet read, handle it
|
||||||
process_udp(eee, (struct sockaddr_in*)&sender_sock, sock,
|
process_udp(eee, sender_sock, sock,
|
||||||
pktbuf + sizeof(uint16_t), *position - sizeof(uint16_t), now);
|
pktbuf + sizeof(uint16_t), *position - sizeof(uint16_t), now);
|
||||||
// reset, await new prepended length
|
// reset, await new prepended length
|
||||||
*expected = sizeof(uint16_t);
|
*expected = sizeof(uint16_t);
|
||||||
|
|
|
@ -615,7 +615,7 @@ int fill_sockaddr (struct sockaddr * addr,
|
||||||
|
|
||||||
|
|
||||||
// fills struct sockaddr's data into n2n_sock
|
// fills struct sockaddr's data into n2n_sock
|
||||||
int fill_n2nsock (n2n_sock_t* sock, struct sockaddr* sa) {
|
int fill_n2nsock (n2n_sock_t* sock, const struct sockaddr* sa) {
|
||||||
|
|
||||||
sock->family = *(sa_family_t*)sa;
|
sock->family = *(sa_family_t*)sa;
|
||||||
switch(sock->family) {
|
switch(sock->family) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user