#include <config.h>
#endif
-#include <sys/un.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/select.h>
#include <sys/socket.h>
+#include <sys/un.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
BROWSING
} state = ACKWAIT;
-static int quit = 0;
-
static enum {
DAEMON_RUN,
DAEMON_KILL,
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 {
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
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;
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);
AvahiIfIndex interface;
AvahiProtocol protocol;
int i_interface, i_protocol, port;
- char a[64];
+ char a[AVAHI_ADDRESS_STR_MAX];
assert(state == BROWSING);
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;
}
{ "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) {
command = DAEMON_CHECK;
break;
default:
- fprintf(stderr, "Invalid command line argument: %c\n", c);
return -1;
}
}
/** 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;
}