Search code examples
c++csocketssendwinsock2

In TCP/IP Socket send, Send data still remains in OS Memory


I created a simple chatting client program to communicate with the server.

After the client sent data to the server using the send() function, the data was initialized to memset (buf, 0x00, sizeof(buf)), but after searching OS memory through Dumpit, there are still traces of data sent somewhere. How can i clear send data?

Screenshot of Dumpit data

int main() {
    WSADATA wsaData;
    SOCKET hSocket;
    SOCKADDR_IN servAddr;

    char message[30];
    char tmp[8];
    int strLen;
    memset(tmp, 0x00, 8);

    if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
        ErrorHandling("WSAStartup() error!");

    hSocket = socket(PF_INET, SOCK_STREAM, 0);
    if (hSocket == INVALID_SOCKET)
        ErrorHandling("socket() error!");

    memset(&servAddr, 0, sizeof(servAddr));
    servAddr.sin_family = AF_INET;
    servAddr.sin_addr.s_addr = inet_addr("222.106.99.137");
    servAddr.sin_port = htons(atoi("20071"));

    if (connect(hSocket, (SOCKADDR*)&servAddr, sizeof(servAddr)) == SOCKET_ERROR)
        ErrorHandling("connect() error!");

    memcpy(tmp, "thisishell", 7);

    sendto(hSocket, tmp, strlen(tmp) + 1, 0,
        (struct sockaddr*)&servAddr, sizeof(servAddr));

    memset(tmp, 0x00, 8);
    memset(tmp, 0xFF, 8);
    memset(tmp, 0x00, 8);

    closesocket(hSocket);
    WSACleanup();

    return 0;
}

Solution

  • Your binary program code still contains the string literal thisishell. Most likely, that's what you're seeing, because your other string literals like "connect() error!" can be seen right above it in memory.