1

How to find the default Default IP Address if my I am connected to more than one network? I found one link

http://libtins.github.io/tutorial/sending/

But In "Sending network layer PDUs" It is written that

PacketSender sender;

IP pkt = IP("192.168.0.1") / TCP(22) / RawPDU("foo"); sender.send(pkt);

Note that no source address was specified in the IP constructor. This uses by default the address 0.0.0.0. However, when sending network layer PDUs, if the source address is 0.0.0.0, the PDU will perform a lookup on the routing table to find out which should be the source address and automatically sets it.

So, Is there any way to find the source address using c++?

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
sk110
  • 11
  • 1
  • 2

1 Answers1

1

Once you connect the socket, you can call getsockname on it to find out the local IP address.

David Schwartz
  • 31,449
  • 2
  • 55
  • 84