X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;ds=sidebyside;f=avahi-dnsconfd%2Fmain.c;h=d10374b83a858eec0aae36d8d2e986ab3b86f2ac;hb=e96bb759f1b469c45eceae696d505663183b70b3;hp=cca0b68118a1195c7487f513580a8feca944933c;hpb=f6924be4422c2477796301cda4a3c663d7e62909;p=catta diff --git a/avahi-dnsconfd/main.c b/avahi-dnsconfd/main.c index cca0b68..d10374b 100644 --- a/avahi-dnsconfd/main.c +++ b/avahi-dnsconfd/main.c @@ -23,11 +23,11 @@ #include #endif -#include #include #include #include #include +#include #include #include #include @@ -61,8 +61,6 @@ static enum { BROWSING } state = ACKWAIT; -static int quit = 0; - static enum { DAEMON_RUN, DAEMON_KILL, @@ -72,8 +70,13 @@ static enum { DAEMON_CHECK } command = DAEMON_RUN; +static int quit = 0; static int daemonize = 0; +#if !HAVE_DECL_ENVIRON +extern char **environ; +#endif + typedef struct DNSServerInfo DNSServerInfo; struct DNSServerInfo { @@ -199,8 +202,18 @@ static char *concat_dns_servers(AvahiIfIndex interface) { for (i = servers; i; i = i->servers_next) if (i->interface == interface || interface <= 0) { + DNSServerInfo *j; char *t; + /* Filter out double entries */ + for (j = servers; j != i; j = j->servers_next) + if (j->interface == interface || interface <= 0) + if (strcmp(i->address, j->address) == 0) + break; + + if (j != i) + continue; + if (!r) t = avahi_strdup(i->address); else @@ -213,37 +226,6 @@ static char *concat_dns_servers(AvahiIfIndex interface) { return r; } -static char *getifname(AvahiIfIndex interface, char *name, size_t len) { - int fd = -1; - char *ret = NULL; - struct ifreq ifr; - - assert(interface >= 0); - - if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { - daemon_log(LOG_ERR, "socket(): %s", strerror(errno)); - goto finish; - } - - memset(&ifr, 0, sizeof(ifr)); - ifr.ifr_ifindex = (int) interface; - - if (ioctl(fd, SIOCGIFNAME, &ifr) < 0) { - daemon_log(LOG_ERR, "SIOCGIFNAME: %s\n", strerror(errno)); - goto finish; - } - - strncpy(name, ifr.ifr_name, len-1); - name[len-1] = 0; - ret = name; - -finish: - if (fd >= 0) - close(fd); - - return ret; -} - static void set_env(const char *name, const char *value) { char **e; size_t l; @@ -274,11 +256,11 @@ static void run_script(int new, AvahiIfIndex interface, AvahiProtocol protocol, char *p; int ret; char ia[16], pa[16]; - char name[IFNAMSIZ+1]; + char name[IF_NAMESIZE]; assert(interface > 0); - if (!getifname(interface, name, sizeof(name))) + if (!if_indextoname(interface, name)) return; p = concat_dns_servers(interface); @@ -315,7 +297,7 @@ static int new_line(const char *l) { AvahiIfIndex interface; AvahiProtocol protocol; int i_interface, i_protocol, port; - char a[64]; + char a[AVAHI_ADDRESS_STR_MAX]; assert(state == BROWSING); @@ -324,7 +306,7 @@ static int new_line(const char *l) { return -1; } - if (sscanf(l+1, "%i %i %64s %i", &i_interface, &i_protocol, a, &port) != 4) { + if (sscanf(l+1, "%i %i %39s %i", &i_interface, &i_protocol, a, &port) != 4) { daemon_log(LOG_ERR, "Failed to parse browsing line: %s", l); return -1; } @@ -411,9 +393,9 @@ static int parse_command_line(int argc, char *argv[]) { { "version", no_argument, NULL, 'V' }, { "refresh", no_argument, NULL, 'r' }, { "check", no_argument, NULL, 'c' }, + { NULL, 0, NULL, 0 } }; - opterr = 0; while ((c = getopt_long(argc, argv, "hDkVrc", long_options, NULL)) >= 0) { switch(c) { @@ -436,7 +418,6 @@ static int parse_command_line(int argc, char *argv[]) { command = DAEMON_CHECK; break; default: - fprintf(stderr, "Invalid command line argument: %c\n", c); return -1; } } @@ -616,7 +597,7 @@ int main(int argc, char *argv[]) { /** Parent **/ if ((ret = daemon_retval_wait(20)) < 0) { - daemon_log(LOG_ERR, "Could not recieve return value from daemon process."); + daemon_log(LOG_ERR, "Could not receive return value from daemon process."); goto finish; }