<?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 socket ioctl help in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/socket-ioctl-help/m-p/2658070#M590792</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I am getting a "reinterpret_cast" warning while compiling the following&lt;BR /&gt;C++ program. In the program I am making socket ioctl call to get the&lt;BR /&gt;network mask. &lt;BR /&gt;&lt;BR /&gt;Looks like there is no way I can get over this warning, the "ifreq"&lt;BR /&gt;structure has no member of type "sockaddr_in". Is there anything wrong&lt;BR /&gt;that I am doing here which gives out this warning ?&lt;BR /&gt;&lt;BR /&gt;$ aCC -AA main1.C &lt;BR /&gt;Warning 749: "main1.C", line 24 # The cast from 'sockaddr *' to&lt;BR /&gt;'sockaddr_in&lt;BR /&gt;    *' is performed as a 'reinterpret_cast'. This operation is&lt;BR /&gt;non-portable&lt;BR /&gt;    and potentially unsafe.&lt;BR /&gt;             s_addr = (struct sockaddr_in *)(&amp;amp;ifr.ifr_addr);&lt;BR /&gt;                      ^^^^^^^^^^^^^^^^^^^^^^                &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Program:&lt;BR /&gt;--------&lt;BR /&gt;&lt;BR /&gt;#include&lt;IOSTREAM&gt;&lt;BR /&gt;using namespace std;&lt;BR /&gt;&lt;BR /&gt;#include&lt;SYS&gt;&lt;BR /&gt;#include&lt;NET&gt;&lt;BR /&gt;#include&lt;SYS&gt;&lt;BR /&gt;#include&lt;UNISTD.H&gt;&lt;BR /&gt;#include&lt;NETINET&gt;&lt;BR /&gt;#include&lt;ARPA&gt;&lt;BR /&gt;&lt;BR /&gt;int main(){&lt;BR /&gt;&lt;BR /&gt;   struct ifreq ifr;&lt;BR /&gt;   int skfd;&lt;BR /&gt;   struct sockaddr_in *s_addr;&lt;BR /&gt;&lt;BR /&gt;   // open system socket&lt;BR /&gt;   if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) &amp;gt;= 0)&lt;BR /&gt;   {&lt;BR /&gt;      strcpy(ifr.ifr_name, "lan0");&lt;BR /&gt;      if (ioctl(skfd, SIOCGIFNETMASK, &amp;amp;ifr) &amp;gt;= 0)&lt;BR /&gt;      {&lt;BR /&gt;         s_addr = (struct sockaddr_in *)(&amp;amp;ifr.ifr_addr);&lt;BR /&gt;         cout&amp;lt;&amp;lt;"Network mask is "&amp;lt;&lt;INET_NTOA&gt;sin_addr)&amp;lt;&lt;ENDL&gt;&lt;/ENDL&gt;      }&lt;BR /&gt;&lt;BR /&gt;      close(skfd);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;regards,&lt;/INET_NTOA&gt;&lt;/ARPA&gt;&lt;/NETINET&gt;&lt;/UNISTD.H&gt;&lt;/SYS&gt;&lt;/NET&gt;&lt;/SYS&gt;&lt;/IOSTREAM&gt;</description>
    <pubDate>Mon, 04 Feb 2002 11:41:41 GMT</pubDate>
    <dc:creator>Prakash Achuthan</dc:creator>
    <dc:date>2002-02-04T11:41:41Z</dc:date>
    <item>
      <title>socket ioctl help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/socket-ioctl-help/m-p/2658070#M590792</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I am getting a "reinterpret_cast" warning while compiling the following&lt;BR /&gt;C++ program. In the program I am making socket ioctl call to get the&lt;BR /&gt;network mask. &lt;BR /&gt;&lt;BR /&gt;Looks like there is no way I can get over this warning, the "ifreq"&lt;BR /&gt;structure has no member of type "sockaddr_in". Is there anything wrong&lt;BR /&gt;that I am doing here which gives out this warning ?&lt;BR /&gt;&lt;BR /&gt;$ aCC -AA main1.C &lt;BR /&gt;Warning 749: "main1.C", line 24 # The cast from 'sockaddr *' to&lt;BR /&gt;'sockaddr_in&lt;BR /&gt;    *' is performed as a 'reinterpret_cast'. This operation is&lt;BR /&gt;non-portable&lt;BR /&gt;    and potentially unsafe.&lt;BR /&gt;             s_addr = (struct sockaddr_in *)(&amp;amp;ifr.ifr_addr);&lt;BR /&gt;                      ^^^^^^^^^^^^^^^^^^^^^^                &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Program:&lt;BR /&gt;--------&lt;BR /&gt;&lt;BR /&gt;#include&lt;IOSTREAM&gt;&lt;BR /&gt;using namespace std;&lt;BR /&gt;&lt;BR /&gt;#include&lt;SYS&gt;&lt;BR /&gt;#include&lt;NET&gt;&lt;BR /&gt;#include&lt;SYS&gt;&lt;BR /&gt;#include&lt;UNISTD.H&gt;&lt;BR /&gt;#include&lt;NETINET&gt;&lt;BR /&gt;#include&lt;ARPA&gt;&lt;BR /&gt;&lt;BR /&gt;int main(){&lt;BR /&gt;&lt;BR /&gt;   struct ifreq ifr;&lt;BR /&gt;   int skfd;&lt;BR /&gt;   struct sockaddr_in *s_addr;&lt;BR /&gt;&lt;BR /&gt;   // open system socket&lt;BR /&gt;   if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) &amp;gt;= 0)&lt;BR /&gt;   {&lt;BR /&gt;      strcpy(ifr.ifr_name, "lan0");&lt;BR /&gt;      if (ioctl(skfd, SIOCGIFNETMASK, &amp;amp;ifr) &amp;gt;= 0)&lt;BR /&gt;      {&lt;BR /&gt;         s_addr = (struct sockaddr_in *)(&amp;amp;ifr.ifr_addr);&lt;BR /&gt;         cout&amp;lt;&amp;lt;"Network mask is "&amp;lt;&lt;INET_NTOA&gt;sin_addr)&amp;lt;&lt;ENDL&gt;&lt;/ENDL&gt;      }&lt;BR /&gt;&lt;BR /&gt;      close(skfd);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;regards,&lt;/INET_NTOA&gt;&lt;/ARPA&gt;&lt;/NETINET&gt;&lt;/UNISTD.H&gt;&lt;/SYS&gt;&lt;/NET&gt;&lt;/SYS&gt;&lt;/IOSTREAM&gt;</description>
      <pubDate>Mon, 04 Feb 2002 11:41:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/socket-ioctl-help/m-p/2658070#M590792</guid>
      <dc:creator>Prakash Achuthan</dc:creator>
      <dc:date>2002-02-04T11:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: socket ioctl help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/socket-ioctl-help/m-p/2658071#M590793</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Your cast is legal; aCC is just concerned your code may be non-portable.  I have three suggestions to make the warning go away:&lt;BR /&gt;&lt;BR /&gt;1) See if aCC prefers you use "reinterpret_cast&lt;STRUCT sockaddr_in=""&gt;" over the C-style cast "(struct sockaddr_in *)".  It may be that aCC thinks you don't realize it is a reinterpret_cast.&lt;BR /&gt;&lt;BR /&gt;2) See if aCC supports a means of disabling certain warnings, such as through #pragma.&lt;BR /&gt;&lt;BR /&gt;3) Finally, there is always the compiler option to disable all warnings (this has obvious disadvantages).  It may be different with aCC, but the switch is usually -w.&lt;BR /&gt;&lt;BR /&gt;For what it's worth, your code compiles without error under g++, even with the -Wall option.&lt;BR /&gt;&lt;BR /&gt;Best of luck to you :)&lt;/STRUCT&gt;</description>
      <pubDate>Mon, 04 Feb 2002 13:50:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/socket-ioctl-help/m-p/2658071#M590793</guid>
      <dc:creator>Jason Deckard</dc:creator>
      <dc:date>2002-02-04T13:50:23Z</dc:date>
    </item>
  </channel>
</rss>

