How to differentiate between two or more devices in the same ip address (wifi)? - file

I am currently working on networking project that share files between mobile devices using p2p technology. Using wifi or mobile network. The main problem is when using wifi the general ip address become the same for all connected devices to that wifi connection and this is the problem how to send the file to a particular one if all connected devices have the same ip address?

Every device on same network has private IP addresses which are unique. All of them shares one public IP address. Now how do server distinguish them by only seeing their public IP and send them data?
Well the answer is the server doesn't see only IP address. It sees IP:Port. Every private IP connected to the server has same public IP but different port. The public IP belongs to your NAT. Your NAT assigns unique port to every private IP addresses and maps them. The mapping is like this [private IP, private port, public IP, public port, transport protocol].
So when your server sends a packet to public IP:port then the packet is forwarded to the mapped private IP:port. And your device with that private IP:Port receives it.

Use the mac address which is uniques for every device you pick.
Comparing mac address will be easy when you encounter multiple devices with same IP address.

Related

How to change dynamic private IP address in a virtual network to static (non-changing) IP address for containergroups (Azure Container Instances)

I currently have a containergroup that uses a virtual network to communicate. What happens is that from time to time the dynamic IP changes randomly. I know it is not possible to have a public (non-changing) IP address using a FQDN for the time being (Azure is working on it), but I was wondering if there is a way to change the IP address from dynamic to static. Any other workaround would be fine too. Thanks in advance.
Unfortunately, currently, the ACI does not provide the ability to assign a static private IP address to the container when using a private VNet. See https://feedback.azure.com/forums/602224-azure-container-instances/suggestions/36989110-allow-aci-instances-to-use-a-static-ip-address-whe.
So you could upvote that feedback so that the Azure team might improve the ACI service.

Raw Sockets - Internet Protocol Layers

I have been working with Raw Berkeley Sockets in C, which allow the programmer to access Layer 2 (IP Headers) of the Internet Protocol Suite. I would like to know how the raw sockets handle transport on Layer 1 (Link Layer), specifically with regard to wireless local area networks.
For example, how does the socket know which network interface (eth0 or wlan0) to send the packet to?
If I am behind a wireless router, should I still fill the IP Source Address of my IP Header with my LAN address (192.168.1.1), or with the internet address (74.125.226.68) of my router?
If I do fill the IP Source address with my LAN address (192.168.1.1), does the IP Header get changed when it goes through the router, or does it stay that way, so that the receiving end of the packet attempts to send the response to a local host on its network?
I would appreciate any insights in this area.
For example, how does the socket know which network interface (eth0 or wlan0) to send the packet to?
You can use the socket option SO_BINDTODEVICE to bind your socket to a specific interface. Otherwise, the operating system chooses one.
If I am behind a wireless router, should I still fill the IP Source Address of my IP Header with my LAN address (192.168.1.1), or with the internet address (74.125.226.68) of my router?
You should use your LAN address. The router is responsible to take care of NAT (network address translation) if necessary.
If I do fill the IP Source address with my LAN address (192.168.1.1), does the IP Header get changed when it goes through the router, or does it stay that way, so that the receiving end of the packet attempts to send the response to a local host on its network?
If NAT is enabled at the router, the source address is changed to reflect the router's external address. Otherwise, your packages are likely to be dropped by routers or firewalls, because your source address is invalid in their context.

How to connect to a client in Broadband shared IP

I am using a Broadband Router on which multiple pcs use the same shared ip as the public ip. how can some other remote client get a specific IP address to connect to me?
I was developing a Client/Server Chat Program using C.
Thanks for considering.
They cannot. The broadband router is the only one with a public IP address.
The usual solution to this problem is to have the router forward a specific port to one of your NAT'd internal machines.
If that's not sufficient, you could investigate "hole punching" and STUN.

Communicate to public IP from a local network (WinSock, C)

I'm new to this forum (at least at asking questions), so please be patient. I'm trying to write simple client-server applications to communicate using datagram (UDP) sockets, with C and Windows.
The scenario is very simple, I want to be able to send/receive data from a machine in some local network (behind a GATEWAY/NAT) to some host having public IP. I can send the data, but it seems impossible to receive any data back, because the remote server can't see the client's local IP.
I don't want the user to perform manual port forwarding on the GATEWAY, and I also don't want to use UPnP because of security issues (though it also should be enabled by the user).
I think it is possible because applications like Skype or Browsers can do it, but how ?
Are there some automatically forwarded ports or things like that ? I'm exhausted of searching the web ... PLEASE HELP !
For UDP connections, most home NAT gateways will automatically create a temporary reverse mapping for each outbound packet.
Consider a scenario where your client is running on the internal machine with IP address 192.168.4.5, sending a UDP packet from port 65000 to the external address 64.34.119.12:6789, via a gateway with external IP address 192.0.43.10. When the gateway sees your internal client send a UDP packet from 192.168.4.5:65000 to the external address, it will NAT it to an external address and port, like 192.0.43.10:5500. Your server will see a packet with a source address of 192.0.43.10:5500 and destination address 64.34.119.12:6789. The router also sets up a reverse mapping, so that if it sees a packet arrive on the external interface with a source of 64.34.119.12:6789 and a destination of 192.0.43.10:5500, it will redirect it back to 192.168.4.5:65000. This mapping typically times out after a short while.
This means that in simple cases, all you need to do is:
On the client, use the same port to send to the server and listen for responses;
On the server, respond to the client at the address and port that the client's packet was receieved from, using the same server port that recieved the packet;
Have the client send the initial packet in the conversation;
Don't leave the "connection" idle for more than a few minutes at a time.

Mobile IP Addresses

I know that when you hit a page on a site your IP gets logged and the owner can view it.
I've seen it with computers.
There can't possibly be enough IPs to cover all computers and cellphones...
So, since mobiles access by 2G, 3G, 4G, what is the IP that gets registered? Is it like PC accessing?
Do they even generate an IP?
I guess that for Wi-Fi connection they do get an IP, so what about the other signals?
With a 3g service provider you are on their network, so the IP Address will go through a NAT firewall/router and the ip of your device will be their public address such as AT&T.
Much like your home router works. Any computer on your home network will share the IP address of the router.

Resources