lilzz
Posts: 411
Joined: Sat Nov 30, 2013 5:27 pm

Ad-hoc Pi communication with DHCP Computer

Tue Jun 24, 2014 9:27 pm

I set up the Pi as Ad-Hoc network with assigned Static IP address and wifi adapter capable of ad-hoc

My computer is using normal DHCP from the router/gateway.

So, I try to Ping from Ad-Hoc Pi and to my normal Computer.


Can someone explain to me how's the communication between the 2 work?

User avatar
DougieLawson
Posts: 39124
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Ad-hoc Pi communication with DHCP Computer

Tue Jun 24, 2014 10:17 pm

Every machine gets an IP address and a netmask (or CIDR format mask).
Every machine has a routing table.

Lets assume one machine is 10.0.0.7/8, the gateway/router is 10.0.0.1/8 and the other machine is 10.0.0.27/8

You have a TCP/IP server running on 10.0.0.27 port 30000
You have a TCP/IP client running on 10.0.0.7 (ephemeral port 51167) that's trying to connect to the server.

How does 10.0.0.7 find 10.0.0.27?

The router keeps an ARP (address resolution protocol) table which has MAC address and IP address. It can also send out ARP packets to discover the network topology. "Who has 10.0.0.7, tell 10.0.0.1". The answer to that is "MAC aa:bb:cc:dd:ee:ff has 10.0.0.7". That's separate from DHCP and is used with ALL routing within your LAN.

When we connect to port 30000 we send a SYN from 10.0.0.7 to 10.0.0.27. (source=0x0A000007, dest=0x0A00001B) (The router knows how to find 10.0.0.27 and can send it on the wires to the right MAC address)
10.0.0.27 sends back a SYN,ACK (source==0x0A00001B, dest=0x0A000007)
10.0.0.7 sends the payload with an ACK (s=0x0A000007, d=0x0A00001B)
10.0.0.27 sends a reply with ACK (s=0x0A00001B, d=0x0A000007)
eventually there's a FIN,ACK packet to end the conversation.

Much the same stuff happens for a ping except that uses ICMP packets with a 56byte payload. There's no SYN, SYN,ACK, ACK three way handshake for ICMP.

When you connect to google.com port 80 (173.194.34.130) the same thing happens, except this time the router has to hand the request up the wire to your ISP and your ISP hands it off to their boundary router and onwards until it reaches Google's server.

Your first reading assignment is to read, digest and understand ALL 998 pages of http://www.redbooks.ibm.com/redbooks/pdfs/gg243376.pdf

If you can't complete that reading assignment then read all HTML pages starting from http://www.tcpipguide.com/free/index.htm
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

lilzz
Posts: 411
Joined: Sat Nov 30, 2013 5:27 pm

Re: Ad-hoc Pi communication with DHCP Computer

Wed Jun 25, 2014 7:33 am

DougieLawson wrote:Every machine gets an IP address and a netmask (or CIDR format mask).
Every machine has a routing table.

Lets assume one machine is 10.0.0.7/8, the gateway/router is 10.0.0.1/8 and the other machine is 10.0.0.27/8

You have a TCP/IP server running on 10.0.0.27 port 30000
You have a TCP/IP client running on 10.0.0.7 (ephemeral port 51167) that's trying to connect to the server.

OK, for discussion sake, let's say 10.0.0.7 is the Pi and setup as ad-hoc.
1)On the Pi 10.0.0.7 /etc/network/interfaces there should be a line to add the gateway 10.0.0.1 right? if that line doesn't exist that means router /gateway doesn't exist. The 10.0.0.7 would become unroutable?

2)When 10.0.0.7 setup ad ad-hoc what does that mean to the router 10.0.0.1? Does it have a special label for 10.0.0.7 as ad-hoc on the routing table?

3)you said 10.0.0.7, 10.0.0.1 and 10.0.0.27 each one has a routing table. Does the router construct the table first and pass it to the other two? How does each table in sync with each other when topology got changed?

4)when 10.0.0.7 pinging 10.0.0.27, the router wouldn't get involved right? 10.0.0.27 would be the server listening on its port for incoming request. and when 10.0.0.7 request comes, the connection got accepted and tcp connection between the two established, right?

User avatar
DougieLawson
Posts: 39124
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Ad-hoc Pi communication with DHCP Computer

Wed Jun 25, 2014 7:43 am

http://www.tcpipguide.com/free/t_OSIRef ... ummary.htm
Wow! Have you read all that stuff already? Is your reading assignment complete?

