Пример #1
0
static int can_bind(addr, port)
{
	/* Check to see if this address is not in use already. */
	if (pcb_lookup(INADDR_ANY, 0, addr, port, &__tcp__.listen) != NULL) {
		return 0;
	}

	if (pcb_lookup(INADDR_ANY, 0, addr, port, &__tcp__.closed) != NULL) {
		return 0;
	}

	return 1;
}
Пример #2
0
inline struct tcp_pcb * tcp_active_lookup(in_addr_t __faddr, uint16_t __fport, 
										  in_addr_t __laddr, uint16_t __lport)
{

	return (struct tcp_pcb *)pcb_lookup(__faddr, __fport, 
										__laddr, __lport, 
										&__tcp__.active);
}
Пример #3
0
int udp_connect(struct udp_pcb * __up, in_addr_t __addr, uint16_t __port) 
{
	int ret = 0;

	if (__up == NULL) {
		DCC_LOG1(LOG_ERROR, "<%05x> NULL", (int)__up);
		/* FIXME: not a socket? The semantic here is not exactly the same
		   as the sockets API. */
		return -ENOTSOCK;
	}

	DCC_LOG3(LOG_TRACE, "<%05x> %I:%d", (int)__up, __addr, ntohs(__port));

	if ((__port == 0) && (__addr != INADDR_ANY)) {
		DCC_LOG1(LOG_WARNING, "<%05x> invalid port.", (int)__up);
		return -EADDRNOTAVAIL;
	}

	tcpip_net_lock();

	if ((__addr == INADDR_ANY) && (__port == 0)) {
		__up->u_faddr = __addr;
		__up->u_fport = __port;
		__os_cond_signal(__up->u_rcv_cond);
	} else {
		if (pcb_lookup(__addr, __port, __up->u_laddr, 
					   __up->u_lport, &__udp__.active)) {
			DCC_LOG3(LOG_WARNING, "<%05x> %I:%d in use", (int)__up,
					 __addr, ntohs(__port));
			ret = -EADDRINUSE;
		} else {
			__up->u_faddr = __addr;
			__up->u_fport = __port;
			__os_cond_signal(__up->u_rcv_cond);
		}
	}

	tcpip_net_unlock();

	return ret;
}