title: segmentation fault for inet_ntoa
body: <pre><code>    #include &lt;stdio.h&gt; 
      #include &lt;string.h&gt; /* for strncpy */ 
      #include &lt;sys/types.h&gt; 
      #include &lt;sys/socket.h&gt; 
      #include &lt;sys/ioctl.h&gt; 
      #include &lt;netinet/in.h&gt; 
      #include &lt;net/if.h&gt; 
  
      int 
      main() 
      { 
       int fd;  
       struct ifreq ifr; 
  
       fd = socket(AF_INET, SOCK_DGRAM, 0);  
  
       /* I want to get an IPv4 IP address */ 
       ifr.ifr_addr.sa_family = AF_INET; 
  
       /* I want IP address attached to "eth0" */ 
       strncpy(ifr.ifr_name, "eth0", IFNAMSIZ-1); 
  
       ioctl(fd, SIOCGIFADDR, &amp;ifr); 
  
       close(fd); 
  
       /* display result */ 
       char* ipaddr; 
       ipaddr = inet_ntoa(((struct sockaddr_in *)&amp;(ifr.ifr_addr))-&gt;sin_addr); 
       printf("%s\n", ipaddr); 
  
       return 0; 
      } 
  </code></pre>
  
  <p>for this line:</p>
  
  <pre><code>     ipaddr = inet_ntoa(((struct sockaddr_in *)&amp;(ifr.ifr_addr))-&gt;sin_addr);         
  </code></pre>
  
  <p>I get</p>
  
  <pre><code>iptry.c: In function ‘main’:
  iptry.c:31:9: warning: assignment makes pointer from integer without a cast [enabled by default]
  </code></pre>
  
  <p>and for            </p>
  
  <pre><code>     printf("%s\n", ipaddr);
  </code></pre>
  
  <p>I get segmentation fault.</p>
  
  <p>What is wrong with this?</p>