aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/gethostbyname.c
diff options
context:
space:
mode:
authorEpoch Qwert <epoch@53flpnlls43fcguy.onion>2014-12-30 07:25:39 -0600
committerEpoch Qwert <epoch@53flpnlls43fcguy.onion>2014-12-30 07:25:39 -0600
commit86ba931697790d4da2515f4457ebfb3f20b43860 (patch)
tree839c1f7ae94fd32639d3311c3a2faee34f88f04c /src/bin/gethostbyname.c
parent05d677a3d3e9e540dffd35c76e35335bf43ead7d (diff)
downloadmisc-86ba931697790d4da2515f4457ebfb3f20b43860.tar.gz
misc-86ba931697790d4da2515f4457ebfb3f20b43860.zip
all those .c changes were mostly fixes of warnings for the change in rebuild.sh being changed to use -Wall.
gethostbyname was almost completely rewritten to work better with ipv6 for gopherd.sh gopherd.sh was rewritten to use gethostbyname instead of dig and to cut out any link-local interface indicators from the output of hop0 and to ignore an error if ipA -> hostname -> ipB causes ipA to be not the same as ipB. Don't remember if there's anything else.
Diffstat (limited to 'src/bin/gethostbyname.c')
-rw-r--r--src/bin/gethostbyname.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/bin/gethostbyname.c b/src/bin/gethostbyname.c
index b670b1e..a63f540 100644
--- a/src/bin/gethostbyname.c
+++ b/src/bin/gethostbyname.c
@@ -2,23 +2,25 @@
#include <netdb.h>
#include <arpa/inet.h>
+#define SILLYLIMIT 256
+
int main(int argc,char *argv[]) {
- int i;
- if(argc < 2) return 1;
- char *addr;
+ char buf[SILLYLIMIT];
struct in_addr saddr;
- if(inet_aton(argv[1],&saddr))
- addr=inet_ntoa(saddr);
- else
- addr=argv[1];
- struct hostent *he=gethostbyname(addr);
-
- for(i=0;he->h_addr_list[i];i++) {
- printf("%u.%u.%u.%u\n",
- (unsigned char)he->h_addr_list[i][0],
- (unsigned char)he->h_addr_list[i][1],
- (unsigned char)he->h_addr_list[i][2],
- (unsigned char)he->h_addr_list[i][3]);
+ struct in6_addr saddr6;
+ struct hostent *he;
+ if(argc<2) return 1;
+ if(!(he=gethostbyname2(
+ argc<3
+ ?inet_aton(argv[1],&saddr)
+ ?inet_ntoa(saddr)
+ :argv[1]
+ :inet_pton(AF_INET6,argv[1],&saddr6)
+ ?inet_ntop(AF_INET6,&saddr6,buf,SILLYLIMIT) //no point, but whatever
+ :argv[1]
+ ,argc<3?AF_INET:AF_INET6))) return 1;
+ for(;*(he->h_addr_list);he->h_addr_list++) {
+ printf("%s\n",inet_ntop(argc<3?AF_INET:AF_INET6,*(he->h_addr_list),buf,SILLYLIMIT));
}
return 0;
}