summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/uanytun.c4
-rw-r--r--src/udp.c4
-rw-r--r--src/udp.h1
3 files changed, 8 insertions, 1 deletions
diff --git a/src/uanytun.c b/src/uanytun.c
index c80ca8b..42b082a 100644
--- a/src/uanytun.c
+++ b/src/uanytun.c
@@ -155,6 +155,9 @@ int process_tun_data(tun_device_t* dev, udp_socket_t* sock, options_t* opt, plai
plain_packet_set_type(plain_packet, PAYLOAD_TYPE_TAP);
else
plain_packet_set_type(plain_packet, PAYLOAD_TYPE_UNKNOWN);
+
+ if(!sock->remote_end_set_)
+ return 0;
cipher_encrypt(c, kd, kd_outbound, plain_packet, encrypted_packet, seq_nr, opt->sender_id_, opt->mux_);
@@ -212,6 +215,7 @@ int process_sock_data(tun_device_t* dev, udp_socket_t* sock, options_t* opt, pla
if(memcmp(&remote, &(sock->remote_end_), sizeof(remote))) {
memcpy(&(sock->remote_end_), &remote, sizeof(remote));
+ sock->remote_end_set_ = 1;
char* addrstring = udp_endpoint_to_string(remote);
log_printf(NOTICE, "autodetected remote host changed %s", addrstring);
free(addrstring);
diff --git a/src/udp.c b/src/udp.c
index 853812c..4d59509 100644
--- a/src/udp.c
+++ b/src/udp.c
@@ -51,6 +51,7 @@ int udp_init(udp_socket_t* sock, const char* local_addr, const char* port)
sock->fd_ = 0;
memset(&(sock->local_end_), 0, sizeof(sock->local_end_));
memset(&(sock->remote_end_), 0, sizeof(sock->local_end_));
+ sock->remote_end_set_ = 0;
struct addrinfo hints, *res;
@@ -116,6 +117,7 @@ void udp_set_remote(udp_socket_t* sock, const char* remote_addr, const char* por
return;
}
memcpy(&(sock->remote_end_), res->ai_addr, sizeof(*(res->ai_addr)));
+ sock->remote_end_set_ = 1;
freeaddrinfo(res);
}
@@ -172,7 +174,7 @@ char* udp_get_local_end_string(udp_socket_t* sock)
char* udp_get_remote_end_string(udp_socket_t* sock)
{
- if(!sock)
+ if(!sock || !sock->remote_end_set_)
return "";
return udp_endpoint_to_string(sock->remote_end_);
diff --git a/src/udp.h b/src/udp.h
index d998b39..b033c5e 100644
--- a/src/udp.h
+++ b/src/udp.h
@@ -49,6 +49,7 @@ struct udp_socket_struct {
int fd_;
udp_endpoint_t local_end_;
udp_endpoint_t remote_end_;
+ int remote_end_set_;
};
typedef struct udp_socket_struct udp_socket_t;