diff --git a/input_iptv.c b/input_iptv.c index 85c6ea15..48159f6f 100644 --- a/input_iptv.c +++ b/input_iptv.c @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -84,6 +85,7 @@ iptv_start_feed(th_transport_t *t, unsigned int weight) memset(&m, 0, sizeof(m)); m.imr_multiaddr.s_addr = t->tht_iptv_group_addr.s_addr; m.imr_address.s_addr = t->tht_iptv_interface_addr.s_addr; + m.imr_ifindex = t->tht_iptv_ifindex; if(setsockopt(fd, SOL_IP, IP_ADD_MEMBERSHIP, &m, sizeof(struct ip_mreqn)) == -1) { @@ -128,7 +130,10 @@ iptv_configure_transport(th_transport_t *t, const char *muxname) { config_entry_t *ce; const char *s; + int fd; char buf[100]; + char ifname[100]; + struct ifreq ifr; if((ce = find_mux_config("iptvmux", muxname)) == NULL) return -1; @@ -139,16 +144,38 @@ iptv_configure_transport(th_transport_t *t, const char *muxname) return -1; t->tht_iptv_group_addr.s_addr = inet_addr(s); - if((s = config_get_str_sub(&ce->ce_sub, "interface-address", NULL)) == NULL) - return -1; - t->tht_iptv_interface_addr.s_addr = inet_addr(s); + t->tht_iptv_ifindex = 0; + + if((s = config_get_str_sub(&ce->ce_sub, "interface-address", NULL)) != NULL) + t->tht_iptv_interface_addr.s_addr = inet_addr(s); + else + t->tht_iptv_interface_addr.s_addr = INADDR_ANY; + + snprintf(ifname, sizeof(ifname), "%s", + inet_ntoa(t->tht_iptv_interface_addr)); + + if((s = config_get_str_sub(&ce->ce_sub, "interface", NULL)) != NULL) { + + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, s, IFNAMSIZ - 1); + ifr.ifr_name[IFNAMSIZ - 1] = 0; + + fd = socket(PF_INET,SOCK_STREAM,0); + if(fd != -1) { + if(ioctl(fd, SIOCGIFINDEX, &ifr) == 0) { + t->tht_iptv_ifindex = ifr.ifr_ifindex; + snprintf(ifname, sizeof(ifname), "%s", s); + } + close(fd); + } + } if((s = config_get_str_sub(&ce->ce_sub, "port", NULL)) == NULL) return -1; t->tht_iptv_port = atoi(s); - snprintf(buf, sizeof(buf), "IPTV: %s (%s:%d)", muxname, - inet_ntoa(t->tht_iptv_group_addr), t->tht_iptv_port); + snprintf(buf, sizeof(buf), "IPTV: %s (%s:%s:%d)", muxname, + ifname, inet_ntoa(t->tht_iptv_group_addr), t->tht_iptv_port); t->tht_name = strdup(buf); return 0; diff --git a/tvhead.h b/tvhead.h index a843b495..e893f1e4 100644 --- a/tvhead.h +++ b/tvhead.h @@ -186,6 +186,8 @@ typedef struct th_transport { struct in_addr group_addr; struct in_addr interface_addr; + int ifindex; + int port; int fd; void *dispatch_handle; @@ -205,6 +207,7 @@ typedef struct th_transport { #define tht_iptv_group_addr u.iptv.group_addr #define tht_iptv_interface_addr u.iptv.interface_addr +#define tht_iptv_ifindex u.iptv.ifindex #define tht_iptv_port u.iptv.port #define tht_iptv_dispatch_handle u.iptv.dispatch_handle #define tht_iptv_fd u.iptv.fd