summaryrefslogtreecommitdiff
path: root/libc/inet
diff options
context:
space:
mode:
authorjoseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d>2008-12-10 16:39:54 +0000
committerjoseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d>2008-12-10 16:39:54 +0000
commit0f1e140e796f55cf5f07d39707f3e88d335f4ff1 (patch)
treee44d49e4cb8da17389d4ffa57e784f7ee91d3381 /libc/inet
parent8acd6170c246b159d26f05d85fa256746391d3d7 (diff)
Merge changes between r7357 and r7510 from /fsf/trunk.
git-svn-id: svn://svn.eglibc.org/trunk@7511 7b3dc134-2b1b-0410-93df-9e9f96275f8d
Diffstat (limited to 'libc/inet')
-rw-r--r--libc/inet/Makefile3
-rw-r--r--libc/inet/getnameinfo.c3
-rw-r--r--libc/inet/tst-getni1.c36
-rw-r--r--libc/inet/tst-getni2.c41
4 files changed, 82 insertions, 1 deletions
diff --git a/libc/inet/Makefile b/libc/inet/Makefile
index 0cc89c94c..6f68e4b61 100644
--- a/libc/inet/Makefile
+++ b/libc/inet/Makefile
@@ -59,7 +59,8 @@ routines-$(OPTION_EGLIBC_ADVANCED_INET6) \
aux-$(OPTION_EGLIBC_INET) += check_pf check_native ifreq
tests := htontest test_ifindex tst-ntoa tst-ether_aton tst-network \
- tst-gethnm test-ifaddrs bug-if1 tst-ether_line
+ tst-gethnm test-ifaddrs bug-if1 tst-ether_line \
+ tst-getni1 tst-getni2
tests-$(OPTION_EGLIBC_ADVANCED_INET6) += test-inet6_opt
include ../Rules
diff --git a/libc/inet/getnameinfo.c b/libc/inet/getnameinfo.c
index 50240383f..db6b5c7ee 100644
--- a/libc/inet/getnameinfo.c
+++ b/libc/inet/getnameinfo.c
@@ -178,6 +178,9 @@ getnameinfo (const struct sockaddr *sa, socklen_t addrlen, char *host,
if (sa == NULL || addrlen < sizeof (sa_family_t))
return EAI_FAMILY;
+ if ((flags & NI_NAMEREQD) && host == NULL && serv == NULL)
+ return EAI_NONAME;
+
switch (sa->sa_family)
{
case AF_LOCAL:
diff --git a/libc/inet/tst-getni1.c b/libc/inet/tst-getni1.c
new file mode 100644
index 000000000..0e8a792f4
--- /dev/null
+++ b/libc/inet/tst-getni1.c
@@ -0,0 +1,36 @@
+#include <netdb.h>
+#include <stdio.h>
+#include <sys/socket.h>
+
+static int
+do_test (void)
+{
+ int retval = 0;
+
+ struct sockaddr_in s;
+ s.sin_family = AF_INET;
+ s.sin_port = 80;
+ s.sin_addr.s_addr = INADDR_LOOPBACK;
+ int r = getnameinfo((struct sockaddr *) &s, sizeof (s), NULL, 0, NULL, 0,
+ NI_NUMERICHOST | NI_NUMERICSERV);
+ printf("r = %d\n", r);
+ if (r != 0)
+ {
+ puts ("failed without NI_NAMEREQD");
+ retval = 1;
+ }
+
+ r = getnameinfo((struct sockaddr *) &s, sizeof (s), NULL, 0, NULL, 0,
+ NI_NUMERICHOST | NI_NUMERICSERV | NI_NAMEREQD);
+ printf("r = %d\n", r);
+ if (r != EAI_NONAME)
+ {
+ puts ("did not fail with EAI_NONAME with NI_NAMEREQD set");
+ retval = 1;
+ }
+
+ return retval;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/inet/tst-getni2.c b/libc/inet/tst-getni2.c
new file mode 100644
index 000000000..b949d888d
--- /dev/null
+++ b/libc/inet/tst-getni2.c
@@ -0,0 +1,41 @@
+#include <netdb.h>
+#include <stdio.h>
+#include <sys/socket.h>
+
+static int
+do_test (void)
+{
+ int retval = 0;
+
+ struct sockaddr_in6 s;
+ s.sin6_family = AF_INET6;
+ s.sin6_port = htons (80);
+ s.sin6_flowinfo = 0;
+ s.sin6_addr = (struct in6_addr) IN6ADDR_ANY_INIT;
+ s.sin6_scope_id = 0;
+ char buf[1000];
+ buf[0] = '\0';
+ int r = getnameinfo((struct sockaddr *) &s, sizeof (s), buf, sizeof (buf),
+ NULL, 0, NI_NUMERICSERV);
+ printf("r = %d, buf = \"%s\"\n", r, buf);
+ if (r != 0)
+ {
+ puts ("failed without NI_NAMEREQD");
+ retval = 1;
+ }
+
+ buf[0] = '\0';
+ r = getnameinfo((struct sockaddr *) &s, sizeof (s), buf, sizeof (buf),
+ NULL, 0, NI_NUMERICSERV | NI_NAMEREQD);
+ printf("r = %d, buf = \"%s\"\n", r, buf);
+ if (r != EAI_NONAME)
+ {
+ puts ("did not fail with EAI_NONAME with NI_NAMEREQD set");
+ retval = 1;
+ }
+
+ return retval;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"