<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic htons problem with K60?  MQX bug? in MQX Software Solutions</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/htons-problem-with-K60-MQX-bug/m-p/166480#M1618</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;The code htons(&amp;amp;server_address.sin_port, 10000); appears to work on the M52259EVB, but not on the TWR-K60. Both running MQX 3.7 &amp;amp; CW10.1. If I change the code to simply server_address.sin_port = 10000; on the K60, it seems to work. Is this an MQX bug or stupid user error? I'd have thought that if it's the latter, it would have been broken for both processors. The whole point is that it should do the same thing regardless of the endian of the processor, right? John&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 13 Sep 2011 03:29:37 GMT</pubDate>
    <dc:creator>jpa</dc:creator>
    <dc:date>2011-09-13T03:29:37Z</dc:date>
    <item>
      <title>htons problem with K60?  MQX bug?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/htons-problem-with-K60-MQX-bug/m-p/166480#M1618</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;The code htons(&amp;amp;server_address.sin_port, 10000); appears to work on the M52259EVB, but not on the TWR-K60. Both running MQX 3.7 &amp;amp; CW10.1. If I change the code to simply server_address.sin_port = 10000; on the K60, it seems to work. Is this an MQX bug or stupid user error? I'd have thought that if it's the latter, it would have been broken for both processors. The whole point is that it should do the same thing regardless of the endian of the processor, right? John&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Sep 2011 03:29:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/htons-problem-with-K60-MQX-bug/m-p/166480#M1618</guid>
      <dc:creator>jpa</dc:creator>
      <dc:date>2011-09-13T03:29:37Z</dc:date>
    </item>
    <item>
      <title>Re: htons problem with K60?  MQX bug?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/htons-problem-with-K60-MQX-bug/m-p/166481#M1619</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Same problem here.&lt;/P&gt;&lt;P&gt;I'll do further investigation but if somoene has a fix, he/she is welcome.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;edit: Sorry, it was a stupid user error in my case...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;--&amp;nbsp;&lt;/P&gt;&lt;P&gt;Emilien&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Aug 2012 15:07:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/htons-problem-with-K60-MQX-bug/m-p/166481#M1619</guid>
      <dc:creator>emilien</dc:creator>
      <dc:date>2012-08-29T15:07:48Z</dc:date>
    </item>
    <item>
      <title>Re: htons problem with K60?  MQX bug?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/htons-problem-with-K60-MQX-bug/m-p/166482#M1620</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi John,&lt;/P&gt;&lt;P&gt;Something to look at is that ColdFire is big endian and Kinetis is little endian architecture.&lt;/P&gt;&lt;P&gt;I looked at the MQX source and Kinetis htons calls a macro that does byte swapping.&amp;nbsp; Maybe it shouldn't????&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From pcb.h:&lt;/P&gt;&lt;P&gt;#define&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;htons(p, x) { *(uint_16*)(p) = HOST_TO_BE_SHORT(x); }&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From mqx.h:&lt;/P&gt;&lt;P&gt;#if (PSP_ENDIAN == MQX_BIG_ENDIAN)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #define HOST_TO_BE_SHORT(n)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (n)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;--- ColdFire&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;BR /&gt;#else // (PSP_ENDIAN == MQX_BIG_ENDIAN)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #define HOST_TO_BE_SHORT(n)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _PSP_SWAP2BYTE(n)&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;--- Kinetis&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Aug 2012 23:04:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/htons-problem-with-K60-MQX-bug/m-p/166482#M1620</guid>
      <dc:creator>DavidS</dc:creator>
      <dc:date>2012-08-29T23:04:42Z</dc:date>
    </item>
    <item>
      <title>Re: htons problem with K60?  MQX bug?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/htons-problem-with-K60-MQX-bug/m-p/166483#M1621</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;htons means to convert from host to network short. Network is always big endian so if you're on a little endian machine (pretty much everybody these days) it needs to do a conversion. You only need to do conversion of data you're stuffing into TCP/UDP packets (which is really just limited to headers and specific protocols - nothing says your own protocol has to be big endian) so there is no reason to be using htons on the address port assignment since that is being used by the TCP/IP stack which will convert whatever it needs to.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(Edit: Apparently not all TCP/IP stacks do the conversion of address and port numbers for you - it appears the MQX implementation in this regard may be non-standard so if you're working with ported application code you might have to pay close attention to it)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Sep 2012 18:20:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/htons-problem-with-K60-MQX-bug/m-p/166483#M1621</guid>
      <dc:creator>BryGuyH</dc:creator>
      <dc:date>2012-09-11T18:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: htons problem with K60?  MQX bug?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/htons-problem-with-K60-MQX-bug/m-p/166484#M1622</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Guys,&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;This is the feature of RTCS&lt;/STRONG&gt; (not a bug).&lt;/P&gt;&lt;P&gt;server_address.sin_port must be in the Host endian. You should not use htons() for port numbers in the RTCS Socket- API.&lt;/P&gt;&lt;P&gt;I know, it is confusing, especially if you have experience with other TCP/IP stacks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Andrey Butok&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Sep 2012 06:55:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/htons-problem-with-K60-MQX-bug/m-p/166484#M1622</guid>
      <dc:creator>butok</dc:creator>
      <dc:date>2012-09-12T06:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: htons problem with K60?  MQX bug?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/htons-problem-with-K60-MQX-bug/m-p/166485#M1623</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Depends on your perspective - POSIX dictates .sin_port to be network byte order. Because MQX is supposed to be posix compliant it is a deviation from spec and consequently an implementation bug in RTCS on little-endian machines.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ref: IEEE Std 1003.1 2004 &amp;lt;netinet/in.h&amp;gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Sep 2012 15:36:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/htons-problem-with-K60-MQX-bug/m-p/166485#M1623</guid>
      <dc:creator>BryGuyH</dc:creator>
      <dc:date>2012-09-12T15:36:03Z</dc:date>
    </item>
    <item>
      <title>Re: htons problem with K60?  MQX bug?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/htons-problem-with-K60-MQX-bug/m-p/166486#M1624</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You are correct.&lt;/P&gt;&lt;P&gt;But the MQX is not fully POSIX compliant. So this is the feature :smileywink:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is not easy to change it. This approach was used by RTCS from beginning. And changing it will require modification of all existing RTCS applications. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BTW:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Some time ago, I was confused as you and wanted to change it. But it is unreal.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If you still believe that it must be changed, you may try to report it as the bug via a customer-service request.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Andrey Butok&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Sep 2012 07:42:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/htons-problem-with-K60-MQX-bug/m-p/166486#M1624</guid>
      <dc:creator>butok</dc:creator>
      <dc:date>2012-09-13T07:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: htons problem with K60?  MQX bug?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/htons-problem-with-K60-MQX-bug/m-p/166487#M1625</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;sorry to hijack this thread - I had another issue related to htonl or htnos in pcb.h (MQX4)&lt;/P&gt;&lt;P&gt;See the definition here:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#define htonl(p,x) (((uint_8_ptr)(p))[0] = ((x) &amp;gt;&amp;gt; 24) &amp;amp; 0xFF, \&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ((uint_8_ptr)(p))[1] = ((x) &amp;gt;&amp;gt; 16) &amp;amp; 0xFF, \&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ((uint_8_ptr)(p))[2] = ((x) &amp;gt;&amp;gt;&amp;nbsp; 8) &amp;amp; 0xFF, \&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ((uint_8_ptr)(p))[3] =&amp;nbsp; (x)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp; 0xFF, \&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (x))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problem is the MACRO&amp;nbsp; definition - this is not compliant to other system where on Linux for example below(man htonl) and htnol(&amp;amp;x, x) just did not work - I have to use another variable to save x - {int y = x; htnol(&amp;amp;x, y); }&lt;/P&gt;&lt;P&gt;This looks to me just wrong.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NAME&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; htonl, htons, ntohl, ntohs - convert values between host and network byte order&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SYNOPSIS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #include &amp;lt;arpa/inet.h&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t htonl(uint32_t hostlong);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint16_t htons(uint16_t hostshort);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t ntohl(uint32_t netlong);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint16_t ntohs(uint16_t netshort);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Jul 2013 23:40:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/htons-problem-with-K60-MQX-bug/m-p/166487#M1625</guid>
      <dc:creator>David_Wu</dc:creator>
      <dc:date>2013-07-11T23:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: htons problem with K60?  MQX bug?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/htons-problem-with-K60-MQX-bug/m-p/166488#M1626</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are right, htonl(p,x) is not compliant with common API. &lt;/P&gt;&lt;P&gt;I do not know why it was done this way (and probably it should be fixed).&lt;/P&gt;&lt;P&gt;But you can use ntohl(x) that has only one input parameter. I know, it has different purpose but in fact it does the same thing.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Jul 2013 07:42:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/htons-problem-with-K60-MQX-bug/m-p/166488#M1626</guid>
      <dc:creator>butok</dc:creator>
      <dc:date>2013-07-12T07:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: htons problem with K60?  MQX bug?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/htons-problem-with-K60-MQX-bug/m-p/166489#M1627</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;right - then htonl(p, x) should&amp;nbsp; refine as&lt;/P&gt;&lt;P&gt;#define htonl(p) ntohl(p)&lt;/P&gt;&lt;P&gt;how simple is that!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Jul 2013 15:33:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/htons-problem-with-K60-MQX-bug/m-p/166489#M1627</guid>
      <dc:creator>David_Wu</dc:creator>
      <dc:date>2013-07-12T15:33:01Z</dc:date>
    </item>
  </channel>
</rss>

