Thank you for your replies!
Ok ok ok, so I dont seem a bit shady here, here is some code. I know that how i explained it probably was not exact and caused some confusion.
Code:
bool CREATE(SOCKET_DATA *PIPE) {
PIPE->m_sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
if ( !IS_VALID( PIPE ) ) {
return false;
}
linger LING;
unsigned int LINGER_SIZE = sizeof(LING);
LING.l_onoff=1;
LING.l_linger=10;
int OPTION = 1;
if ( setsockopt( PIPE->m_sock, SOL_SOCKET, SO_REUSEADDR, (char*)&OPTION, sizeof( OPTION ) ) == -1 ) {
return false;
}
if ( setsockopt( PIPE->m_sock, SOL_SOCKET, SO_LINGER, (void*)(&LING), LINGER_SIZE ) == -1 ) {
return false;
}
return true;
}
Now first I setup a server socket to listen, and after that I have a bind, listen and accept socket which all works perfectly, plus a non blocking function, again working perfectly. The other function sets up a client socket, connecting to a seperate server, web server or whatever. The purpose of the two sockets is to transfer data between. At this point you understand that this program is a kind of proxy, which it is.
So after I try to setup a client socket, after calling the create_socket function, right this line,
PIPE->m_sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
run those two commands through terminal, "netstat" and "lsof" and tada we have the CLOSED issue. Before that, it doesnt exist, but aha we have established a connection and a listen.
Code:
program 11413 K7 4u IPv4 0x0da8ead8 0t0 TCP *:21172 (LISTEN)
program 11413 K7 5u IPv4 0x0da93ea8 0t0 TCP 17.172.232.12:21172->17.172.232.12:52561 (ESTABLISHED)
program 11413 K7 6u IPv4 0x0da88688 0t0 TCP 172.16.1.253:52562->cplusplus.com:http (CLOSE_WAIT)
[COLOR="Red"]program 11413 k7 8u IPv4 0x0fdd0f68 0t0 TCP *:* (CLOSED)[/COLOR] **This is the problem, right here**
But it shows "above" that a connection was established. My functions work correctly, but setting up the second socket literally makes the program just go like omg omg omg omg. lol
unless there's a problem with my pointers, but I dont think so.