1

anybody care to share some insights on how to use LSP for packet modifying ?

I am using the non IFS subtype and I can see how (pseudo?) packets first enter WSPRecv. But how do I modify them ? My inquiry is about one single HTTP response that causes WSPRecv to be called 3 times :((. I need to modify several parts of this response, but since it comes in 3 slices, it is pretty hard to modify it accordingly. And, maybe on other machines or under different conditions (such as high traffic) there would only be one sole WSPRecv call, or maybe 10 calls. What is the best way to work arround this (please no NDIS :D), and how to properly change the buffer (lpBuffers->buf) by increasing it ?

int WSPAPI 
WSPRecv(
SOCKET          s,
LPWSABUF        lpBuffers,
DWORD           dwBufferCount,
LPDWORD         lpNumberOfBytesRecvd,
LPDWORD         lpFlags,
LPWSAOVERLAPPED lpOverlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
LPWSATHREADID   lpThreadId,
LPINT           lpErrno
)
{
LPWSAOVERLAPPEDPLUS ProviderOverlapped = NULL;
SOCK_INFO          *SocketContext = NULL;
int                 ret = SOCKET_ERROR;


*lpErrno = NO_ERROR;

//
// Find our provider socket corresponding to this one
//
SocketContext = FindAndRefSocketContext(s, lpErrno);
if ( NULL == SocketContext )
{
    dbgprint( "WSPRecv: FindAndRefSocketContext failed!" );
    goto cleanup;
}

//
// Check for overlapped I/O
//
if ( NULL != lpOverlapped )
{
    /*bla bla .. not interesting in my case*/
}
else
{
    ASSERT( SocketContext->Provider->NextProcTable.lpWSPRecv );

    SetBlockingProvider(SocketContext->Provider);
    ret = SocketContext->Provider->NextProcTable.lpWSPRecv(
            SocketContext->ProviderSocket, 
            lpBuffers, 
            dwBufferCount,
            lpNumberOfBytesRecvd, 
            lpFlags, 
            lpOverlapped, 
            lpCompletionRoutine, 
            lpThreadId,
            lpErrno);
    SetBlockingProvider(NULL);

    //is this the place to modify packet length and contents ?

    if (strstr(lpBuffers->buf, "var mapObj = null;"))
    {
        int nLen = strlen(lpBuffers->buf) + 200;
        /*CHAR *szNewBuf = new CHAR[];
        CHAR *pIndex;

        pIndex = strstr(lpBuffers->buf, "var mapObj = null;");
        nLen = strlen(strncpy(szNewBuf, lpBuffers->buf, (pIndex - lpBuffers->buf) * sizeof (CHAR)));
        nLen = strlen(strncpy(szNewBuf + nLen * sizeof(CHAR), "var com = null;\r\n", 17 * sizeof(CHAR)));
        pIndex += 18 * sizeof(CHAR);
        nLen = strlen(strncpy(szNewBuf + nLen * sizeof(CHAR), pIndex, 1330 * sizeof (CHAR)));
        nLen = strlen(strncpy(szNewBuf + nLen * sizeof(CHAR), "if (com == null)\r\n" \
                                           "com = new ActiveXObject(\"InterCommJS.Gateway\");\r\n" \
                                            "com.lat = latitude;\r\n" \
                                            "com.lon = longitude;\r\n}", 111 * sizeof (CHAR)));
        pIndex = strstr(szNewBuf, "Content-Length:");
        pIndex += 16 * sizeof(CHAR);
        strncpy(pIndex, "1465", 4 * sizeof(CHAR));

        lpBuffers->buf = szNewBuf;
        lpBuffers->len += 128;*/
    }

    if ( SOCKET_ERROR != ret )
    {
        SocketContext->BytesRecv += *lpNumberOfBytesRecvd;
    }
}

cleanup:

if ( NULL != SocketContext )
    DerefSocketContext( SocketContext, lpErrno );

return ret;
}

Thank you

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
kellogs
  • 2,837
  • 3
  • 38
  • 51
  • I think I am up to something - how about catching the connect request initiated by my target application and then redirecting it to my custom socket server which would proxy all the communication between target app and web server ? Then I shall only wait for that (3 slices) http response, swallow it and send my target app what I want. Still, how do I know that spcific Http response is complete ? – kellogs Feb 10 '10 at 23:58
  • can you post the whole code here or somewhere I am interested in doing this as well. Thank you. – Para Nov 27 '12 at 21:49

1 Answers1

0

my comment worked out. http response headers / request turned out to end in \r\n\r\n.

kellogs
  • 2,837
  • 3
  • 38
  • 51