How to modify source ip address of an incoming udp packge which is sent by row socket from local

Hi all,

I have some trouble in modifing source ip address of an incoming udp packet which is sent by row socket from localhost.

I have added a filter on FWPM_LAYER_INBOUND_TRANSPORT_V4 layer and the filter did catch the packet. But when I get the pointer of IP header of UDP header and watch them in Windbg, It seems that many fields of IP header ( such as checksum, ttl) are zero and many fields of UDP header( such as checksum, src port, dst port) also are zero. I have changed the source ip address (without calculate IP header checksum and UDP header checksum) and reinjected it to tcp/ip stack. But my UDP client can't not receive the modified packet. What the problem?

In addition, my code works well if the udp packet is sent by normal socket. In this case, the filelds of IP header and UDP header both right. And I recalculate the checksum of IP header and UDP header after modify the packet.

Are there some special measure should be take when filtering raw socket?

Thank you!

[1033 byte] By [anylin] at [2008-1-26]
# 1

So you are doing a loopback send correct (e.g. destination address is 127.0.0.1)? If yes, is the receiving UDP socket also a raw socket?

It appears that the packet sent from the RAW socket is not correclty formed. For raw sends, the tcpip stack is not going to fill out the ports (nor checksum) so the packet needs to be crafted with the correct ports etc.

You can check the "Status" field of the net buffer list from your completion function. I am guessing the error is "port unreachable" or something of that nature.

Hope this helps,

Biao.W.

BiaoWang[MSFT] at 2007-9-28 > top of Msdn Tech,Windows Networking Development,Windows Filtering Platform (WFP)...
# 2

Yes, you are right. The packet sent from the RAW socket is not correclty formed! I have fixed this problem.

Thanks Biao!

anylin at 2007-9-28 > top of Msdn Tech,Windows Networking Development,Windows Filtering Platform (WFP)...