X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fmdnsd.git;a=blobdiff_plain;f=util.c;h=0c4a4eed68da2e336ffe1341b8c5d664e2312140;hp=a4a117bc2ef4f49da0b0c90982330cd917654db5;hb=9061708d9d39f011c5e78f922a5262ad571607cb;hpb=788316ef66136e6a68d881e5b24ccf5a98fa4550;ds=sidebyside diff --git a/util.c b/util.c index a4a117b..0c4a4ee 100644 --- a/util.c +++ b/util.c @@ -34,7 +34,6 @@ #include "util.h" int debug = 0; -struct uloop_fd listener; static void signal_shutdown(int signal) @@ -73,31 +72,6 @@ rand_time_delta(uint32_t t) return val; } -const char* -get_iface_ipv4(const char *ifname) -{ - static char buffer[INET_ADDRSTRLEN]; - struct ifreq ir; - const char *ret; - int sock; - - sock = socket(AF_INET, SOCK_DGRAM, 0); - if (sock < 0) - return NULL; - - memset(&ir, 0, sizeof(struct ifreq)); - - strncpy(ir.ifr_name, ifname, sizeof(ir.ifr_name)); - - if (ioctl(sock, SIOCGIFADDR, &ir) < 0) - return NULL; - - ret = inet_ntop(AF_INET, &((struct sockaddr_in *) &ir.ifr_addr)->sin_addr, buffer, sizeof(buffer)); - close(sock); - - return ret; -} - char* get_hostname(void) { @@ -109,50 +83,8 @@ get_hostname(void) return utsname.nodename; } -int -socket_setup(int fd, const char *ip) -{ - struct ip_mreqn mreq; - uint8_t ttl = 255; - int yes = 1; - int no = 0; - struct sockaddr_in sa; - - sa.sin_family = AF_INET; - sa.sin_port = htons(MCAST_PORT); - inet_pton(AF_INET, MCAST_ADDR, &sa.sin_addr); - - memset(&mreq, 0, sizeof(mreq)); - mreq.imr_address.s_addr = htonl(INADDR_ANY); - mreq.imr_multiaddr = sa.sin_addr; - - if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0) - fprintf(stderr, "ioctl failed: IP_MULTICAST_TTL\n"); - - if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) - fprintf(stderr, "ioctl failed: SO_REUSEADDR\n"); - - if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) { - fprintf(stderr, "failed to join multicast group: %s\n", strerror(errno)); - close(fd); - fd = -1; - return -1; - } - - if (setsockopt(fd, IPPROTO_IP, IP_RECVTTL, &yes, sizeof(yes)) < 0) - fprintf(stderr, "ioctl failed: IP_RECVTTL\n"); - - if (setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &yes, sizeof(yes)) < 0) - fprintf(stderr, "ioctl failed: IP_PKTINFO\n"); - - if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, &no, sizeof(no)) < 0) - fprintf(stderr, "ioctl failed: IP_MULTICAST_LOOP\n"); - - return 0; -} - void* -memdup(void *d, int l) +memdup(const void *d, int l) { void *r = malloc(l); if (!r)