From d797b2cf497587355bbf25cd27d59edd1c3f2915 Mon Sep 17 00:00:00 2001 From: Nicola Ruggero Date: Thu, 4 Nov 2010 12:14:03 +0100 Subject: Implemented client IP logging --- common/os_calls.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'common/os_calls.c') diff --git a/common/os_calls.c b/common/os_calls.c index 617f3d60..4004fdfc 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -492,6 +492,35 @@ g_tcp_accept(int sck) return accept(sck, (struct sockaddr*)&s, &i); } +/*****************************************************************************/ +void APP_CC +g_write_ip_address(int rcv_sck, char* ip_address) +{ + struct sockaddr_in s; + struct in_addr in; + int len; + int ip_port; + + memset(&s,0,sizeof(&s)); + len = sizeof(s); + getpeername(rcv_sck,(struct sockaddr*)&s, &len); + + memset(&in,0,sizeof(in)); + in.s_addr = s.sin_addr.s_addr; + + ip_port = ntohs(s.sin_port); + + if (ip_port != 0) + { + sprintf(ip_address, "%s:%d - socket: %d", inet_ntoa(in), ip_port, rcv_sck); + } + else + { + sprintf(ip_address, "NULL:NULL - socket: %d", rcv_sck); + } + +} + /*****************************************************************************/ void APP_CC g_sleep(int msecs) -- cgit v1.2.3