Hi,
I don't have any sample code, sorry.
However, I'd really like to have 1$ for every time I have seen someone doing the error you did. Really, I have seen it made so many times that I'm becoming sick of it. I know that everybody is different, and that you can't really say "I told already", but I feel like Don Quixote, fighting in vain.
Anyway... let's start again from scratch.
In IP a subnet is defined as a group of hosts that can reach each other by pure means of below-IP mechanisms. I.e., every node in the subnet can "talk" to each other without a router in between, purely because the L2 layer allows that.
In a subnet you can have broadcast (not in IPv6) packets, and IP will identify two host belonging to the same subnet if they have the same network prefix.
The network prefix is defined by the IP address and the network mask. If two addresses are identical after being XOR-ed with the same network mask (the one both believe that is the subnet network mask), then they are in the same subnet. Otherwise they aren't and the packet is sent to the designated gateway.
In a point-to-point (serial) link, you usually have only TWO hosts, which raises some issues, because you need to "waste" 2 more IP addresses for something you'll never use. Basically you need a /30 subnet when you could have used a /31. Never mind, this is not relevant.
Still, if you have a 3 nodes topology and you connect them with p2p links, one node will be in the middle, and will have to either:
1) act as a router, or
2) bridge its interfaces at L2.
Otherwise what will happen is this:
A---B---C
A sends a packet to C, and it thinks they're on the same subnet.
A sends the packet in its interface, and it reaches B. B will ignore the packet, because it's not a router. C will never receive it.
Another scenario.
A sends a packet to B, B replies to A (luck!)
C sends a packet to B, B replies to C... but sends the packet to A.
This is because for node B both links are equivalent, as they're the same subnet !
Basically.... everything goes boom.
So, what is your mistake ? IP addressing.
T.