Re: Changing the source IP of outgoing UDP packets on a socket

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Kashif Shaikh wrote:
> Hello,
>
> I have a multi-homed host with two interfaces: eth0: 10.0.0.1 and a
> virtual interface eth0:0 10.0.0.101. What I'm trying to do is send a
> broadcast packet to 10.0.0.255 using the virtual IP as the source
> address(since both IPs are on the same network).
>
> Currently, when I create the destination broadcast socket and send some
> data, tcpdump shows the source IP to be 10.0.0.1.  But I need the source
> IP to be 10.0.0.101!

You don't have to 'change the source IP of packets'... you want the packets to 
be created with a specific source address.

Just be sure to call bind() on the socket before you send UDP packets.  There 
you specify the local address used (that's why it's called "bind to that 
address").  Most programs use INADDR_ANY for the local address, since it 
means the socket can hear on any interface.   It's undefined what address it 
would use for transmission; but users don't care about that.

Since it's not your case, specify the correct local address on bind().

- ------
Javier
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+NyYRsIoGnxsRK/ERAkGMAJ9mz23sIPsfzu3l5CQ8LLJ0g0bvdACfVyYA
49C07GxOj/1z2FVaL+xHfcU=
=ROyR
-----END PGP SIGNATURE-----

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux