3

i am trying to communicate with FPGA board, on which basic UDP protocol was implemented. i use windows 7 PC, python 2.7.6 32 bit.

my computer is connected to LAN network. automatically receives this IP (from ipconfig): IP 192.168.2.1, Subnet mask: 255.255.255.0

my board is connected to to my computer with a switch. IP of the board is fixed (in hardware code) - 192.168.4.10.

if i understand currectly - my computer and my board are on different subnets, because 2 of the 4 right ip sub-numbers are different.

when i send UDP packet - card does not receive it. when i manually force my computer to be the same ip (192.168.2.1) but 255.255.0.0 subnet mask, it does receive.

python code i use for sending is something like this:

import socket

UDP_IP = "192.168.4.10"
RECEIVE_PORT = 5005
SEND_PORT = 5005
MESSAGE = "Hello, World!"

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock .bind(('', SEND_PORT))
sock.sendto(MESSAGE, (UDP_IP, RECEIVE_PORT))

what could be the reason? is there any way i can fix this in code? is there any way i can change my subnet mask in code? what should i read to understand my problem?

user1952686
  • 339
  • 1
  • 4
  • 12

1 Answers1

3

Actually you should use "IP address alias" to have both of 192.168.2.1/255.255.255.0 and, say, 192.168.4.1/255.255.255.0 on a single Ethernet port on your PC:


What happened when you sent a UDP datagram to 192.168.4.10 from 192.168.2.1/255.255.255.0:

  1. The network addresses of your PC and the destination were different: 192.168.4.0 vs 192.168.2.0
  2. Therefore your PC assumed it had to ask the gateway router to appropriately deliver the datagram somewhere remote, and sent it to the router (the details on how to do so don't matter here)
  3. I guess your router knew nothing about the 192.168.4.0 network and had to discard the datagram

What happened when you sent a UDP datagram to 192.168.4.10 from 192.168.2.1/255.255.0.0:

  1. The network addresses of your PC and the destination agreed: 192.168.0.0
  2. So your PC assumed it didn't have to bother the gateway router and could directly talk to it
  3. Then the next step was to query the recipient's MAC address by ARP (Address Resolution Protocol.) It simply uses Ethernet broadcast to ask all the devices connected to your LAN who is the owner of 192.168.4.10
  4. As there's no notion of subnet in ARP/Ethernet, your FPGA NIC simply replied something like "Yes, I have 192.168.4.10. Call me at d8:cb:8a:f0:0b:aa"
  5. Your PC could send a UDP datagram to d8:cb:8a:f0:0b:aa
    • FYI: a similar process must have happened before your PC could talk to the gateway router.
Community
  • 1
  • 1
nodakai
  • 7,773
  • 3
  • 30
  • 60
  • If you are lucky, your remote device is ALSO listening for UDP multicast or broadcast and you can get a packet through to it that way. if you also are listening on UDP multicast/broadcast you might get an answer back. BUT ONLY if the remote device KNOWS to respond to your machine via multicast/broadcast UDP. If you are stuck with UDP unicast, then the @nodakai gives is the only one there is - add an alias to your NIC (if you can). – Jesse Chisholm Jan 29 '15 at 21:34
  • PS: Adding an alias programmatically is non-trivial. (1) be administrator, (2) force the NIC to be STATIC IP Address (if it is currently DHCP), (3) add the alias. There is no OS-independent way to do all this. And I don't know python networking well enough to suggest. – Jesse Chisholm Jan 29 '15 at 21:38