AgentSmithers
August 11th, 2009, 01:04 PM
Hello, I'm writing a Application that Forwards packet's from one IP to the next using my Suse Box basically like a Proxy, I created a PF_PACKET, SOCK_RAW, ETH_P_ALL socket then use Recvfrom(Socket,buffer,BufferSize,NULL,NULL) to then recv all the information rewrite the Buffer with the new Forwarding address then using SentTo to send it off so it gets forwarded.
Now everything works like a charm but I believe even the packets that are not being sent from the specific IP that im really looking for I'm still overwriting it then passing it alone, I believe I need to fill in the RecvFrom Nulls with the correct information but the examples I see define a Layer4 Port in the structure, How can I make it so if the Packet = Layer3(IP) then forwarded it so it will forward all packets that come from that IP regardless of the PORT, Or should I look for a Layer2(MAC ADDRESS) then forward by that? But Do I really want to forward ICMP packets Etc Etc?? It appears when overwritting the Layer2 Mac with the correct source then sending it the router then returns the packet to the computer in the middle and not the computer who originally created the packet. Any Ideas?
Another Simple Question. I got a Char Array of bytes
How do I compare two bytes at once
say I got the Values
char * MycharArray = 0x01 0x02 0x03 0x04 0x05 0x06 0x07
and I check at a pointer in the middle for 0x0304
I tryed casting like so to compare two bytes at once but failed =(
if (int(MycharArray + 4)) = 0x0405
{
}
Any Ideas?
Now everything works like a charm but I believe even the packets that are not being sent from the specific IP that im really looking for I'm still overwriting it then passing it alone, I believe I need to fill in the RecvFrom Nulls with the correct information but the examples I see define a Layer4 Port in the structure, How can I make it so if the Packet = Layer3(IP) then forwarded it so it will forward all packets that come from that IP regardless of the PORT, Or should I look for a Layer2(MAC ADDRESS) then forward by that? But Do I really want to forward ICMP packets Etc Etc?? It appears when overwritting the Layer2 Mac with the correct source then sending it the router then returns the packet to the computer in the middle and not the computer who originally created the packet. Any Ideas?
Another Simple Question. I got a Char Array of bytes
How do I compare two bytes at once
say I got the Values
char * MycharArray = 0x01 0x02 0x03 0x04 0x05 0x06 0x07
and I check at a pointer in the middle for 0x0304
I tryed casting like so to compare two bytes at once but failed =(
if (int(MycharArray + 4)) = 0x0405
{
}
Any Ideas?