Skip to content

Commit

Permalink
get_iface_local_addr4: handle err from get_ifindex
Browse files Browse the repository at this point in the history
- return on wrong iface spec (similarly as IPv6 does)
- return on "help"
  • Loading branch information
MartinPulec committed Dec 4, 2024
1 parent e88ad54 commit e62773d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/rtp/net_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ static bool udp_addr_valid4(const char *dst)
* 2. representation of the address if iface is an adress
* 3a. [Windows only] interface index
* 3b. [otherwise] iface local address
* 4a. [error] htonl(INADDR_ANY) if no IPv4 address on iface
* 4b. [error] ((unsigned) -1) on wrong iface spec or help
*/
static in_addr_t
get_iface_local_addr4(const char iface[])
Expand All @@ -392,7 +394,7 @@ get_iface_local_addr4(const char iface[])

unsigned int ifindex = get_ifindex(iface);
if (ifindex == (unsigned) -1) {
return htonl(INADDR_ANY);
return ifindex;
}

#ifdef _WIN32
Expand Down Expand Up @@ -429,6 +431,9 @@ udp_join_mcast_grp4(unsigned long addr, int rx_fd, int tx_fd, int ttl,
struct ip_mreq imr;

in_addr_t iface_addr = get_iface_local_addr4(iface);
if (iface_addr == (unsigned) -1) {
return false;
}
char buf[IN4_MAX_ASCII_LEN + 1] = "(err. unknown)";
inet_ntop(AF_INET, &iface_addr, buf, sizeof buf);
MSG(INFO, "mcast4 iface bound to: %s\n", buf);
Expand Down

0 comments on commit e62773d

Please sign in to comment.