From a4c3018c79d9ec9bebedc17135bf16811add7911 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 19 Feb 2019 14:54:42 +0100 Subject: [PATCH] Fix udp again --- src/packet.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/packet.c b/src/packet.c index bb798e3..2ce45ba 100644 --- a/src/packet.c +++ b/src/packet.c @@ -48,6 +48,12 @@ enum FD_STATE write_packet_to_udp(int fd, struct buffer_packet* bp, struct udp_t ssize_t nwrite; size_t bytes_to_send; size_t pkt_header_size = sizeof(bp->ip.ap.str) - sizeof(char); + struct sockaddr* addr = NULL; + socklen_t addrlen = 0; + if (udp_t->set) { + addr = (struct sockaddr*) &udp_t->addr; + addrlen = sizeof(struct sockaddr_in); + } if (bp->mode != BP_WRITING) return FDS_ERR; @@ -56,8 +62,8 @@ enum FD_STATE write_packet_to_udp(int fd, struct buffer_packet* bp, struct udp_t &(bp->ip.ap.str.payload), bytes_to_send, 0, - (struct sockaddr*)&udp_t->addr, - udp_t->addrlen); + addr, + addrlen); if (nwrite == -1 && errno == EAGAIN) return FDS_AGAIN; if (nwrite != bytes_to_send) return FDS_ERR;