diff options
author | James <> | 2013-03-17 12:16:37 +0000 |
---|---|---|
committer | James <> | 2013-03-17 12:16:37 +0000 |
commit | 27b76ab0671089c47506615a796a261e993896a7 (patch) | |
tree | 61213d67e7fa87b20356b23798558e2c4212c42f /package/network/utils/resolveip | |
download | trunk-36060-master.tar.gz trunk-36060-master.tar.bz2 trunk-36060-master.zip |
Diffstat (limited to 'package/network/utils/resolveip')
6 files changed, 413 insertions, 0 deletions
diff --git a/package/network/utils/resolveip/.svn/entries b/package/network/utils/resolveip/.svn/entries new file mode 100644 index 0000000..cf3d7dd --- /dev/null +++ b/package/network/utils/resolveip/.svn/entries @@ -0,0 +1,65 @@ +10 + +dir +36060 +svn://svn.openwrt.org/openwrt/trunk/package/network/utils/resolveip +svn://svn.openwrt.org/openwrt + + + +2012-11-08T10:48:08.097938Z +34116 +jow + + + + + + + + + + + + + + +3c298f89-4303-0410-b956-a3cf2f4a3e73 + +src +dir + +Makefile +file + + + + +2013-03-17T12:13:17.000000Z +1fa9897b6ef6d0f594dd26fbd8e322b1 +2012-11-08T10:48:08.097938Z +34116 +jow + + + + + + + + + + + + + + + + + + + + + +1159 + diff --git a/package/network/utils/resolveip/.svn/text-base/Makefile.svn-base b/package/network/utils/resolveip/.svn/text-base/Makefile.svn-base new file mode 100644 index 0000000..d1e675e --- /dev/null +++ b/package/network/utils/resolveip/.svn/text-base/Makefile.svn-base @@ -0,0 +1,45 @@ +# +# Copyright (C) 2011-2012 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=resolveip +PKG_RELEASE:=2 + +include $(INCLUDE_DIR)/package.mk + +define Package/resolveip + SECTION:=utils + CATEGORY:=Base system + TITLE:=Simple DNS resolver with configurable timeout + MAINTAINER:=Jo-Philipp Wich <jow@openwrt.org> +endef + +define Package/resolveip/description + This package contains the small resolveip utility which + can be used by scripts to turn host names into numeric + IP addresses. It supports IPv4 and IPv6 resolving and + has a configurable timeout to guarantee a certain maximum + runtime in case of slow or defunct DNS servers. +endef + +define Build/Prepare + $(INSTALL_DIR) $(PKG_BUILD_DIR) + $(INSTALL_DATA) ./src/resolveip.c $(PKG_BUILD_DIR)/ +endef + +define Build/Compile + $(TARGET_CC) $(TARGET_CFLAGS) -Wall \ + -o $(PKG_BUILD_DIR)/resolveip $(PKG_BUILD_DIR)/resolveip.c +endef + +define Package/resolveip/install + $(INSTALL_DIR) $(1)/usr/bin + $(INSTALL_BIN) $(PKG_BUILD_DIR)/resolveip $(1)/usr/bin/ +endef + +$(eval $(call BuildPackage,resolveip)) diff --git a/package/network/utils/resolveip/Makefile b/package/network/utils/resolveip/Makefile new file mode 100644 index 0000000..d1e675e --- /dev/null +++ b/package/network/utils/resolveip/Makefile @@ -0,0 +1,45 @@ +# +# Copyright (C) 2011-2012 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=resolveip +PKG_RELEASE:=2 + +include $(INCLUDE_DIR)/package.mk + +define Package/resolveip + SECTION:=utils + CATEGORY:=Base system + TITLE:=Simple DNS resolver with configurable timeout + MAINTAINER:=Jo-Philipp Wich <jow@openwrt.org> +endef + +define Package/resolveip/description + This package contains the small resolveip utility which + can be used by scripts to turn host names into numeric + IP addresses. It supports IPv4 and IPv6 resolving and + has a configurable timeout to guarantee a certain maximum + runtime in case of slow or defunct DNS servers. +endef + +define Build/Prepare + $(INSTALL_DIR) $(PKG_BUILD_DIR) + $(INSTALL_DATA) ./src/resolveip.c $(PKG_BUILD_DIR)/ +endef + +define Build/Compile + $(TARGET_CC) $(TARGET_CFLAGS) -Wall \ + -o $(PKG_BUILD_DIR)/resolveip $(PKG_BUILD_DIR)/resolveip.c +endef + +define Package/resolveip/install + $(INSTALL_DIR) $(1)/usr/bin + $(INSTALL_BIN) $(PKG_BUILD_DIR)/resolveip $(1)/usr/bin/ +endef + +$(eval $(call BuildPackage,resolveip)) diff --git a/package/network/utils/resolveip/src/.svn/entries b/package/network/utils/resolveip/src/.svn/entries new file mode 100644 index 0000000..0bc2478 --- /dev/null +++ b/package/network/utils/resolveip/src/.svn/entries @@ -0,0 +1,62 @@ +10 + +dir +36060 +svn://svn.openwrt.org/openwrt/trunk/package/network/utils/resolveip/src +svn://svn.openwrt.org/openwrt + + + +2012-11-08T10:48:08.097938Z +34116 +jow + + + + + + + + + + + + + + +3c298f89-4303-0410-b956-a3cf2f4a3e73 + +resolveip.c +file + + + + +2013-03-17T12:13:17.000000Z +202783d173f5dd5f020df23e8a5c41c2 +2012-11-08T10:48:08.097938Z +34116 +jow + + + + + + + + + + + + + + + + + + + + + +1885 + diff --git a/package/network/utils/resolveip/src/.svn/text-base/resolveip.c.svn-base b/package/network/utils/resolveip/src/.svn/text-base/resolveip.c.svn-base new file mode 100644 index 0000000..43c5ae7 --- /dev/null +++ b/package/network/utils/resolveip/src/.svn/text-base/resolveip.c.svn-base @@ -0,0 +1,98 @@ +/* + * Based on code found at https://dev.openwrt.org/ticket/4876 . + * Extended by Jo-Philipp Wich <jow@openwrt.org> for use in OpenWrt. + * + * You may use this program under the terms of the GPLv2 license. + */ + +#include <string.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netdb.h> +#include <arpa/inet.h> +#include <netinet/in.h> +#include <stdlib.h> +#include <unistd.h> +#include <signal.h> + + +static void abort_query(int sig) +{ + exit(1); +} + +static void show_usage(void) +{ + printf("Usage:\n"); + printf(" resolveip -h\n"); + printf(" resolveip [-t timeout] hostname\n"); + printf(" resolveip -4 [-t timeout] hostname\n"); + printf(" resolveip -6 [-t timeout] hostname\n"); + exit(255); +} + +int main(int argc, char **argv) +{ + int timeout = 3; + int opt; + char ipaddr[INET6_ADDRSTRLEN]; + void *addr; + struct addrinfo *res, *rp; + struct sigaction sa = { .sa_handler = &abort_query }; + struct addrinfo hints = { + .ai_family = AF_UNSPEC, + .ai_socktype = SOCK_STREAM, + .ai_protocol = IPPROTO_TCP, + .ai_flags = 0 + }; + + while ((opt = getopt(argc, argv, "46t:h")) > -1) + { + switch ((char)opt) + { + case '4': + hints.ai_family = AF_INET; + break; + + case '6': + hints.ai_family = AF_INET6; + break; + + case 't': + timeout = atoi(optarg); + if (timeout <= 0) + show_usage(); + break; + + case 'h': + show_usage(); + break; + } + } + + if (!argv[optind]) + show_usage(); + + sigaction(SIGALRM, &sa, NULL); + alarm(timeout); + + if (getaddrinfo(argv[optind], NULL, &hints, &res)) + exit(2); + + for (rp = res; rp != NULL; rp = rp->ai_next) + { + addr = (rp->ai_family == AF_INET) + ? (void *)&((struct sockaddr_in *)rp->ai_addr)->sin_addr + : (void *)&((struct sockaddr_in6 *)rp->ai_addr)->sin6_addr + ; + + if (!inet_ntop(rp->ai_family, addr, ipaddr, INET6_ADDRSTRLEN - 1)) + exit(3); + + printf("%s\n", ipaddr); + } + + freeaddrinfo(res); + exit(0); +} diff --git a/package/network/utils/resolveip/src/resolveip.c b/package/network/utils/resolveip/src/resolveip.c new file mode 100644 index 0000000..43c5ae7 --- /dev/null +++ b/package/network/utils/resolveip/src/resolveip.c @@ -0,0 +1,98 @@ +/* + * Based on code found at https://dev.openwrt.org/ticket/4876 . + * Extended by Jo-Philipp Wich <jow@openwrt.org> for use in OpenWrt. + * + * You may use this program under the terms of the GPLv2 license. + */ + +#include <string.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netdb.h> +#include <arpa/inet.h> +#include <netinet/in.h> +#include <stdlib.h> +#include <unistd.h> +#include <signal.h> + + +static void abort_query(int sig) +{ + exit(1); +} + +static void show_usage(void) +{ + printf("Usage:\n"); + printf(" resolveip -h\n"); + printf(" resolveip [-t timeout] hostname\n"); + printf(" resolveip -4 [-t timeout] hostname\n"); + printf(" resolveip -6 [-t timeout] hostname\n"); + exit(255); +} + +int main(int argc, char **argv) +{ + int timeout = 3; + int opt; + char ipaddr[INET6_ADDRSTRLEN]; + void *addr; + struct addrinfo *res, *rp; + struct sigaction sa = { .sa_handler = &abort_query }; + struct addrinfo hints = { + .ai_family = AF_UNSPEC, + .ai_socktype = SOCK_STREAM, + .ai_protocol = IPPROTO_TCP, + .ai_flags = 0 + }; + + while ((opt = getopt(argc, argv, "46t:h")) > -1) + { + switch ((char)opt) + { + case '4': + hints.ai_family = AF_INET; + break; + + case '6': + hints.ai_family = AF_INET6; + break; + + case 't': + timeout = atoi(optarg); + if (timeout <= 0) + show_usage(); + break; + + case 'h': + show_usage(); + break; + } + } + + if (!argv[optind]) + show_usage(); + + sigaction(SIGALRM, &sa, NULL); + alarm(timeout); + + if (getaddrinfo(argv[optind], NULL, &hints, &res)) + exit(2); + + for (rp = res; rp != NULL; rp = rp->ai_next) + { + addr = (rp->ai_family == AF_INET) + ? (void *)&((struct sockaddr_in *)rp->ai_addr)->sin_addr + : (void *)&((struct sockaddr_in6 *)rp->ai_addr)->sin6_addr + ; + + if (!inet_ntop(rp->ai_family, addr, ipaddr, INET6_ADDRSTRLEN - 1)) + exit(3); + + printf("%s\n", ipaddr); + } + + freeaddrinfo(res); + exit(0); +} |