From de6ce224dbda9480f4cbed14f2ce8f5e9f3028a7 Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Fri, 9 Sep 2005 21:30:38 +0000 Subject: mine: * fake-addrinfo-test.c: New file. * Makefile.in (check): Do pass arguments to addrinfo-test invocation added by Marc's patch. (fake-addrinfo-test): New target. (all): Depend on it. (SRCS): Fix typo in last change. Add fake-addrinfo-test.c. (OBJS): Add fake-addrinfo-test.o. from Marc Aurele La France: * Makefile.in: Build addrinfo-test. * addrinfo-test.c (main): 'numeric' -> 'numerichost'; Add -n option to set AI_NUMERICSERV (if available); print usage message when no arguments are given. ticket: 3176 status: open git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@17379 dc483132-0cff-0310-8789-dd5450dbe970 --- src/tests/resolve/ChangeLog | 17 +++++++++++++++++ src/tests/resolve/Makefile.in | 29 ++++++++++++++++++++++------- src/tests/resolve/addrinfo-test.c | 33 ++++++++++++++++++++++++++------- src/tests/resolve/fake-addrinfo-test.c | 2 ++ 4 files changed, 67 insertions(+), 14 deletions(-) create mode 100644 src/tests/resolve/fake-addrinfo-test.c (limited to 'src/tests/resolve') diff --git a/src/tests/resolve/ChangeLog b/src/tests/resolve/ChangeLog index b19b33e238..f84ca064b1 100644 --- a/src/tests/resolve/ChangeLog +++ b/src/tests/resolve/ChangeLog @@ -1,3 +1,20 @@ +2005-09-07 Ken Raeburn + + * fake-addrinfo-test.c: New file. + * Makefile.in (check): Do pass arguments to addrinfo-test + invocation added by Marc's patch. + (fake-addrinfo-test): New target. + (all): Depend on it. + (SRCS): Fix typo in last change. Add fake-addrinfo-test.c. + (OBJS): Add fake-addrinfo-test.o. + +2005-09-01 Marc Aurele La France + + * Makefile.in: Build addrinfo-test. + * addrinfo-test.c (main): 'numeric' -> 'numerichost'; Add -n option + to set AI_NUMERICSERV (if available); print usage message when no + arguments are given. + 2004-08-23 Ken Raeburn * addrinfo-test.c: New file. diff --git a/src/tests/resolve/Makefile.in b/src/tests/resolve/Makefile.in index 712cfa4404..653b587f7c 100644 --- a/src/tests/resolve/Makefile.in +++ b/src/tests/resolve/Makefile.in @@ -6,21 +6,30 @@ RUN_SETUP = @KRB5_RUN_ENV@ PROG_LIBPATH=-L$(TOPLIBD) PROG_RPATH=$(KRB5_LIBDIR) -OBJS=resolve.o -SRCS=$(srcdir)/resolve.c +OBJS=resolve.o addrinfo-test.o fake-addrinfo-test.o +SRCS=$(srcdir)/resolve.c $(srcdir)/addrinfo-test.c \ + $(srcdir)/fake-addrinfo-test.c -all:: resolve +all:: resolve addrinfo-test fake-addrinfo-test -resolve: $(OBJS) - $(CC_LINK) -o resolve $(OBJS) $(LIBS) +resolve: resolve.o + $(CC_LINK) -o $@ $< $(LIBS) -check:: resolve +addrinfo-test: addrinfo-test.o + $(CC_LINK) -o $@ $< $(LIBS) + +fake-addrinfo-test: fake-addrinfo-test.o + $(CC_LINK) -o $@ $< $(SUPPORT_LIB) $(LIBS) + +check:: resolve addrinfo-test $(RUN_SETUP) ./resolve + $(RUN_SETUP) ./addrinfo-test -p telnet + $(RUN_SETUP) ./fake-addrinfo-test -p telnet install:: clean:: - $(RM) resolve + $(RM) resolve addrinfo-test # +++ Dependency line eater +++ # @@ -28,3 +37,9 @@ clean:: # the Makefile.in file # $(OUTPRE)resolve.$(OBJEXT): resolve.c +$(OUTPRE)addrinfo-test.$(OBJEXT): addrinfo-test.c +$(OUTPRE)fake-addrinfo-test.$(OBJEXT): fake-addrinfo-test.c \ + addrinfo-test.c $(SRCTOP)/include/fake-addrinfo.h $(SRCTOP)/include/port-sockets.h \ + $(BUILDTOP)/include/krb5/autoconf.h $(SRCTOP)/include/socket-utils.h \ + $(SRCTOP)/include/k5-platform.h $(BUILDTOP)/include/krb5/autoconf.h \ + $(SRCTOP)/include/k5-thread.h diff --git a/src/tests/resolve/addrinfo-test.c b/src/tests/resolve/addrinfo-test.c index f2bc0c8f34..1aa30602c9 100644 --- a/src/tests/resolve/addrinfo-test.c +++ b/src/tests/resolve/addrinfo-test.c @@ -37,6 +37,7 @@ */ #include +#include #include #include #include @@ -84,7 +85,7 @@ static const char *socktypename (int t) { static char *whoami; -void usage () { +static void usage () { fprintf(stderr, "usage:\n" "\t%s [ options ] [host]\n" @@ -103,6 +104,7 @@ void usage () { "\n" "\t-p P\tspecify port P (service name or port number)\n" "\t-N\thostname is numeric, skip DNS query\n" + "\t-n\tservice/port is numeric (sets AI_NUMERICSERV)\n" "\t-P\tset AI_PASSIVE\n" "\n" "default: protocol 0, socket type 0, address family 0, null port\n" @@ -128,7 +130,7 @@ static const char *familyname (int f) { int main (int argc, char *argv[]) { struct addrinfo *ap, *ap2; - int err, numeric = 0; + int err, numerichost = 0, numericserv = 0; char *hname, *port = 0, *sep; struct addrinfo hints; @@ -145,6 +147,9 @@ int main (int argc, char *argv[]) hname = 0; hints.ai_family = 0; + if (argc == 1) + usage (); + while (++argv, --argc > 0) { char *arg; arg = *argv; @@ -189,7 +194,10 @@ int main (int argc, char *argv[]) hints.ai_family = AF_INET6; break; case 'N': - numeric = 1; + numerichost = 1; + break; + case 'n': + numericserv = 1; break; case 'P': hints.ai_flags |= AI_PASSIVE; @@ -199,9 +207,9 @@ int main (int argc, char *argv[]) } } - if (hname && !numeric) + if (hname && !numerichost) hints.ai_flags |= AI_CANONNAME; - if (numeric) { + if (numerichost) { #ifdef AI_NUMERICHOST hints.ai_flags |= AI_NUMERICHOST; #else @@ -209,6 +217,14 @@ int main (int argc, char *argv[]) exit(1); #endif } + if (numericserv) { +#ifdef AI_NUMERICSERV + hints.ai_flags |= AI_NUMERICSERV; +#else + fprintf(stderr, "AI_NUMERICSERV not defined on this platform\n"); + exit(1); +#endif + } printf("getaddrinfo(hostname %s, service %s,\n" " hints { ", @@ -219,6 +235,9 @@ int main (int argc, char *argv[]) Z(PASSIVE); #ifdef AI_NUMERICHOST Z(NUMERICHOST); +#endif +#ifdef AI_NUMERICSERV + Z(NUMERICSERV); #endif if (sep[0] == 0) printf ("no-flags"); @@ -273,11 +292,11 @@ int main (int argc, char *argv[]) printf("\taddr = %-28s\tport = %s\n", hbuf, pbuf); err = getnameinfo(ap2->ai_addr, ap2->ai_addrlen, hbuf, sizeof (hbuf), - 0, 0, NI_NAMEREQD); + pbuf, sizeof(pbuf), NI_NAMEREQD); if (err) printf("\tgetnameinfo(NI_NAMEREQD): %s\n", eaistr(err)); else - printf("\tgetnameinfo => %s\n", hbuf); + printf("\tgetnameinfo => %s, %s\n", hbuf, pbuf); } return 0; } diff --git a/src/tests/resolve/fake-addrinfo-test.c b/src/tests/resolve/fake-addrinfo-test.c new file mode 100644 index 0000000000..f04024d737 --- /dev/null +++ b/src/tests/resolve/fake-addrinfo-test.c @@ -0,0 +1,2 @@ +#define USE_FAKE_ADDRINFO +#include "addrinfo-test.c" -- cgit