static TCPChild* _tcpchild_new(TCP* tcp, TCP* parent, in_addr_t peerIP, in_port_t peerPort) { MAGIC_ASSERT(tcp); MAGIC_ASSERT(parent); TCPChild* child = g_new0(TCPChild, 1); MAGIC_INIT(child); /* my parent can find me by my key */ child->key = utility_ipPortHash(peerIP, peerPort); descriptor_ref(tcp); child->tcp = tcp; descriptor_ref(parent); child->parent = parent; child->state = TCPCS_INCOMPLETE; socket_setPeerName(&(child->tcp->super), peerIP, peerPort); /* the child is bound to the parent server's address, because all packets * coming from the child should appear to be coming from the server itself */ socket_setSocketName(&(child->tcp->super), socket_getBinding(&(parent->super)), parent->super.boundPort); return child; }
static void _host_associateInterface(Host* host, Socket* socket, in_addr_t bindAddress, in_port_t bindPort) { MAGIC_ASSERT(host); /* connect up socket layer */ socket_setSocketName(socket, bindAddress, bindPort, FALSE); /* now associate the interfaces corresponding to bindAddress with socket */ if(bindAddress == htonl(INADDR_ANY)) { /* need to associate all interfaces */ GHashTableIter iter; gpointer key, value; g_hash_table_iter_init(&iter, host->interfaces); while(g_hash_table_iter_next(&iter, &key, &value)) { NetworkInterface* interface = value; networkinterface_associate(interface, socket); } } else { NetworkInterface* interface = host_lookupInterface(host, bindAddress); networkinterface_associate(interface, socket); } }