src/standard.c
int addr_to_str(struct sockaddr_storage *addr, char *str, int size)
{

	void *ptr;

	if (size < 5)
		return 0;
	*str = '\0';

	switch (addr->ss_family) {
	case AF_INET:
		ptr = &((struct sockaddr_in *)addr)->sin_addr;
		break;
	case AF_INET6:
		ptr = &((struct sockaddr_in6 *)addr)->sin6_addr;
		break;
	case AF_UNIX:
		memcpy(str, "unix", 5);
		return addr->ss_family;
	default:
		return 0;
	}

	if (inet_ntop(addr->ss_family, ptr, str, size))
		return addr->ss_family;

	/* failed */
	return -1;
}
/* Tries to convert a sockaddr_storage address to text form. Upon success, the
 * address family is returned so that it's easy for the caller to adapt to the
 * output format. Zero is returned if the address family is not supported. -1
 * is returned upon error, with errno set. AF_INET, AF_INET6 and AF_UNIX are
 * supported.
 */
Tries to convert a sockaddr_storage address to text form. Upon success, the
address family is returned so that it's easy for the caller to adapt to the
output format. Zero is returned if the address family is not supported. -1
is returned upon error, with errno set.
Tries to convert a sockaddr_storage address to text form . Upon success the address family is returned so that it ' s easy for the caller to adapt to the output format . Zero is returned if the address family is not supported . - 1 is returned upon error with errno set .
int addr_to_str(struct sockaddr_storage *addr, char *str, int size)
{
	void *ptr;
	if (size < 5)
		return 0;
	*str = '\0';
	switch (addr->ss_family) {
	case AF_INET:
		ptr = &((struct sockaddr_in *)addr)->sin_addr;
		break;
	case AF_INET6:
		ptr = &((struct sockaddr_in6 *)addr)->sin6_addr;
		break;
	case AF_UNIX:
		memcpy(str, "unix", 5);
		return addr->ss_family;
	default:
		return 0;
	}
	if (inet_ntop(addr->ss_family, ptr, str, size))
		return addr->ss_family;
	return -1;
}
int addr_to_str ( struct sockaddr_storage * addr , char * str , int size ) { void * ptr ; if ( size < 5 ) return 0 ; * str = ' \0 ' ; switch ( addr -> ss_family ) { case AF_INET : ptr = & ( ( struct sockaddr_in * ) addr ) -> sin_addr ; break ; case AF_INET6 : ptr = & ( ( struct sockaddr_in6 * ) addr ) -> sin6_addr ; break ; case AF_UNIX : memcpy ( str , " " , 5 ) ; return addr -> ss_family ; default : return 0 ; } if ( inet_ntop ( addr -> ss_family , ptr , str , size ) ) return addr -> ss_family ; return -1 ; }
Tries to convert a sockaddr_storage address to text form.
Tries to convert a sockaddr_storage address to text form .
/* failed */