4 * Given a socket, supply the name of the host at the other end.
6 * Copyright (c) 1996-2010 by the citadel.org team
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 void locate_host(StrBuf *tbuf, int client_socket)
30 struct sockaddr_in6 clientaddr;
31 unsigned int addrlen = sizeof(clientaddr);
32 char clienthost[NI_MAXHOST];
33 char clientservice[NI_MAXSERV];
35 getpeername(client_socket, (struct sockaddr *)&clientaddr, &addrlen);
36 getnameinfo((struct sockaddr *)&clientaddr, addrlen,
37 clienthost, sizeof(clienthost),
38 clientservice, sizeof(clientservice),
42 StrBufAppendBufPlain(tbuf, clienthost, -1, 0);
47 void locate_host(StrBuf *tbuf, int client_socket)
49 struct sockaddr_in cs;
56 if (getpeername(client_socket, (struct sockaddr *) &cs, &len) < 0) {
57 StrBufAppendBufPlain(tbuf, HKEY("<unknown>"), 0);
60 if ((ch = gethostbyaddr((char *) &cs.sin_addr, sizeof(cs.sin_addr),
62 i = (char *) &cs.sin_addr;
67 StrBufPrintf(tbuf, "%d.%d.%d.%d", a1, a2, a3, a4);
70 StrBufAppendBufPlain(tbuf, ch->h_name, -1, 0);
73 #endif /* CTDL_IPV6 */