Skip to content

Commit e62773d

Browse files
committed
get_iface_local_addr4: handle err from get_ifindex
- return on wrong iface spec (similarly as IPv6 does) - return on "help"
1 parent e88ad54 commit e62773d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/rtp/net_udp.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ static bool udp_addr_valid4(const char *dst)
376376
* 2. representation of the address if iface is an adress
377377
* 3a. [Windows only] interface index
378378
* 3b. [otherwise] iface local address
379+
* 4a. [error] htonl(INADDR_ANY) if no IPv4 address on iface
380+
* 4b. [error] ((unsigned) -1) on wrong iface spec or help
379381
*/
380382
static in_addr_t
381383
get_iface_local_addr4(const char iface[])
@@ -392,7 +394,7 @@ get_iface_local_addr4(const char iface[])
392394

393395
unsigned int ifindex = get_ifindex(iface);
394396
if (ifindex == (unsigned) -1) {
395-
return htonl(INADDR_ANY);
397+
return ifindex;
396398
}
397399

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

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

0 commit comments

Comments
 (0)