Beej network programming example - unable to receive packets

I'm trying to work through https://beej.us/guide/bgnet/html//#datagram I have two computers each using WSL2 and have listener set up on one and talker set up on the other. Talker send the packets but listener doesnt receive them. I think it's because I'm using the wrong address. How do i find the address of the listener machine and if that's not right how do i recieve packets on the listener machine from the talker machine?
In a cmd.exe console on each Windows machine, do this:
1
2
3
4
5
6
7
$ ipconfig
....
Wireless LAN adapter WiFi:
   Connection-specific DNS Suffix  . :
   IPv4 Address. . . . . . . . . . . : 192.168.1.2
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.1.1


In a bash console on each WSL2 machine, do this:
1
2
3
4
$ ifconfig
eth0      Link encap:Ethernet  HWaddr 90:2b:34:31:53:b3  
		  inet addr:192.168.1.10  Bcast:192.168.1.255  Mask:255.255.255.0

The point is to discover whether the WSL2 'machines' piggyback off the same IP address as the host Windows machine, or whether Windows provides some kind of internal network (much like Virtualbox does).
talker:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
rjphares@DESKTOP-Q37H32C:~$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.21.143.234  netmask 255.255.240.0  broadcast 172.21.143.255
        inet6 fe80::215:5dff:fe29:e029  prefixlen 64  scopeid 0x20<link>
        ether 00:15:5d:29:e0:29  txqueuelen 1000  (Ethernet)
        RX packets 163  bytes 212606 (212.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 96  bytes 6716 (6.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 3  bytes 252 (252.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3  bytes 252 (252.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
C:\WINDOWS\system32>ipconfig

Windows IP Configuration


Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::dda4:c27d:7646:ced8%5
   IPv4 Address. . . . . . . . . . . : 192.168.1.16
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.1.1

Ethernet adapter vEthernet (WSL):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::1af:6bbc:4fe4:dd4e%17
   IPv4 Address. . . . . . . . . . . : 172.21.128.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :
Last edited on
listener:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
rjphares@DESKTOP-48D77E5:~$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.72.249  netmask 255.255.240.0  broadcast 172.20.79.255
        inet6 fe80::215:5dff:fe8b:140f  prefixlen 64  scopeid 0x20<link>
        ether 00:15:5d:8b:14:0f  txqueuelen 1000  (Ethernet)
        RX packets 259  bytes 225739 (225.7 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 82  bytes 5740 (5.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
C:\WINDOWS\system32>ipconfig

Windows IP Configuration


Wireless LAN adapter Local Area Connection* 3:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Local Area Connection* 4:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Wi-Fi:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::3832:a453:1a7e:ebe4%11
   IPv4 Address. . . . . . . . . . . : 192.168.1.11
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.1.1

Ethernet adapter Bluetooth Network Connection:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter vEthernet (WSL):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::18bb:3545:5eac:bc0f%42
   IPv4 Address. . . . . . . . . . . : 172.20.64.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :
i also turned off both firewalls so i dont think its because of a firewall
Last edited on
can you ping one machine from the other by ip addres (literally, at the console, ping 192.168.1.11 from the other machine, etc)
So each windows machine creates a local virtual network for all the WSL2 instances running on that particular machine, who's addresses run from 172.16.0.0 to 172.31.255.255
Just like the two windows machines are on your own private network who's addresses run from 192.168.0.0 to 192.168.255.255
https://en.wikipedia.org/wiki/Reserved_IP_addresses

The addresses of interest are these.
talker-linux - 172.21.143.234
talker-win32 - 192.168.1.16
talker-bridge - 172.21.128.1

listener-linux - 172.20.72.249
listener-win32 - 192.168.1.11
listener-bridge - 172.20.64.1


Running wireshark (from https://www.wireshark.org/ ) on both Windows machines will tell you how far messages are getting from talker to listener.

The first goal is to make sure each WSL2 instance can ping it's peer on the other host.
talker: ping 172.20.72.249
listener: ping 172.21.143.234

My guess would be that the routing tables are only set up to allow a WSL2 instance to talk to it's host and the outside world.
https://ss64.com/nt/route.html
https://ss64.com/nt/netstat.html (netstat -rn in particular)
So you would need to tell the various machines (two windows machines, and two WSL2 instances) how to route messages from one 172.x.y.z network to another 172.a.b.c network.

Are the 172 addresses the same every time you run a WSL2 instance on a given host, or the same following each reboot of a host? Or are they randomly assigned every time?
If it's all dynamic, there's going to be a lot of fiddling each time you restart.

Running two WSL2 instances on the same machine would be a lot easier, because both instances would be on the same 172 subnet.
I am unable to ping the other computer(listener-->talker and talker-->listener). Also the address changes each time I use ifconfig when the computer is rebooted.

The addresses are the same each time i use ipconfig when the computer is rebooted.

I have ran two instances of WSL2 on same computer and got successful results when running a client and server so that worked but was for a different solution in a different book.
well, this is your problem. I don't care what book it came from but if they can't talk to each other your code won't fix that and will not work. If you have a book that can set up the 2 so they talk, use that part of those instructions and then try your code... or see how those instructions are different from the new ones... or try a third set off the web.
Last edited on
Solution: uninstall WSL2 :)
Topic archived. No new replies allowed.