<div dir="ltr">Does anybody know how to get all the ip addresses from linux kernel? I can google some code that runs in user mode. But not in kernel.<div><br></div><div><div>    s = socket(AF_INET, SOCK_STREAM, 0);</div><div>
    if(s &lt; 0)</div><div>    {</div><div>       printf(&quot;socket screwup\n&quot;);</div><div>       exit(1);</div><div>    }</div><div>    memset(&amp;ifr, 0, sizeof(ifr));</div><div>    ifc.ifc_len = sizeof(buff);</div>
<div>    ifc.ifc_buf = buff;</div><div>    if(ioctl(s, SIOCGIFCONF, &amp;ifc) &lt; 0)</div><div>    {</div><div>        printf(&quot;SIOCGIFCONF screwed up\n&quot;);</div><div>        exit(1);</div><div>    }</div><div>    pifr = (struct ifreq *)(ifc.ifc_req);</div>
<div>    for(i = ifc.ifc_len / sizeof(struct ifreq); --i &gt;= 0; pifr++)</div><div>    {</div><div>        strcpy(ifr.ifr_name, pifr-&gt;ifr_name);    //eth0 eth1 ...</div><div>        if(ioctl(s, SIOCGIFADDR, &amp;ifr) &lt; 0)</div>
<div>        {</div><div>            printf(&quot;ip screwed up\n&quot;);</div><div>            exit(1);</div><div>        }</div><div>        memcpy(ip, ifr.ifr_addr.sa_data+2, 4);</div><div>        printf(&quot;%s\n&quot;,inet_ntoa(*(struct in_addr *)ip));</div>
<div>    }</div></div></div>