コード例 #1
0
struct sockaddr *
transport_listen
(
	TransportProtocol protocol,
	OWSLAddressFamily address_family,
	unsigned short bind_port,
	int pending_max
)
{
	struct sockaddr * bound_address = NULL ;
	struct sockaddr * address ;
	char * ip = OWSL_LOCAL_ADDRESS ;
	char public_ip [OWSL_IP_MAX_SIZE] ;
	if (owsl_address_public_ip_get (address_family, public_ip, sizeof (public_ip)) == 0)
	{
		ip = public_ip ;
	}
	address = owsl_address_ip_port_new (address_family, ip, bind_port) ;
	if (address != NULL)
	{
		bound_address = transport_address_listen (protocol, address, /*OWSL_ADDRESS_SIZE*/sizeof(struct sockaddr), 0, pending_max) ;
		free (address) ;
	}
	return bound_address ;
}
コード例 #2
0
NETLIB_BOOLEAN
udp_sip_ping
(
	const char * sip_server,
	unsigned short sip_port,
	unsigned short local_port,
	int ping_timeout,
	const char * sip_address,
	const char * sip_realm
)
{
	int return_code ;
	OWSLSocket udp_socket ;
	struct sockaddr * local_address ;
	struct sockaddr * remote_address ;
	char * ip = OWSL_LOCAL_ADDRESS ;
	char public_ip [OWSL_IP_MAX_SIZE] ;
	if (owsl_address_public_ip_get (OWSL_AF_IPV4, public_ip, sizeof (public_ip)) == 0)
	{
		ip = public_ip ;
	}

	/* TODO: IPv6 support in netlib */
	udp_socket = owsl_socket_by_type (OWSL_TYPE_IPV4_UDP) ;
	if (udp_socket <= 0)
	{
		return NETLIB_FALSE ;
	}

	return_code = owsl_reuse_set (udp_socket) ;
	if (return_code != 0)
	{
		owsl_close (udp_socket) ;
		return NETLIB_FALSE ;
	}

	/* TODO: IPv6 support in netlib */
	local_address = owsl_address_ip_port_new (OWSL_AF_IPV4, ip, local_port) ;
	if (local_address == NULL)
	{
		owsl_close (udp_socket) ;
		return NETLIB_FALSE ;
	}

	return_code = owsl_bind (udp_socket, local_address, /*OWSL_ADDRESS_SIZE*/sizeof(struct sockaddr)) ;
	free (local_address) ;
	if (return_code != 0)
	{
		owsl_close (udp_socket) ;
		return NETLIB_FALSE ;
	}

	/* TODO: IPv6 support in netlib */
	remote_address = owsl_address_port_new (OWSL_AF_IPV4, sip_server, sip_port) ;
	if (remote_address == NULL)
	{
		owsl_close (udp_socket) ;
		return NETLIB_FALSE ;
	}

	return_code = owsl_connect (udp_socket, remote_address, /*OWSL_ADDRESS_SIZE*/sizeof(struct sockaddr)) ;
	free (remote_address) ;
	if (return_code != 0)
	{
		NETLIB_LOG_ERROR (make_error_string ("udp_sip_ping : connect")) ;
		owsl_close (udp_socket) ;
		return NETLIB_FALSE ;
	}

	return_code = sip_ping (udp_socket, ping_timeout, sip_address, sip_realm) ;

	owsl_close (udp_socket) ;

	return return_code == 0 ? NETLIB_TRUE : NETLIB_FALSE ;
}