<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Winsock, lokale ip adresse]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe einen Server geschrieben und alles klappt perfekt. Nun möchte ich verhindern, dass sich ein lokaler Client zu diesem verbindet. Wie kann ich also die lokale IP Adresse(192.168....) herausfinden? Ich nutze Winsock.</p>
<p>Danke,<br />
Sockee</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/226865/winsock-lokale-ip-adresse</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 09:23:45 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/226865.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 06 Nov 2008 19:06:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Winsock, lokale ip adresse on Thu, 06 Nov 2008 19:06:52 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe einen Server geschrieben und alles klappt perfekt. Nun möchte ich verhindern, dass sich ein lokaler Client zu diesem verbindet. Wie kann ich also die lokale IP Adresse(192.168....) herausfinden? Ich nutze Winsock.</p>
<p>Danke,<br />
Sockee</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1611456</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1611456</guid><dc:creator><![CDATA[Sockee]]></dc:creator><pubDate>Thu, 06 Nov 2008 19:06:52 GMT</pubDate></item><item><title><![CDATA[Reply to Winsock, lokale ip adresse on Thu, 06 Nov 2008 20:03:30 GMT]]></title><description><![CDATA[<p>getpeername</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1611481</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1611481</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Thu, 06 Nov 2008 20:03:30 GMT</pubDate></item><item><title><![CDATA[Reply to Winsock, lokale ip adresse on Thu, 06 Nov 2008 20:27:44 GMT]]></title><description><![CDATA[<p>Im Prinzip bräuchte ich nur eine Funktion, die mir die lokale IP-Adresse vom Computer ausgibt, auf dem das Programm gerade ausgeführt wird.</p>
<pre><code>IF (MEINE_IP != AKTUELLE_IP)
 connect(AKTUELLE_IP, ...);
ELSE
 NOTHING
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1611493</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1611493</guid><dc:creator><![CDATA[Sockee]]></dc:creator><pubDate>Thu, 06 Nov 2008 20:27:44 GMT</pubDate></item><item><title><![CDATA[Reply to Winsock, lokale ip adresse on Thu, 06 Nov 2008 20:40:44 GMT]]></title><description><![CDATA[<p>Is copy&amp;paste aus 3 Jahre alten Notizen:</p>
<pre><code class="language-cpp">unsigned long longToIp(const char* szIp)
{
	int octets[4];
	const char* auxCad = szIp;
	unsigned long lIp = 0; 

	for(int i = 0; i &lt; 4; ++i)
	{
		octets[i] = atoi(auxCad);

		if(octets[i] &lt; 0 || octets[i] &gt; 255)
			return 0;

		lIp |= (octets[i] &lt;&lt; (i * 8));

		auxCad = strchr(auxCad, '.');

		if(auxCad == 0 &amp;&amp; i != 3)
			return -1;

		auxCad++;
	}

	return lIp;
}

	// ALL UGLY...
	PMIB_UDPTABLE pUdpTable;
	unsigned long size = 0;
	bool free = 0;

	if(GetUdpTable(0, &amp;size, 0) == ERROR_INSUFFICIENT_BUFFER)
	{
		pUdpTable = (MIB_UDPTABLE*) new char[size];
		free = true;
	}

	if(GetUdpTable(pUdpTable, &amp;size, 0) == NO_ERROR)
	{
		if(pUdpTable-&gt;dwNumEntries &gt; 0)
		{
			for(unsigned i = 0; i &lt; pUdpTable-&gt;dwNumEntries; ++i)
			{
				if(htons(*((unsigned short *)&amp;pUdpTable-&gt;table[i].dwLocalPort)) == gamePort)
				{
					localIp = inet_ntoa(*(struct in_addr *)(char*)&amp;pUdpTable-&gt;table[i].dwLocalAddr);
					ulLocalIp = longToIp(localIp.c_str());
				}
			}
		}
	}

	if(free)
		delete [] pUdpTable;

OR

	char hostName[MAX_PATH];
	WSADATA wsaData;

	WSAStartup(MAKEWORD(2, 0), &amp;wsaData);

	gethostname(hostName, MAX_PATH);
	HOSTENT *hostEnt = gethostbyname(hostName);
	in_addr *host = reinterpret_cast&lt;LPIN_ADDR&gt;(hostEnt-&gt;h_addr);
	localIp = inet_addr(inet_ntoa(*host));

	WSACleanup();
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1611500</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1611500</guid><dc:creator><![CDATA[Bronson]]></dc:creator><pubDate>Thu, 06 Nov 2008 20:40:44 GMT</pubDate></item></channel></rss>