<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: How to Program raw UDP sockets in C on Linux	</title>
	<atom:link href="https://www.binarytides.com/raw-udp-sockets-c-linux/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.binarytides.com/raw-udp-sockets-c-linux/</link>
	<description>News, Technology, Entertainment and more</description>
	<lastBuildDate>Tue, 14 Sep 2021 14:58:50 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>
	<item>
		<title>
		By: Stefan		</title>
		<link>https://www.binarytides.com/raw-udp-sockets-c-linux/comment-page-1/#comment-324070</link>

		<dc:creator><![CDATA[Stefan]]></dc:creator>
		<pubDate>Tue, 14 Sep 2021 14:58:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/?p=3145#comment-324070</guid>

					<description><![CDATA[Hi madmat, 

Sorry, I think you&#039;re wrong:
You oversee, that a value &#062;0xFFFF can be appear even after the first sum. So the addition of the bits &#062;0xFFFF have to be done twice.
As an example, think about checksum of 0x3FFFF after addition of all bytes to be checksummed.
The first wrap gives you 3 + 0xFFFF = 0x10002, the second wrap gives you 1 + 2 = 0x0003 as final checksum.
This rule is valid for both, IP and UDP.

regards,
Stefan]]></description>
			<content:encoded><![CDATA[<p>Hi madmat, </p>
<p>Sorry, I think you&#8217;re wrong:<br />
You oversee, that a value &gt;0xFFFF can be appear even after the first sum. So the addition of the bits &gt;0xFFFF have to be done twice.<br />
As an example, think about checksum of 0x3FFFF after addition of all bytes to be checksummed.<br />
The first wrap gives you 3 + 0xFFFF = 0x10002, the second wrap gives you 1 + 2 = 0x0003 as final checksum.<br />
This rule is valid for both, IP and UDP.</p>
<p>regards,<br />
Stefan</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: madmat		</title>
		<link>https://www.binarytides.com/raw-udp-sockets-c-linux/comment-page-1/#comment-166638</link>

		<dc:creator><![CDATA[madmat]]></dc:creator>
		<pubDate>Fri, 07 Sep 2018 10:08:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/?p=3145#comment-166638</guid>

					<description><![CDATA[in csum() I found a small error here:

    sum = (sum&#062;&#062;16)+(sum &#038; 0xffff);
    sum = sum + (sum&#062;&#062;16); // this line is useless
I rebuild csum() a little:

uint16_t csum(void *buf,  int cb) 
{
	uint16_t *ptr = (uint16_t *)buf;
	//initialize the sum with the last byte in case of odd size, otherwise to zero
	int32_t sum = (cb&#038;1)?((uint8_t)buf)[cb-1]:0;
	cb/=2;
	while(cb--) sum+=*ptr++;
	return (uint16_t)~((sum&#062;&#062;16)+(sum &#038; 0xffff));
}
sould work the same way]]></description>
			<content:encoded><![CDATA[<p>in csum() I found a small error here:</p>
<p>    sum = (sum&gt;&gt;16)+(sum &amp; 0xffff);<br />
    sum = sum + (sum&gt;&gt;16); // this line is useless<br />
I rebuild csum() a little:</p>
<p>uint16_t csum(void *buf,  int cb)<br />
{<br />
	uint16_t *ptr = (uint16_t *)buf;<br />
	//initialize the sum with the last byte in case of odd size, otherwise to zero<br />
	int32_t sum = (cb&amp;1)?((uint8_t)buf)[cb-1]:0;<br />
	cb/=2;<br />
	while(cb&#8211;) sum+=*ptr++;<br />
	return (uint16_t)~((sum&gt;&gt;16)+(sum &amp; 0xffff));<br />
}<br />
sould work the same way</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: mljli		</title>
		<link>https://www.binarytides.com/raw-udp-sockets-c-linux/comment-page-1/#comment-120646</link>

		<dc:creator><![CDATA[mljli]]></dc:creator>
		<pubDate>Fri, 09 Jun 2017 10:23:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/?p=3145#comment-120646</guid>

					<description><![CDATA[For anyone got UDP checksum error, just swap the order of placeholder and protocol in the pseudo_header struct to match the endianness of your OS.]]></description>
			<content:encoded><![CDATA[<p>For anyone got UDP checksum error, just swap the order of placeholder and protocol in the pseudo_header struct to match the endianness of your OS.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Fatemah Alharbi		</title>
		<link>https://www.binarytides.com/raw-udp-sockets-c-linux/comment-page-1/#comment-75222</link>

		<dc:creator><![CDATA[Fatemah Alharbi]]></dc:creator>
		<pubDate>Wed, 27 Apr 2016 01:23:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/?p=3145#comment-75222</guid>

					<description><![CDATA[Thanks for the code but I keep getting error on my UDP checksum calculation. How can I fix that? The IP checksum is correct though!]]></description>
			<content:encoded><![CDATA[<p>Thanks for the code but I keep getting error on my UDP checksum calculation. How can I fix that? The IP checksum is correct though!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Viktor Przebinda		</title>
		<link>https://www.binarytides.com/raw-udp-sockets-c-linux/comment-page-1/#comment-68062</link>

		<dc:creator><![CDATA[Viktor Przebinda]]></dc:creator>
		<pubDate>Wed, 07 Oct 2015 01:05:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/?p=3145#comment-68062</guid>

					<description><![CDATA[Also agree with Daniel, tcpdump was giving checksum errors until I changed csum to use sizeof (struct iphdr).]]></description>
			<content:encoded><![CDATA[<p>Also agree with Daniel, tcpdump was giving checksum errors until I changed csum to use sizeof (struct iphdr).</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: James		</title>
		<link>https://www.binarytides.com/raw-udp-sockets-c-linux/comment-page-1/#comment-66289</link>

		<dc:creator><![CDATA[James]]></dc:creator>
		<pubDate>Fri, 27 Jun 2014 23:04:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/?p=3145#comment-66289</guid>

					<description><![CDATA[I agree with Daniel, if the data is different as I needed it to be, you must change the code to use this for IP header checksum: iph-&#062;check = csum ((unsigned short *) datagram, sizeof (struct iphdr));]]></description>
			<content:encoded><![CDATA[<p>I agree with Daniel, if the data is different as I needed it to be, you must change the code to use this for IP header checksum: iph-&gt;check = csum ((unsigned short *) datagram, sizeof (struct iphdr));</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Franck Chaillat		</title>
		<link>https://www.binarytides.com/raw-udp-sockets-c-linux/comment-page-1/#comment-65843</link>

		<dc:creator><![CDATA[Franck Chaillat]]></dc:creator>
		<pubDate>Thu, 21 Nov 2013 12:40:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/?p=3145#comment-65843</guid>

					<description><![CDATA[you realy help me so much dude! thanks!]]></description>
			<content:encoded><![CDATA[<p>you realy help me so much dude! thanks!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Silver Moon		</title>
		<link>https://www.binarytides.com/raw-udp-sockets-c-linux/comment-page-1/#comment-56959</link>

		<dc:creator><![CDATA[Silver Moon]]></dc:creator>
		<pubDate>Sat, 20 Oct 2012 05:34:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/?p=3145#comment-56959</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.binarytides.com/raw-udp-sockets-c-linux/comment-page-1/#comment-56949&quot;&gt;Daniel&lt;/a&gt;.

the ip checksum is being calculated like this
iph-&gt;check = csum ((unsigned short *) datagram, iph-&gt;tot_len);

the second parameter is the ip header length which specifies how much of the whole datagram should be used to calculate the checksum, which is only the ip header in this case.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.binarytides.com/raw-udp-sockets-c-linux/comment-page-1/#comment-56949">Daniel</a>.</p>
<p>the ip checksum is being calculated like this<br />
iph->check = csum ((unsigned short *) datagram, iph->tot_len);</p>
<p>the second parameter is the ip header length which specifies how much of the whole datagram should be used to calculate the checksum, which is only the ip header in this case.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Daniel		</title>
		<link>https://www.binarytides.com/raw-udp-sockets-c-linux/comment-page-1/#comment-56949</link>

		<dc:creator><![CDATA[Daniel]]></dc:creator>
		<pubDate>Fri, 19 Oct 2012 21:10:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/?p=3145#comment-56949</guid>

					<description><![CDATA[First of all, you should really change all the comments that say &quot;TCP&quot; to &quot;UDP&quot;. It looks like you&#039;ve just copied some TCP code. Secondly, the IP header checksum is supposed to only sum the IP header itself, whereas in your code it sums the entire datagram. This may still work, but only because the rest of the datagram is set to 0. To do it correctly, you should only sum the length of the IP header.]]></description>
			<content:encoded><![CDATA[<p>First of all, you should really change all the comments that say &#8220;TCP&#8221; to &#8220;UDP&#8221;. It looks like you&#8217;ve just copied some TCP code. Secondly, the IP header checksum is supposed to only sum the IP header itself, whereas in your code it sums the entire datagram. This may still work, but only because the rest of the datagram is set to 0. To do it correctly, you should only sum the length of the IP header.</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
