replace inet_ntoa to inet_ntop

This commit is contained in:
ubuntu201711081 2020-12-04 07:23:13 +00:00
parent 3e4a5ac1db
commit 9b991b13b2

View File

@ -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);