Using WSL2, and a raw sockets implementation, I cannot seem to send any packets. I cannot include all the code as it is a big driver, but I will try include the relevant parts below. I don't think there is anything wrong with the socket code, but maybe my socket configuration or something.
In tcpdump I can see my packets being sent, but they do not show in up Wireshark on the vEthernet(WSL) interface, or the PCs Ethernet interface that is the only internet connection.
The socket is created with:
int sock = socket(AF_PACKET, SOCK_DGRAM, htons(ETH_P_ALL));
The send function uses the code below. sa.sll_ifindex is set to the index of the eth0 AF_PACKET network interface (6 in my case). sa.sll_addr is set to the MAC address of the same interface. The packet data is constructed by lwIP IP stack. sendto always succeeds, returning the full number of bytes sent.
memset(&sa, 0, sizeof(sa));
sa.sll_family = AF_PACKET;
sa.sll_halen = netif->hwaddr_len;
for (unsigned i = 0; i < netif->hwaddr_len; i++)
{
sa.sll_addr[i] = netif->hwaddr[i];
}
sa.sll_ifindex = ctx->HostInterfaceIndex;
sa.sll_protocol = htons(ETH_P_IP);
ssize_t sent = sendto(ctx->RawSockHandle, buf, p->tot_len, 0, (struct sockaddr *)&sa, sizeof(sa));
When application code is sending a DNS query, I see the following in netcap:
14:01:01.101480 IP 172.17.44.146.10924 > dns.google.domain: 55249+ A? test.site.io. (35)
14:01:01.452154 IP 172.17.44.146.10924 > dns.google.domain: 55249+ A? test.site.io. (35)
14:01:02.452560 IP 172.17.44.146.10924 > dns.google.domain: 55249+ A? test.site.io. (35)
14:01:04.452146 IP 172.17.44.146.10924 > dns.google.domain: 55249+ A? test.site.io. (35)
14:01:07.452520 IP 172.17.44.146.10924 > one.one.one.one.domain: 55249+ A? test.site.io. (35)
14:01:08.452721 IP 172.17.44.146.10924 > one.one.one.one.domain: 55249+ A? test.site.io. (35)
14:01:09.452102 IP 172.17.44.146.10924 > one.one.one.one.domain: 55249+ A? test.site.io. (35)
14:01:11.452584 IP 172.17.44.146.10924 > one.one.one.one.domain: 55249+ A? test.site.io. (35)
So, it appears my packets are making it into the WSL eth0 interface, but not making it any further.
Any suggestions on what I can do to diagnose this. I can paste additional code if needed, just ask. I tried to keep it simple.

getaddrinfo, etc. to get the IP (not MAC) address of google.com (e.g.142.251.35.164)? You may want to start withAF_INETfirst, to verify things and then graduate toAF_PACKETwhen the simpler/regular connect is working.