Hi Martin,<div><br></div><div>A simple way might be:</div><div><br></div><div><div> char name[MAXHOSTNAMELEN];</div><div><div> struct sockaddr_in addr;</div></div><div><br></div><div> gethostname(name,sizeof(name));</div>
<div><br></div><div> struct hostent *hostEntry=0;</div><div><div> struct in_addr ia;</div><div><br></div><div> // From the Unix network FAQ (<a href="http://www.unixguide.net/network/socketfaq/">www.unixguide.net/network/socketfaq/</a>)</div>
<div> // First try it as aaa.bbb.ccc.ddd.</div><div> ia.s_addr=inet_addr(name);</div><div> if(ia.s_addr!=INADDR_NONE)</div><div> {</div><div> // Got it...</div><div> addr.sin_addr.s_addr=ia.s_addr;</div><div> return TRUE;</div>
<div> }</div><div> // Next, try just gethostbyname()</div><div> hostEntry=gethostbyname(name);</div><div> if(hostEntry)</div><div> {</div><div> addr.sin_addr.s_addr=*(int*)hostEntry->h_addr_list[0];</div><div> return TRUE;</div>
<div> }</div><div> </div><div> if(!hostEntry)</div><div> {</div><div> qnError("QNAddress:GetByName(%s) failed",name);</div><div> return FALSE;</div><div> }</div><div> // Retrieve address (IPv4)</div>
<div> addr.sin_addr.s_addr=*(int*)hostEntry->h_addr_list[0];</div><div><br></div></div><div>May require some tuning to your code context.</div><div><br></div><div>Cheers,</div><div>Ruud</div><br><div class="gmail_quote">
On Wed, Sep 19, 2012 at 4:02 PM, Martin Zemblowski <span dir="ltr"><<a href="mailto:martin@bigheadgames.co.uk" target="_blank">martin@bigheadgames.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Is there any simple way in enet to get local ip of pc running the code (ie 192.168.1.10) ?<br>
Regards<br>
<br>
______________________________<u></u>_________________<br>
ENet-discuss mailing list<br>
<a href="mailto:ENet-discuss@cubik.org" target="_blank">ENet-discuss@cubik.org</a><br>
<a href="http://lists.cubik.org/mailman/listinfo/enet-discuss" target="_blank">http://lists.cubik.org/<u></u>mailman/listinfo/enet-discuss</a><br>
</blockquote></div><br></div>