Wireshark does not display WSL2 loopback traffic
Asked Answered
E

1

11

I try to send udp packet between on my WSL2 localhost client and server, i can sent data successfully but when want to analyze on wireshark, wireshark cannot capture anything at loopback traffic adapter and vEthernet capture. Running program and wireshark windows image at after the sender code.

sender.cpp

#define PORT 50254

int main(){
    Client* client = new Client("127.0.0.1", PORT);
    memset(&client->serv_addr, 0, sizeof(client->serv_addr));
    client->serv_addr.sin_family = AF_INET;
    client->serv_addr.sin_port = htons(port);
    client->serv_addr.sin_addr.s_addr = inet_addr(client->ipAddres);
    if ((client->Socket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
        perror("socket creation failed");
        exit(EXIT_FAILURE);
    }
    if (connect(client->Socket, (struct sockaddr*)&client->serv_addr, sizeof(client->serv_addr)) < 0)
    {
        printf("\n Error : Connect Failed \n");
        exit(0);
    }
    char* message = "Hello Server";
    cout << "Sent Size : " << send(client->Socket,message, 100, 0) << endl;
}

Wireshark and running program

Elicia answered 22/3, 2022 at 12:2 Comment(2)
Not a single answer ?? I'm facing the same issueLongshore
Use tcp dump and capture packets and copy them to wireshark. sudo tcpdump -i 1 -w ./mycap.pcapAstrology
R
2

It seems that you have to install Wireshark on WSL2 in order to see the loopback traffic. You can use the following commands to install Wireshark on WSL2.

sudo apt install wireshark
sudo dpkg-reconfigure wireshark-common
sudo chmod +x /usr/bin/dumpcap

After installing, type wireshark in WSL2 and the wireshark gui should pop out. The downside is the scaling of the WSL2 Wireshark seems to not function well on high-resolution monitors. I still havn't find a way to solve this though; if you don't mind pixelated you can try this. The result is not unacceptable but still very blurry.

Rae answered 29/9, 2023 at 17:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.