Skip to content

Commit

Permalink
Handle BSD vs GLIBC differences in udp.h
Browse files Browse the repository at this point in the history
  • Loading branch information
rigtorp committed Nov 16, 2020
1 parent 021c37d commit 43ff116
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/udpreplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,22 @@ int main(int argc, char *argv[]) {
}
}

#ifdef __GLIBC__
ssize_t len = ntohs(udp->len) - 8;
#else
ssize_t len = ntohs(udp->uh_ulen) - 8;
#endif
const u_char *d =
&p[sizeof(ether_header) + ip->ip_hl * 4 + sizeof(udphdr)];

sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
#ifdef __GLIBC__
addr.sin_port = udp->dest;
#else
addr.sin_port = udp->uh_dport;
#endif
addr.sin_addr = {ip->ip_dst};
auto n = sendto(fd, d, len, 0, reinterpret_cast<sockaddr *>(&addr),
sizeof(addr));
Expand Down

0 comments on commit 43ff116

Please sign in to comment.