Search code examples
c++network-programminghookwinsockwinsock2

How to construct a const char *buffer for send() function of winsock


I hooked the send function but I'm receiving errors from the server. The server says that I'm sending an invalid packet.

What's the right way to construct a const char *buffer for the send function?

I want to construct a buffer from a string. The string contains the exact hex codes in memory.

My send hook function

int WINAPI sendHook(SOCKET s, const char *buf, int len, int flags) {

    string packet = "3904050080841E00";
    return pSend(s, packet.c_str(), packet.length(), flags);
}

Solution

  • Simple.

    const char[] packet = {0x39, 0x04, 0x05, 0x00, 0x80, 0x84, 0x1E, 0x00};
    return pSend(s, packet, sizeof packet, flags);