Re: Modify IP address / Port with a interface filter extension
Re: Modify IP address / Port with a interface filter extension
- Subject: Re: Modify IP address / Port with a interface filter extension
- From: Stephane Sudre <email@hidden>
- Date: Wed, 5 Apr 2006 10:45:12 +0200
On 4 avr. 06, at 21:39, devmaillists wrote:
Hello dear mailing list,
I like to modify a Ethernet packet with a interface filter extension.
The subject of change is the ip destination and port number.
I am not very familiar with the mbuf structures but I am currently
learning. So here come my questions.
Do I have to extract the data of an mbuf int a separate buffer to work
on? Or is looping through the mbuf until I find the right position the
best way.
If I modifiy a byte in the IP data, the CS of the IP Packet and of
the Ethernet packet do have to be recalculated or only the IP CS?
Is there a call doing the recalculation or is it best to recalc it by
my own?
Does anybody have s short sample?
For the IP checksum, if you need it:
u_int16_t ComputeIPChecksum(u_int16_t * buffer,u_int16_t inLength)
{
u_int32_t tChecksum=0;
if ((inLength & 1) == 0)
inLength = inLength >> 1;
else
inLength = (inLength >> 1) + 1;
while (inLength > 0)
{
tChecksum += ntohs(*(buffer));
buffer += 1;
inLength--;
}
tChecksum = (tChecksum >> 16) + (tChecksum & 0xffff);
tChecksum += (tChecksum >> 16);
return(~tChecksum);
}
[...]
struct ip * tIPHeader;
[...]
tIPHeader->ip_sum=0;
tIPHeader->ip_sum=htons(ComputeIPChecksum((u_int16_t *)
tIPHeader,tIPHeader->ip_hl*4));
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden