How should I print server address

Use inet_ntop() to convert it to a string

This function converts the network address structure src in the af address family into a character string. The resulting string is copied to the buffer pointed to by dst, which must be a non-null pointer. The caller specifies the number of bytes available in this buffer in the argument size.

inet_ntop() extends the inet_ntoa(3) function to support multiple address families, inet_ntoa(3) is now considered to be deprecated in favor of inet_ntop().


That worked for me:

struct sockaddr_in sa;
char buffer[INET_ADDRSTRLEN];
inet_ntop( AF_INET, &sa.sin_addr, buffer, sizeof( buffer ));
printf( "address:%s\n", buffer );

AF_INET is used to denote that the sin_addr points to an IPv4 network address. The resulting string is copied to the buffer variable. You should specify the number of bytes available in the buffer in the last argument of inet_ntop().