Sourceware Bugzilla – Attachment 2128 Details for
Bug 5460
glibc-2.6+ returns too many results from /etc/hosts in some cases
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
getaddrinfo.c test case
getaddrinfo.c (text/plain), 1.57 KB, created by
Mike Frysinger
on 2007-12-09 04:36:15 UTC
(
hide
)
Description:
getaddrinfo.c test case
Filename:
MIME Type:
Creator:
Mike Frysinger
Created:
2007-12-09 04:36:15 UTC
Size:
1.57 KB
patch
obsolete
>#define _GNU_SOURCE >#include <netdb.h> >#include <stdio.h> >#include <stdlib.h> >#include <string.h> >#include <arpa/inet.h> >#include <netinet/in.h> >#include <sys/socket.h> >#include <sys/types.h> > >void doit(const char *name, const char *family_name, int family) >{ > printf("--- looking up '%s' for family %s (%i)\n", name, family_name, family); > > struct addrinfo hints; > memset(&hints, 0, sizeof(hints)); > hints.ai_socktype = SOCK_STREAM; > hints.ai_flags = AI_NUMERICHOST; > hints.ai_family = family; > > struct addrinfo *hostaddr = 0; > int res = getaddrinfo(name, "telnet", &hints, &hostaddr); > if (res == EAI_NONAME) { > printf("getaddrinfo(...) = EAI_NONAME, trying again with AI_CANONNAME\n"); > hints.ai_flags = AI_CANONNAME; > res = getaddrinfo(name, "telnet", &hints, &hostaddr); > } > if (res == EAI_NONAME) { > printf("getaddrinfo(...) = EAI_NONAME ... FAIL\n"); > } else if (res) { > printf("getaddrinfo(...) = %i ... FAIL\n", res); > } else { > printf("getaddrinfo(...) = %i\n", res); > > while (hostaddr) { > char name[1024], service[1024]; > res = getnameinfo(hostaddr->ai_addr, hostaddr->ai_addrlen, > name, sizeof(name), service, sizeof(service), > NI_NUMERICHOST | NI_NUMERICSERV); > printf("getnameinfo(...) = %i\n", res); > printf("\tname = %s\n", name); > printf("\tservice = %s\n", service); > hostaddr = hostaddr->ai_next; > } > } > > freeaddrinfo(hostaddr); >} > >int main(int argc, char *argv[]) >{ > const char *name = (argc > 1 ? argv[1] : "localhost"); > >#define doit(name, family) doit(name, #family, family) > doit(name, 0); > doit(name, AF_INET); > doit(name, AF_INET6); > > puts(""); > > return 0; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 5460
: 2128