Networking Forums

Networking Forums > Computer Networking > Linux Networking > Sending raw ip on multihomed host

Reply
Thread Tools Display Modes

Sending raw ip on multihomed host

 
 
Robin
Guest
Posts: n/a

 
      02-10-2004, 05:04 PM
This is a "getlocaladdr" problem.

I've implemented a "virtual applikation server" that will take packets and
send them to another host based on port numbers, thus working as both
client and server to make a session work (like a man in the middle)..

The problem is to support this funktionality on a multihomed host (a host
with more than one network card).. since I don't know what source address
to use when sending packets.

I'm using a raw socket like this for sending:
m_sock = socket(PF_INET, SOCK_RAW, htons(IPPROTO_RAW));
// -------------> Also tried AF_INET
const int on = 1;
setsockopt(m_sock, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on));

According to man page the following holds for raw sockets with IP_HDRINCL
+------------------------------------------------------------------+
|IP Header fields modified on sending when IP_HDRINCL is specified |
+------------------------------------------------------------------+
| Sending fragments with IP_HDRINCL is not supported currently. |
+--------------------------+---------------------------------------+
|IP Checksum |Always filled in. |
+--------------------------+---------------------------------------+
|Source Address |Filled in when zero. |
+--------------------------+---------------------------------------+
|Packet Id |Filled in when passed as 0. |
+--------------------------+---------------------------------------+
|Total Length |Always filled in. |
+--------------------------+---------------------------------------+

But the kernel don't fill in the source when i zero it out in the header.
I'm using the following sendto.

sockaddr_in toAddr = packet.getDestinationHost();
toAddr.sin_family = AF_INET;
return sendto(m_sock,
(void *) packet.getBuffer(), /* "const void* msg" */
packet.get_ip_len(),
0,
(sockaddr *) &toAddr,
sizeof(struct sockaddr_in)); /* "socklen_t tolen" */

It works fine when I specify the correct source address in the packet so I
must be doing atleast some of it right..

I zero it out like this...

in_addr sourceAddr;
bzero(&sourceAddr, sizeof(in_addr));
_packet.set_ip_src(sourceAddr);

but the address wont be filled in after send... I guess that I actually send
a packet with source address = 0.0.0.0

I would be so very happy if someone could point out what I'm doing wrong or
help me in some other way to dynamicly find out the correct source IP based
on the destination address..
I've considered to just send the packet out on all networks just to be safe
but that just doesn't seem right.

I'm using Mandrake 9.0: Kernel 2.4.19(Patched with IPDIVERT); Glibc 2.2.5

Thanks
 
Reply With Quote
 
 
 
 
Cameron Kerr
Guest
Posts: n/a

 
      02-11-2004, 06:56 AM
Robin <(E-Mail Removed)> wrote:
> This is a "getlocaladdr" problem.
>
> I've implemented a "virtual applikation server" that will take packets and
> send them to another host based on port numbers, thus working as both
> client and server to make a session work (like a man in the middle)..


You know about the Linux Virtual Server component of 2.6 kernels?

> The problem is to support this funktionality on a multihomed host (a host
> with more than one network card).. since I don't know what source address
> to use when sending packets.


Follow this psuedocode:

for every network device that is UP:
create a socket for this device
store the devices source address
add it to a list of sockets to select on.
select on all of the sockets waiting for readablity
use the stored address for the source address.

Alternatively, you may be able to use recvmsg and sendmsg, but I don't
know if that would work with raw IP

--
Cameron Kerr
(E-Mail Removed) : http://nzgeeks.org/cameron/
Empowered by Perl!
 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IPv4 host behind NAT talking to IPv6 host Noob Linux Networking 8 07-28-2011 10:34 PM
Problem with NTLM2 on multihomed host Peter Skvarka Windows Networking 2 08-26-2006 05:59 AM
Host-to-host connection in wireless adhoc network? Tim Boneko Linux Networking 0 08-17-2005 05:28 PM
Linux<->Windows connection using USB host-to-host cable =?iso-8859-2?Q?Rados=B3aw?= Grzanka Linux Networking 0 04-10-2004 03:23 PM
Access to public host from private host through Linux router Santanu Chatterjee Linux Networking 5 11-14-2003 11:57 PM



1 2 3 4 5 6 7 8 9 10 11