Skip to content

Commit

Permalink
Fix: redudp failing to extract original destination address
Browse files Browse the repository at this point in the history
  • Loading branch information
semigodking committed Nov 22, 2019
1 parent 7a2f8ad commit 3a46f2f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@


#define addr_size(addr) (((struct sockaddr *)addr)->sa_family == AF_INET ? sizeof(struct sockaddr_in): \
((struct sockaddr *)addr)->sa_family == AF_INET6 ? sizeof(struct sockaddr_in6): sizeof(struct sockaddr_storage))
((struct sockaddr *)addr)->sa_family == AF_INET6 ? sizeof(struct sockaddr_in6): sizeof(struct sockaddr_storage))

int red_recv_udp_pkt(
int fd,
Expand Down Expand Up @@ -77,7 +77,9 @@ int red_recv_udp_pkt(
if (
cmsg->cmsg_level == SOL_IP &&
cmsg->cmsg_type == IP_ORIGDSTADDR &&
cmsg->cmsg_len >= CMSG_LEN(sizeof(*toaddr))
(cmsg->cmsg_len == CMSG_LEN(sizeof(struct sockaddr_in))
|| cmsg->cmsg_len == CMSG_LEN(sizeof(struct sockaddr_in6))) &&
cmsg->cmsg_len <= CMSG_LEN(sizeof(*toaddr))
) {
struct sockaddr* cmsgaddr = (struct sockaddr*)CMSG_DATA(cmsg);
if (cmsgaddr->sa_family == AF_INET) {
Expand Down

0 comments on commit 3a46f2f

Please sign in to comment.