replace inet_ntoa to inet_ntop
This commit is contained in:
		
							parent
							
								
									3e4a5ac1db
								
							
						
					
					
						commit
						9b991b13b2
					
				
					 1 changed files with 3 additions and 2 deletions
				
			
		
							
								
								
									
										5
									
								
								server.c
									
										
									
									
									
								
							
							
						
						
									
										5
									
								
								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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue