X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=comstack%2Ftcpip.c;h=4e2ab4f4fc987909b4b8bf5d0525e1cf9bdd4696;hp=3fdb3e240fded8e2b37b424d30df756460299745;hb=29818ed78e32998641adcf5f23d3b854355918b5;hpb=b159db0e380339b4f51ba3871458fcf09bbfdece diff --git a/comstack/tcpip.c b/comstack/tcpip.c index 3fdb3e2..4e2ab4f 100644 --- a/comstack/tcpip.c +++ b/comstack/tcpip.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: tcpip.c,v $ - * Revision 1.6 1995-09-29 17:12:00 quinn + * Revision 1.7 1995-10-30 12:41:16 quinn + * Added hostname lookup for server. + * + * Revision 1.6 1995/09/29 17:12:00 quinn * Smallish * * Revision 1.5 1995/09/29 17:01:48 quinn @@ -111,6 +114,7 @@ int tcpip_rcvconnect(COMSTACK h); int tcpip_bind(COMSTACK h, void *address, int mode); int tcpip_listen(COMSTACK h, char *addrp, int *addrlen); COMSTACK tcpip_accept(COMSTACK h); +char *tcpip_addrstr(COMSTACK h); int completeBER(unsigned char *buf, int len); @@ -187,6 +191,7 @@ COMSTACK tcpip_type(int blocking, int protocol) p->f_bind = tcpip_bind; p->f_listen = tcpip_listen; p->f_accept = tcpip_accept; + p->f_addrstr = tcpip_addrstr; p->state = CS_UNBND; p->event = CS_NONE; @@ -503,3 +508,26 @@ int tcpip_close(COMSTACK h) free(h); return 0; } + +char *tcpip_addrstr(COMSTACK h) +{ + struct sockaddr_in addr; + static char buf[64]; + char *r; + int len; + struct hostent *host; + + len = sizeof(addr); + if (getpeername(h->iofile, (struct sockaddr*) &addr, &len) < 0) + { + h->cerrno = CSYSERR; + return 0; + } + if ((host = gethostbyaddr((char*)&addr.sin_addr, sizeof(addr.sin_addr), + AF_INET))) + r = (char*) host->h_name; + else + r = inet_ntoa(addr.sin_addr); + sprintf(buf, "tcp:%s", r); + return buf; +}