Re: Modify IP address / Port with a interface filter extension
site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com 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. 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; [...] _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... 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? tIPHeader->ip_sum=0; tIPHeader->ip_sum=htons(ComputeIPChecksum((u_int16_t *) tIPHeader,tIPHeader->ip_hl*4)); This email sent to site_archiver@lists.apple.com
participants (1)
-
Stephane Sudre