4 * Examine a socket and determine the name/address of the originating host.
14 #include <sys/types.h>
16 #include <sys/socket.h>
19 #include <netinet/in.h>
29 void locate_host(char *tbuf, int client_socket)
31 struct sockaddr_in cs;
38 if (getpeername(client_socket, (struct sockaddr *) &cs, &len) < 0) {
39 strcpy(tbuf, "<unknown>");
42 if ((ch = gethostbyaddr((char *) &cs.sin_addr, sizeof(cs.sin_addr),
44 i = (char *) &cs.sin_addr;
49 sprintf(tbuf, "%d.%d.%d.%d", a1, a2, a3, a4);
52 safestrncpy(tbuf, ch->h_name, 64);