diff options
author | Mike Brady <mikebrady@eircom.net> | 2017-02-05 13:47:01 +0000 |
---|---|---|
committer | Mike Brady <mikebrady@eircom.net> | 2017-02-05 13:47:01 +0000 |
commit | 2cab35cd55eb30c28551927ea7a6435603763889 (patch) | |
tree | c34fa542e818b790d34b020e4d902910f7419d4d /mdns_tinysvcmdns.c | |
parent | 5c42d8203ffc6fb5c24f8eb405a3377d0302cea1 (diff) |
Add a new setting to specify the interface the service should be provided on.
Diffstat (limited to 'mdns_tinysvcmdns.c')
-rw-r--r-- | mdns_tinysvcmdns.c | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/mdns_tinysvcmdns.c b/mdns_tinysvcmdns.c index 8d51d4b..57f41ae 100644 --- a/mdns_tinysvcmdns.c +++ b/mdns_tinysvcmdns.c @@ -70,17 +70,21 @@ static int mdns_tinysvcmdns_register(char *apname, int port) { // Look for an ipv4/ipv6 non-loopback interface to use as the main one. for (ifa = ifalist; ifa != NULL; ifa = ifa->ifa_next) { - if (!(ifa->ifa_flags & IFF_LOOPBACK) && ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET) { - uint32_t main_ip = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr; - - mdnsd_set_hostname(svr, hostname, main_ip); // TTL should be 120 seconds - break; - } else if (!(ifa->ifa_flags & IFF_LOOPBACK) && ifa->ifa_addr && - ifa->ifa_addr->sa_family == AF_INET6) { - struct in6_addr *addr = &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr; - - mdnsd_set_hostname_v6(svr, hostname, addr); // TTL should be 120 seconds - break; + // only check for the named interface, if specified + if ((config.interface==NULL) || (strcmp(config.interface,ifa->ifa_name)==0)) { + + if (!(ifa->ifa_flags & IFF_LOOPBACK) && ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET) { + uint32_t main_ip = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr; + + mdnsd_set_hostname(svr, hostname, main_ip); // TTL should be 120 seconds + break; + } else if (!(ifa->ifa_flags & IFF_LOOPBACK) && ifa->ifa_addr && + ifa->ifa_addr->sa_family == AF_INET6) { + struct in6_addr *addr = &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr; + + mdnsd_set_hostname_v6(svr, hostname, addr); // TTL should be 120 seconds + break; + } } } @@ -92,20 +96,22 @@ static int mdns_tinysvcmdns_register(char *apname, int port) { // Skip the first one, it was already added by set_hostname for (ifa = ifa->ifa_next; ifa != NULL; ifa = ifa->ifa_next) { if (ifa->ifa_flags & IFF_LOOPBACK) // Skip loop-back interfaces - continue; - - switch (ifa->ifa_addr->sa_family) { - case AF_INET: { // ipv4 - uint32_t ip = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr; - struct rr_entry *a_e = rr_create_a(create_nlabel(hostname), ip); // TTL should be 120 seconds - mdnsd_add_rr(svr, a_e); - } break; - case AF_INET6: { // ipv6 - struct in6_addr *addr = &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr; - struct rr_entry *aaaa_e = - rr_create_aaaa(create_nlabel(hostname), addr); // TTL should be 120 seconds - mdnsd_add_rr(svr, aaaa_e); - } break; + continue; + // only check for the named interface, if specified + if ((config.interface==NULL) || (strcmp(config.interface,ifa->ifa_name)==0)) { + switch (ifa->ifa_addr->sa_family) { + case AF_INET: { // ipv4 + uint32_t ip = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr; + struct rr_entry *a_e = rr_create_a(create_nlabel(hostname), ip); // TTL should be 120 seconds + mdnsd_add_rr(svr, a_e); + } break; + case AF_INET6: { // ipv6 + struct in6_addr *addr = &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr; + struct rr_entry *aaaa_e = + rr_create_aaaa(create_nlabel(hostname), addr); // TTL should be 120 seconds + mdnsd_add_rr(svr, aaaa_e); + } break; + } } } |