# How to read and write ip packets



## Palla (Jan 11, 2010)

Hi to all!
I'm an Informatics Engineering student and I work into the networking Laboratory.
This is my problem:
I have a FreeBSD Computer in LAN with ather computer give web services.
I must develop an application that take an ip packet, rewrite an ip header and resend the new ip packet.

I found this web page where is learning how to use BPF to read ip packet.
Have you got other guide or advices (or the problem solution ) to help me?


----------



## SirDice (Jan 11, 2010)

http://lmgtfy.com/?q=socket+programming


----------



## expl (Jan 11, 2010)

SirDice said:
			
		

> http://lmgtfy.com/?q=socket+programming



Capturing and sending (your own formated packets) has nothing to do with sockets or their programming.



			
				Palla said:
			
		

> Hi to all!
> I'm an Informatics Engineering student and I work into the networking Laboratory.
> This is my problem:
> I have a FreeBSD Computer in LAN with ather computer give web services.
> ...



Well the link you linked yourself pretty much covers the mechanics of capturing/sending the packets via BPF mechanism that is very nice way to do it without writing your own kernel module. What other information are you missing?


----------



## Palla (Jan 11, 2010)

expl said:
			
		

> Capturing and sending (your own formated packets) has nothing to do with sockets or their programming.
> 
> 
> 
> Well the link you linked yourself pretty much covers the mechanics of capturing/sending the packets via BPF mechanism that is very nice way to do it without writing your own kernel module. What other information are you missing?



I'm not a FreeBSD user, so I would like to have some "ok" aboute the document I have linked.

Thank for your help


----------



## expl (Jan 11, 2010)

Well I am not sure what are you asking, but yes this would be most simple and correct way to do your assignment.


----------



## J65nko (Jan 11, 2010)

As far as I understand packet filters like pf and ipfw, which do Network Address/Port Translation (NAT/PAT) also rewrite packets. You could look at the source code how they exactly do it.


----------



## expl (Jan 11, 2010)

J65nko said:
			
		

> As far as I understand packet filters like pf and ipfw, which do Network Address/Port Translation (NAT/PAT) also rewrite packets. You could look at the source code how they exactly do it.



They have their own custom kernel modules. I do not think thats a solution for a small assignment.


----------



## danger@ (Jan 11, 2010)

Some pcap features might help you too...


----------

