#include #include #include #include #include "parseInetAddr.h" void parse_inet_address(struct sockaddr_in *inet_ad, char *buff, int bsize) { struct hostent *hp; char *cname, bigbuff[1024] ; int cport, wrsz ; hp = gethostbyaddr((char *)&inet_ad->sin_addr, sizeof(struct in_addr), AF_INET) ; if (hp == (struct hostent *)NULL) cname = inet_ntoa(inet_ad->sin_addr) ; else cname = hp->h_name ; cport = ntohs(inet_ad->sin_port) ; wrsz = sprintf(bigbuff, "%s (%d)", cname, cport) ; if (wrsz <= 0) buff[0] = '\0' ; else if (wrsz < bsize) (void) memcpy(buff, bigbuff, wrsz+1) ; else { (void) memcpy(buff, bigbuff, bsize-1) ; buff[bsize] = '\0' ; } }