From: jow Date: Sun, 17 Jul 2011 22:21:18 +0000 (+0000) Subject: [backfire] merge r27666 X-Git-Url: http://git.ozo.com/?p=openwrt-10.03%2F.git;a=commitdiff_plain;h=338602fd63cc75f3baea2cf29ba913fc91620e60;ds=sidebyside [backfire] merge r27666 git-svn-id: svn://svn.openwrt.org/openwrt/branches/backfire@27667 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- diff --git a/package/lua/Makefile b/package/lua/Makefile index fdbbddc40..55329cd3c 100644 --- a/package/lua/Makefile +++ b/package/lua/Makefile @@ -86,7 +86,7 @@ endef define Build/Configure endef -TARGET_CFLAGS += -DLUA_USE_LINUX $(FPIC) -std=gnu99 +TARGET_CFLAGS += -DLUA_USE_LINUX $(FPIC) -std=gnu99 -ggdb3 ifneq ($(CONFIG_USE_EGLIBC),) ifeq ($(CONFIG_EGLIBC_OPTION_EGLIBC_UTMP),) diff --git a/package/resolveip/Makefile b/package/resolveip/Makefile new file mode 100644 index 000000000..6ab04e162 --- /dev/null +++ b/package/resolveip/Makefile @@ -0,0 +1,44 @@ +# +# Copyright (C) 2011 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:=1 + +include $(INCLUDE_DIR)/package.mk + +define Package/resolveip + SECTION:=utils + CATEGORY:=Base system + TITLE:=Simple DNS resolver with configurable timeout +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/resolveip/src/resolveip.c b/package/resolveip/src/resolveip.c new file mode 100644 index 000000000..8d6788c9a --- /dev/null +++ b/package/resolveip/src/resolveip.c @@ -0,0 +1,98 @@ +/* + * Based on code found at https://dev.openwrt.org/ticket/4876 . + * Extended by Jo-Philipp Wich for use in OpenWrt. + * + * You may use this program under the terms of the GPLv2 license. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +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; + char 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 (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); +}