Skip to content
This repository has been archived by the owner on Nov 29, 2020. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
paldier committed May 4, 2019
1 parent cbb6f5a commit b394b2f
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 1 deletion.
1 change: 1 addition & 0 deletions release/src/router/rc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ endif
@cd $(INSTALLDIR)/sbin && ln -sf rc reboot
@cd $(INSTALLDIR)/sbin && ln -sf rc halt
@cd $(INSTALLDIR)/sbin && ln -sf rc netool
@cd $(INSTALLDIR)/sbin && ln -sf rc ddns_custom_updated
ifeq ($(HND_ROUTER),y)
@cd $(INSTALLDIR)/sbin && ln -sf rc hnd-write
@cd $(INSTALLDIR)/sbin && ln -sf rc hnd-erase
Expand Down
1 change: 1 addition & 0 deletions release/src/router/rc/rc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,7 @@ extern void start_DSLsenddiagmail(void);
extern void start_snmpd(void);
extern void stop_snmpd(void);
#endif
int ddns_custom_updated_main(int argc, char *argv[]);
#ifdef RTCONFIG_TIMEMACHINE
extern int start_timemachine(void);
extern void stop_timemachine(void);
Expand Down
4 changes: 3 additions & 1 deletion release/src/router/softcenter/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
include ../common.mak

all: versioncmp base64_encode
all: versioncmp base64_encode resolvip

versioncmp:
$(CC) versioncmp.c -o versioncmp
base64_encode:
$(CC) base64.c -o base64_encode
resolvip:
$(CC) resolvip.c -o resolvip
install:
install -d $(INSTALLDIR)/sbin
install -d $(INSTALLDIR)/usr/sbin
Expand Down
98 changes: 98 additions & 0 deletions release/src/router/softcenter/resolvip.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Based on code found at https://dev.openwrt.org/ticket/4876 .
* Extended by Jo-Philipp Wich <[email protected]> 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);
}

0 comments on commit b394b2f

Please sign in to comment.