diff options
author | Gwenolé Beauchesne <gbeauchesne@mandriva.org> | 2003-06-04 18:44:09 +0000 |
---|---|---|
committer | Gwenolé Beauchesne <gbeauchesne@mandriva.org> | 2003-06-04 18:44:09 +0000 |
commit | 4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b (patch) | |
tree | acd4001a266a8713495af7f1b2102b61e67113b0 /mdk-stage1/dietlibc/libugly/getnameinfo.c | |
parent | 71b111ec6c4671667a19c6fbe0023d33422535d7 (diff) | |
download | drakx-4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b.tar drakx-4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b.tar.gz drakx-4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b.tar.bz2 drakx-4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b.tar.xz drakx-4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b.zip |
Import dietlibc 0.22 + other fixes for AMD64
Diffstat (limited to 'mdk-stage1/dietlibc/libugly/getnameinfo.c')
-rw-r--r-- | mdk-stage1/dietlibc/libugly/getnameinfo.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/mdk-stage1/dietlibc/libugly/getnameinfo.c b/mdk-stage1/dietlibc/libugly/getnameinfo.c new file mode 100644 index 000000000..40883ba09 --- /dev/null +++ b/mdk-stage1/dietlibc/libugly/getnameinfo.c @@ -0,0 +1,46 @@ +#include <sys/socket.h> +#include <netinet/in.h> +#include <netdb.h> +#include <arpa/inet.h> +#include <string.h> + +extern int __ltostr(char *s, int size, unsigned long i, int base, char UpCase); + +int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, + size_t hostlen, char *serv, size_t servlen, int flags) { + sa_family_t f=((struct sockaddr_storage *)sa)->ss_family; + (void)salen; /* shut gcc up about unused salen */ + if (host && hostlen>0) { /* user wants me to resolve the host name */ + register const char*addr=(f==AF_INET6)?(char*)&((struct sockaddr_in6*)sa)->sin6_addr: + (char*)&((struct sockaddr_in*)sa)->sin_addr; + if (flags&NI_NUMERICHOST) { + if (!inet_ntop(f,addr,host,hostlen)) + return EAI_NONAME; + } else { + char buf[4096]; + struct hostent h; + struct hostent *H; + int herrno; + if (gethostbyaddr_r(addr,f==AF_INET6?16:4,f,&h,buf,4096,&H,&herrno)) { + switch (herrno) { + case TRY_AGAIN: return EAI_AGAIN; + case NO_DATA: + case HOST_NOT_FOUND: return EAI_NONAME; + } + } + strncpy(host,h.h_name,hostlen-1); + host[hostlen-1]=0; + } + } + if (serv && servlen>0) { + register short int port=(f==AF_INET6)?((struct sockaddr_in6*)sa)->sin6_port:((struct sockaddr_in*)sa)->sin_port; + if (flags&NI_NUMERICSERV) { + __ltostr(serv,servlen,ntohs(port),10,0); + } else { + struct servent *s; + if (!(s=getservbyport(port,flags&NI_DGRAM?"udp":"tcp"))) + return EAI_SERVICE; + } + } + return 0; +} |