Can server automatically response in Udp broadcasting event? - ios

I am a beginner to iOS and network. What I want to do is sending a broadcast msg to a local network and getting all AP(hotspot) information back, like MAC address. I am just wondering if the AP(server) will automatically send the response back to the sender (like my iPhone) after I send a msg to "255.255.255.255" by Udp.

This is more of a networking question.
In short: use DHCP (RFC 2131) to get the server IP and use ARP (RFC 826) to obtain the MAC address associated to that IP. DHCP is connectionless (UDP), but ARP is a TCP/IP protocol.
The DHCP message (DHCPDISCOVER) will send something like "this is my MAC address(xx:xx:xx:xx:xx:xx), give me an IP addresss!" and the response (DHCPOFFER) from the server will contain the IP of the access point but not the MAC.
To get the MAC address of the AP, use ARP.
ARP stands for Address Resolution Protocol and is the mechanism used in the IP protocol over ethernet to obtain the MAC address of the destination. If the destination IP address belong to the same IP subnetwork the ARP module will send a broadcast ethernet message (ARP query) asking the MAC address of the destination IP address. If the destination is not on your local network the ARP module will send an ARP query using the IP address of your router.

Related

Wireshark Displayed Packets

I am a Wireshark learner and currently I am using Tshark to sniff my network packages. Currently my local IP is 192.168.0.114 and my collegue is 192.168.0.102.
However when I start capturing packets, I receive some packets with source IP 192.168.0.102 and destination IP 192.168.0.255. I am not the sender nor the receiverWhy am I seeing those packets? Here is my code just in case>
capture = pyshark.LiveCapture(interface='eth0')
capture.sniff(timeout=50)
capture
192.168.0.255 seems to by the broadcast IP address : 192.168.0.102 send this message to all other hosts on the network, your computer is receiving it as a member of this subnet.
The mask is probably 255.255.255.0 :)

What is required for direct TCP\IP connection?

I want to write an app, that establishes direct TCP\IP connection between two devices over the internet.
I have a server to exchange IP addresses and ports, but is it enough to establish a connection?
How to handle cases, where both devices are on the one IP (connected to the same Wi-Fi hotspot)?
Also, I don't understand how open ports on the device could be accessible without port forwarding settings on hotspot? Is there any range of ports open for apps usage?
You are correct about port forwarding for most cases.
TCP/IP is OSI Layer 4 protocol. You need to be able to send data to the sever application with a known IP address and port number. Now when on the internet, this can get more complicated because you normally do not directly interface with the IP address that the rest of the internet reaches you at. This is your public IP address. The modem you have from your ISP likely implements a NAT
, which turns your private address into your public address. You modem will block all TCP SYN requests unless there is forwarding rule specifically for it.
This is just the typical case, you can also look into setting your modem up for DMZ mode and even implementing your own reverse proxy like nginx.

How to send UDP packets to a MAC address from an Android app?

Is there a way to send UDP packets to a network MAC address?
Neither DatagramSocket nor DatagramPacket seems to have a mechanism of doing this.
Because of the layered network stack, the first response is that you cannot send a UDP message to a MAC address. My statement means that you don't have any means of setting a MAC address in a UDP datagram field. You can send a UDP datagram to an IP address and port. This IP address can be unicast, multicast, or broadcast.
If you intend to send a UDP datagram to a specific MAC address, you need to implement a more complex solution (DHCP is an example of a more complex solution). There are different strategies you can apply:
If you just need to send a datagram to a MAC address without having received any datagram from that NIC, and knowing that MAC address, first you will need to send a layer 2 frame to that MAC address (a layer 2 protocol allows you to set a MAC address). You can implement a protocol listening to that MAC address frames and being able to send a response back providing you the corresponding IP address. RARP is a protocol that lets you get an IP given the MAC address
You can implement your protocol that uses a multicast group. From your PC you send a multicast message containing the MAC address you are targeting. All nodes (applications in nodes) subscribed to that multicast group receive that message. The one with the targeted MAC address can respond. Once it responds, you have its IP address and can send a unicast UDP datagram.
The short answer is no. The networking stack is set up for the hardware address to be addressable in the OS's media layer with only a defined interface with the transport layer exposed to the application. You would need to tap into the low-level OS. It looks like you are trying to make this call within Java and it's highly unlikely that you will be able to accomplish this.

Send udp message outside of subnet

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?
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:
http://www.unixwerk.eu/linux/redhat/ipalias.html
How to create an IP alias on Windows
What happened when you sent a UDP datagram to 192.168.4.10 from 192.168.2.1/255.255.255.0:
The network addresses of your PC and the destination were different: 192.168.4.0 vs 192.168.2.0
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)
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:
The network addresses of your PC and the destination agreed: 192.168.0.0
So your PC assumed it didn't have to bother the gateway router and could directly talk to it
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
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"
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.

Getting IP addresses of the PC's available on wifi network in android

I am able to establish connection between android and PC via Wi-fi. But this is done by hard coding the the IP address of the PC (server) in the android program. But I wanted to get IP addresses of the PC's available on the Wi-fi network programmatically. So please let me know how to scan for PC's on the network and get their respective IP address.
can you not multicast a UDP packet on the network which the server listens for and responds to with a packet containing the ip address of the server in order to set up the connection?
You should be able to find help on that topic, with some options here here and here

Resources