From 9b991b13b2e92f0b81fb4771ea185d1d20e99485 Mon Sep 17 00:00:00 2001 From: ubuntu201711081 <201711081@jbnu.ac.kr> Date: Fri, 4 Dec 2020 07:23:13 +0000 Subject: [PATCH] replace inet_ntoa to inet_ntop --- server.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server.c b/server.c index 474de73..21b990e 100644 --- a/server.c +++ b/server.c @@ -198,8 +198,9 @@ int main(int argc, const char *argv[]){ while ((csock = accept(sock, (struct sockaddr *)&client_addr,&client_addr_len)) >= 0) { int fd; - /*inet_ntoa is not reentrant function. do not use it in signal handler.*/ - printf("Connect : %s\n",(inet_ntoa(client_addr.sin_addr))); + char ip_buf[INET_ADDRSTRLEN]; + char * msg = inet_ntop(AF_INET,&addr.sin_addr,ip_buf,sizeof(ip_buf)); + fprintf(stderr,"Connected on : %s:%d\n",msg == NULL ? "(null)" : msg , ntohs(addr.sin_port)); if((fd = read_request(csock,buf,bufsize)) > 0){ send_response(csock,fd,buf,bufsize); close(fd);