<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 9pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class='hmmessage'>
Hi, all, this is code of calculation udp checksum.<br><br>http://www.gilgil.co.kr/snoop/<br><br>//<br>// All UDPHdr field except UDPHdr.Checksum<br>// IPHdr.Source, IPHdr.Destination, UDPHdrLen<br>//<br>function snoopUDPChecksum(IPHdr: PIP_HDR; UDPHdr: PUDP_HDR): UINT16;<br>var<br> i: Integer;<br> UDPHdrLen: Integer;<br> Source, Destination: UINT32;<br> Sum: UINT32;<br> p: PUINT16;<br>begin<br> UDPHdrLen := ntohs(UDPHdr.Len);<br> Sum := 0;<br><br> // Add UDPHdr and Data Buffer as array of UINT16<br> p := PUINT16(UDPHdr);<br> for i := 0 to UDPHdrLen div 2 - 1 do<br> begin<br> Sum := Sum + htons(p^);<br> inc(p);<br> end;<br><br> // if Len is OddNumber, Add Last Data<br> if (UDPHdrLen div 2) * 2 <> UDPHdrLen then<br> Sum := Sum + (htons(p^) and $FF00);<br><br> // Decrease Checksum from Sum<br> Sum := Sum - ntohs(UDPHdr.Checksum);<br><br> // Add Source Address<br> Source := ntohl(IPHdr.Source);<br> Sum := Sum + ((Source and $FFFF0000) shr 16) + (Source and $0000FFFF);<br><br> // Add Destination Addres<br> Destination := ntohl(IPHdr.Destination);<br> Sum := Sum + ((Destination and $FFFF0000) shr 16) + (Destination and $0000FFFF);<br><br> // Add Extra Information<br> Sum := Sum + PROTO_UDP + UINT32(UDPHdrLen);<br><br> // Recalculate Sum<br> while (Sum shr 16) > 0 do<br> Sum := (Sum and $FFFF) + (Sum shr 16);<br> Sum := not Sum;<br><br> Result := UINT16(Sum);<br>end;<br><br><hr>From: gianluca.varenni@cacetech.com<br>To: winpcap-users@winpcap.org<br>Subject: Re: [Winpcap-users] UDP Checksum<br>Date: Tue, 19 Aug 2008 13:12:32 -0700<br><br>
<meta http-equiv="Content-Type" content="text/html; charset=unicode">
<meta name="Generator" content="Microsoft SafeHTML">
<style>
@page Section1
{size:8.5in 11.0in;}
.ExternalClass P.EC_MsoNormal
{font-size:11pt;font-family:'Calibri','sans-serif';}
.ExternalClass LI.EC_MsoNormal
{font-size:11pt;font-family:'Calibri','sans-serif';}
.ExternalClass DIV.EC_MsoNormal
{font-size:11pt;font-family:'Calibri','sans-serif';}
.ExternalClass A:link
{color:blue;text-decoration:underline;}
.ExternalClass SPAN.EC_MsoHyperlink
{color:blue;text-decoration:underline;}
.ExternalClass A:visited
{color:purple;text-decoration:underline;}
.ExternalClass SPAN.EC_MsoHyperlinkFollowed
{color:purple;text-decoration:underline;}
.ExternalClass P.EC_MsoAcetate
{font-size:8pt;font-family:'Tahoma','sans-serif';}
.ExternalClass LI.EC_MsoAcetate
{font-size:8pt;font-family:'Tahoma','sans-serif';}
.ExternalClass DIV.EC_MsoAcetate
{font-size:8pt;font-family:'Tahoma','sans-serif';}
.ExternalClass SPAN.EC_EmailStyle17
{color:windowtext;font-family:'Calibri','sans-serif';}
.ExternalClass SPAN.EC_BalloonTextChar
{font-family:'Tahoma','sans-serif';}
.ExternalClass .EC_MsoChpDefault
{;}
.ExternalClass DIV.EC_Section1
{page:Section1;}
</style>
<div><font size="2">I would have a look at</font></div>
<div><font size="2">- the tcpdump source code</font></div>
<div><font size="2">- the wireshark source code</font></div>
<div><font size="2"></font> </div>
<div><font size="2">Have a nice day</font></div>
<div><font size="2">GV</font></div>
<blockquote style="border-left: 2px solid rgb(0, 0, 0); padding-right: 0px; padding-left: 5px; margin-left: 5px; margin-right: 0px;">
<div style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">----- Original Message ----- </div>
<div style="background: rgb(228, 228, 228) none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><b>From:</b>
<a title="sandeep.gangadharan@hp.com" href="mailto:sandeep.gangadharan@hp.com">Gangadharan, Sandeep</a> </div>
<div style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><b>To:</b> <a title="winpcap-users@winpcap.org" href="mailto:winpcap-users@winpcap.org">winpcap-users@winpcap.org</a> </div>
<div style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><b>Sent:</b> Tuesday, August 19, 2008 4:01
AM</div>
<div style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><b>Subject:</b> [Winpcap-users] UDP
Checksum</div>
<div><br></div>
<div class="EC_Section1">
<p class="EC_MsoNormal">Anyone has a sample code to do udp checksum calculation?
<span style="color: rgb(31, 73, 125);"></span></p>
<p class="EC_MsoNormal"> </p></div>
<BR><hr>
<BR>_______________________________________________<br>Winpcap-users
mailing list<br><a href="mailto:Winpcap-users@winpcap.org">Winpcap-users@winpcap.org</a><br><a href="https://www.winpcap.org/mailman/listinfo/winpcap-users" target="_blank">https://www.winpcap.org/mailman/listinfo/winpcap-users</a><br></blockquote>
</body>
</html>