X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fnet_packet.c;h=3d3d6913f34d9cc1061bc827f8a47ffc2654bc0b;hb=6be453fc63da9f87455b5e579cb686f95fa92102;hp=c8f48d32b1f9fd4682166c8a4574f3f8be7bdae8;hpb=43cf631bc10097448db041639ad07f84f647017e;p=tinc diff --git a/src/net_packet.c b/src/net_packet.c index c8f48d32..3d3d6913 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -23,6 +23,7 @@ #include "system.h" #ifdef HAVE_ZLIB +#define ZLIB_CONST #include #endif @@ -158,8 +159,11 @@ static void udp_probe_h(node_t *n, vpn_packet_t *packet, length_t len) { if(!n->status.udp_confirmed) { n->status.udp_confirmed = true; fprintf(stderr, "Updating address cache...\n"); - if (!n->address_cache) + + if(!n->address_cache) { n->address_cache = open_address_cache(n); + } + reset_address_cache(n->address_cache, &n->address); } @@ -246,9 +250,22 @@ static length_t uncompress_packet(uint8_t *dest, const uint8_t *source, length_t #ifdef HAVE_ZLIB else { unsigned long destlen = MAXSIZE; + static z_stream stream; - if(uncompress(dest, &destlen, source, len) == Z_OK) { - return destlen; + if(stream.next_in) { + inflateReset(&stream); + } else { + inflateInit(&stream); + } + + stream.next_in = source; + stream.avail_in = len; + stream.next_out = dest; + stream.avail_out = destlen; + stream.total_out = 0; + + if(inflate(&stream, Z_FINISH) == Z_STREAM_END) { + return stream.total_out; } else { return -1; }