<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>Portability Blog (Entries tagged as posix)</title>
    <link>http://portabilityblog.com/blog/</link>
    <description>tales about building software on many platforms</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 1.2.1 - http://www.s9y.org/</generator>
    <managingEditor>df.portabilityblog@erinye.com</managingEditor>
<webMaster>df.portabilityblog@erinye.com</webMaster>
<pubDate>Thu, 20 Dec 2007 12:19:37 GMT</pubDate>

    <image>
        <url>http://portabilityblog.com/blog/templates/default/img/s9y_banner_small.png</url>
        <title>RSS: Portability Blog - tales about building software on many platforms</title>
        <link>http://portabilityblog.com/blog/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>socklen_t confusion</title>
    <link>http://portabilityblog.com/blog/archives/7-socklen_t-confusion.html</link>
            <category>Operating Systems</category>
    
    <comments>http://portabilityblog.com/blog/archives/7-socklen_t-confusion.html#comments</comments>
    <wfw:comment>http://portabilityblog.com/blog/wfwcomment.php?cid=7</wfw:comment>

    <slash:comments>2</slash:comments>
    <wfw:commentRss>http://portabilityblog.com/blog/rss.php?version=2.0&amp;type=comments&amp;cid=7</wfw:commentRss>
    

    <author>nospam@example.com (Daniel Fischer)</author>
    <content:encoded>
    The BSD socket API (accept, bind, and so on) uses a struct sockaddr to pass socket addresses. Additionally, there&#039;s a parameter for passing the size of the memory block allocated for a struct sockaddr to the socket functions. This argument is passed as a pointer to the actual size, and upon completion of the API call, will contain the actual length of the address stored in the memory block instead of its size. In the original BSD API, this argument was of type int *.&lt;br /&gt;
&lt;br /&gt;
At one point, a draft of the POSIX.1g standard defined this to be size_t *. This was a bit broken because size_t is usually not the same type as int on 64-bit platforms, the re-definition thus resulting in an unintended and incompatible change. The short of it is that people complained, and the type was changed again. Instead of reverting to int *, however, a new type socklen_t was introduced. This new type is defined to be the same as int on most platforms. As Linus Torvalds puts it,&lt;br /&gt;
&lt;blockquote&gt;_Any_ sane library _must_ have &quot;socklen_t&quot; be the same size as int. Anything else breaks any BSD socket layer stuff. POSIX initially did make it a size_t, and I (and hopefully others, but obviously not too many) complained to them very loudly indeed. Making it a size_t is completely broken, exactly because size_t very seldom is the same size as &quot;int&quot; on 64-bit architectures, for example. And it has to be the same size as &quot;int&quot; because that&#039;s what the BSD socket interface is.&lt;br /&gt;
&lt;/blockquote&gt;&lt;br /&gt;
(Quote taken from man 2 accept on Linux.)&lt;br /&gt;
&lt;br /&gt;
So for a small period of time, operating system vendors were preparing for POSIX.1g as it was known back then and started to use size_t instead of int. As the draft was changed to use socklen_t, and later SUSv2 included socklen_t, they mostly started to use socklen_t and defined it to int. Some defined it to be the same type as size_t. One example that is mentioned in Linux&#039; man 2 accept is SunOS 5. This includes the current release of Solaris, being based on SunOS 5.10. However, that&#039;s not a &lt;i&gt;big&lt;/i&gt; portability issue. It&#039;s broken as described above, but code that uses socklen_t in all places should be just fine.&lt;br /&gt;
&lt;br /&gt;
On HP-UX, you get the worst of both worlds. On the one hand, you can use the old BSD API with pointers to int. On the other hand, you can define _XOPEN_SOURCE_EXTENDED and get the new API with socklen_t. However, if you don&#039;t define _XOPEN_SOURCE_EXTENDED, you still get a definition of socklen_t to size_t.  The type exists but is completely worthless as it can&#039;t be used with the socket API, which expects int.&lt;br /&gt;
&lt;br /&gt;
I&#039;ve actually seen code that fell over this in both possible ways, using int * in one place and socklen_t * in another...&lt;br /&gt;
 
    </content:encoded>

    <pubDate>Sat, 22 Dec 2007 14:22:00 +0100</pubDate>
    <guid isPermaLink="false">http://portabilityblog.com/blog/archives/7-guid.html</guid>
    <category>hp-ux</category>
<category>posix</category>

</item>

</channel>
</rss>