Look at the communications layers.

WiFi is part of layer 1 (physical including wireless radio), Ad-hoc is part of layer 2 (data-link), IP is layer 3 & TCP is layer 4.

With an ad-hoc connection you've got a single point-to-point connection and that's reflected in the IP routing table. At the IP layer we mostly don't care how layer 1 & layer 2 are making the connection, we simply build a packet with the right source & dest addresses and hand it to layer 2 with a simple "send that and tell me when it's done" instruction.

The local routing tables are constructed by throwing a bunch of ARP packets round the network and building the table when the ARP replies come back. Some parts of the routing table are built from the DHCP (or static) network definition.

This gets a whole lot more complex when we reach (via the link to our ISP) the boundary gateway protocols of the public Internet (so we'll ignore that piece and treat it as a mystical cloud where we pour our data in and, some how, it magically reaches the destination).

With the ARP table we have a match for IP address to MAC address and MAC address to IP address so part of the layer 2 processing is to convert the source & dest IP addresses to source & dest MAC addresses before we hand the stuff to layer 1 to send it on the physical connection. At each layer the packet of payload data grows by a few bytes as the layer adds it's routing information.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: Ad-hoc Pi communication with DHCP Computer

Wed Jun 25, 2014 1:19 pm

The gateway information only comes into play when you want to access an IP address *outside* the 10.* network.

lilzz
Posts: 411
Joined: Sat Nov 30, 2013 5:27 pm

Re: Ad-hoc Pi communication with DHCP Computer

Wed Jun 25, 2014 3:25 pm

AndrewS wrote:The gateway information only comes into play when you want to access an IP address *outside* the 10.* network.
But my static and self assigned 10.0.0.7 is with ESSID pi-ad-hoc and My 10.0.0.27 from dhcp is with ESSID HOME-1E6. Should they be treated as different network or same network? If considered different network then the router is needed for communication between the two.

If considered same network that means IP address not ESSID determines whether they same network or not?

User avatar
DougieLawson
Posts: 39124
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Ad-hoc Pi communication with DHCP Computer

Wed Jun 25, 2014 3:32 pm

If you have disconnected subnets they shouldn't share the same address block. Divide it into subnets and assign different subnets where needed.

Beware that 10.xxx.xxx.xxx is never routed between one subnet and another through ANY gateway/router.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: Ad-hoc Pi communication with DHCP Computer

Wed Jun 25, 2014 3:45 pm

Ahhh! You never mentioned that you were actually using different wireless networks!
I think me and Dougie had been assuming that your "DHCP Computer" was connected to your router via Ethernet cable.

Yes, if the wireless networks are using different SSIDs, they won't be able to communicate, unless you have a router with two wireless radios (not just two antenna that are connected to the same wireless radio!), that's able to connect to each of the wireless networks and route packets between them. But in that case you'd need to use a different netmask on each wireless network (e.g. 10.0.*.* and 10.1.*.*) so that the router knows which network the packets are supposed to be routed to.

lilzz
Posts: 411
Joined: Sat Nov 30, 2013 5:27 pm

Re: Ad-hoc Pi communication with DHCP Computer

Thu Jun 26, 2014 3:01 am

AndrewS wrote:Ahhh! You never mentioned that you were actually using different wireless networks!
I think me and Dougie had been assuming that your "DHCP Computer" was connected to your router via Ethernet cable.

Yes, if the wireless networks are using different SSIDs, they won't be able to communicate, unless you have a router with two wireless radios (not just two antenna that are connected to the same wireless radio!), that's able to connect to each of the wireless networks and route packets between them. But in that case you'd need to use a different netmask on each wireless network (e.g. 10.0.*.* and 10.1.*.*) so that the router knows which network the packets are supposed to be routed to.

OK, i only have a normal router.i guess i have rid off different ESSID so they can communicate.
when I manually give out IP address of 10.0.0.7 is there any advantage or disadvantage to label it as wifi-mode ad-hoc while the other rest are getting dhcp.
So, they shouldn't have any problem pinging each other right?

plugwash
Forum Moderator
Forum Moderator
Posts: 3614
Joined: Wed Dec 28, 2011 11:45 pm

Re: Ad-hoc Pi communication with DHCP Computer

Thu Jun 26, 2014 9:30 pm

DougieLawson wrote: Beware that 10.xxx.xxx.xxx is never routed between one subnet and another through ANY gateway/router.
BS, it can be routed within your network like any other IP block, it just can't be routed on the public internet.

Return to “General discussion”