Note that there are some explanatory texts on larger screens.

plurals
  1. POWinsock2 error 10014 on split TCP stream
    primarykey
    data
    text
    <p>code first</p> <pre><code>DWORD WINAPI tcp_t(LPVOID lpParam) { SOCKET tcp_client_s = (SOCKET)lpParam; struct sockaddr_in tcp_client; int tcp_client_len = sizeof(tcp_client), length; char req[4096], resp[4096]; getpeername(tcp_client_s, (struct sockaddr *)&amp;tcp_client, &amp;tcp_client_len); cli_log(PROTO_TCP, LOG_SYS, "(%s:%d) TCP thread spawned\n", inet_ntoa(tcp_client.sin_addr), ntohs(tcp_client.sin_port)); length = get_req_tcp(tcp_client_s, req, tcp_client); if(strci(req, "GET /syachi2ds/web/", 0)) { while(!strstr(req, "Connection: close\r\n\r\n")) length += get_req_tcp(tcp_client_s, req + length, tcp_client); length = check_req(req, resp); if(length &gt; 0) send_resp_tcp(tcp_client_s, resp, length, tcp_client); } closesocket(tcp_client_s); cli_log(PROTO_TCP, LOG_SYS, "(%s:%d) socket closed, closing thread\n", inet_ntoa(tcp_client.sin_addr), ntohs(tcp_client.sin_port)); ExitThread(0); } int get_req_tcp(SOCKET in_s, char *buf, struct sockaddr_in in) { int retval; cli_log(PROTO_TCP, LOG_COMM, "(%s:%d) waiting for incoming request...\n", inet_ntoa(in.sin_addr), ntohs(in.sin_port)); if ( (retval = recv(in_s, buf, 4096, 0)) == SOCKET_ERROR) cli_log(PROTO_TCP, LOG_ERROR, "(%d) recv() failed\n", WSAGetLastError()); cli_log(PROTO_TCP, LOG_COMM, "(%s:%d) data received\n", inet_ntoa(in.sin_addr), ntohs(in.sin_port)); return retval; } </code></pre> <p>This is part of a larger program I'm writing that does some kind of server emulation. It works good with TCP streams thar are not split into multiple packets, otherwise it gives winsock error 10014 on the first subsequent <code>recv()</code> invoked in the while loop.</p> <p>PS: <code>strci()</code> is a custom case-insensitive <code>strstr()</code></p> <p>PS2: i know there's no check for buffer overflows on req array.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload