Back to index

webcit  8.12-dfsg
locate_host.c
Go to the documentation of this file.
00001 /*
00002  * Given a socket, supply the name of the host at the other end.
00003  *
00004  * Copyright (c) 1996-2012 by the citadel.org team
00005  *
00006  * This program is open source software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License, version 3.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  */
00014 
00015 #include "webcit.h"
00016 #include "webserver.h"
00017 
00018 /*
00019  * IPv4/IPv6 locate_host()
00020  */
00021 void locate_host(StrBuf *tbuf, int client_socket)
00022 {
00023        struct sockaddr_in6 clientaddr;
00024        unsigned int addrlen = sizeof(clientaddr);
00025        char clienthost[NI_MAXHOST] = "";
00026 
00027        getpeername(client_socket, (struct sockaddr *)&clientaddr, &addrlen);
00028        getnameinfo((struct sockaddr *)&clientaddr, addrlen, clienthost, sizeof(clienthost), NULL, 0, 0);
00029         StrBufAppendBufPlain(tbuf, clienthost, -1, 0);
00030        syslog(9, "Client is at %s\n", clienthost);
00031 }