68 lines
2.1 KiB
C
68 lines
2.1 KiB
C
#include "port-tunnel.h"
|
|
|
|
////////////////////////////////////////
|
|
// ConnectorUDP //
|
|
////////////////////////////////////////
|
|
|
|
void ConnectorUDP_construct(ConnectorUDP* ptr, knIPV4Endpoint listener_end, knIPV4Endpoint connector_end, OutputMode out_mode){
|
|
__PipeStorage_construct(&ptr->pipes);
|
|
|
|
if(out_mode == OutputMode_Bind){
|
|
tryLast(knSocketUDP_open(true), m_s, ;);
|
|
ptr->main_sock = m_s.value.VoidPtr;
|
|
tryLast(knSocketUDP_bind(ptr->main_sock, connector_end), _m7u7, ;);
|
|
}
|
|
else if(out_mode == OutputMode_Send){
|
|
tryLast(knSocketUDP_open(false), m_s, ;);
|
|
ptr->main_sock = m_s.value.VoidPtr;
|
|
}
|
|
else throw("no output mode has been selected");
|
|
|
|
ptr->listener_end = listener_end;
|
|
ptr->connector_end = connector_end;
|
|
ptr->out_mode = out_mode;
|
|
}
|
|
|
|
void ConnectorUDP_destruct(ConnectorUDP* ptr){
|
|
__PipeStorage_destruct(&ptr->pipes);
|
|
tryLast(knSocketUDP_close(ptr->main_sock), _m864, ;);
|
|
}
|
|
|
|
void ConnectorUDP_start(ConnectorUDP* ptr){
|
|
__PipeStorage_startGCAsync(&ptr->pipes);
|
|
|
|
}
|
|
|
|
////////////////////////////////////////
|
|
// ConnectorTCP //
|
|
////////////////////////////////////////
|
|
|
|
void ConnectorTCP_construct(ConnectorTCP* ptr, knIPV4Endpoint listener_end, knIPV4Endpoint connector_end, OutputMode out_mode){
|
|
__PipeStorage_construct(&ptr->pipes);
|
|
|
|
if(out_mode == OutputMode_Bind){
|
|
tryLast(knSocketTCP_open(true), m_s, ;);
|
|
ptr->main_sock = m_s.value.VoidPtr;
|
|
tryLast(knSocketTCP_bindAndListen(ptr->main_sock, connector_end), _m7u7, ;);
|
|
}
|
|
else if(out_mode == OutputMode_Send){
|
|
tryLast(knSocketTCP_open(false), m_s, ;);
|
|
ptr->main_sock = m_s.value.VoidPtr;
|
|
}
|
|
else throw("no output mode has been selected");
|
|
|
|
ptr->listener_end = listener_end;
|
|
ptr->connector_end = connector_end;
|
|
ptr->out_mode = out_mode;
|
|
}
|
|
|
|
void ConnectorTCP_destruct(ConnectorTCP* ptr){
|
|
__PipeStorage_destruct(&ptr->pipes);
|
|
tryLast(knSocketTCP_close(ptr->main_sock), _m864, ;);
|
|
}
|
|
|
|
void ConnectorTCP_start(ConnectorTCP* ptr){
|
|
__PipeStorage_startGCAsync(&ptr->pipes);
|
|
|
|
}
|