TCP/IP Programming Manual
 /* Obtains the client's name with a call to getnameinfo using the
 address in the sockaddr_storage structure named clientaddr. The
 NI_NAMEREQD flag directs the routine to return a hostname for 
 the given address. */ 
 ni = getnameinfo((struct sockaddr *)&clientaddr,
 clientaddrlen, addrbuf, sizeof(addrbuf), port, sizeof(port),
 NI_NUMERICHOST|NI_NUMERICSERV);
 if (ni == 0)
 printf(" (%s) port %s", addrbuf, port);
 printf(":\n\"%s\"\n", databuf);
 /* Sends a response to the client. */
 if (send(new_s, response, (int)strlen(response), 0) < 0) {
 perror("send");
 FILE_CLOSE_((short)new_s);
 continue;
 }
 FILE_CLOSE_((short)new_s);
 }
 FILE_CLOSE_((short)s);
}
240 Sample Programs










