<?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[IP kriegen ?? GetHostByName]]></title><description><![CDATA[<pre><code>#include &lt;windows.h&gt;
#include &lt;conio.h&gt;
#include &lt;iostream&gt;
using namespace std;
//#pragma comment(lib,&quot;ws2_32.lib&quot;)  // für MSV C++

int main()
{
 char hostname[255];
 char *szIPAddress;
 WORD wVer;
 WSADATA wData;
 PHOSTENT hostinfo;
 wVer = MAKEWORD( 2, 0 );

 if ( WSAStartup( wVer, &amp;wData ) == 0 )
 {
  if( gethostname ( hostname, sizeof(hostname)) == 0)
  {
   if((hostinfo = gethostbyname(hostname)) != NULL)
   {
    szIPAddress = inet_ntoa (*(struct in_addr *)*hostinfo-&gt;h_addr_list);
   }
  }
 WSACleanup();
 }

  cout&lt;&lt;szIPAddress&lt;&lt;endl;
  getch();
  return 0;
}
</code></pre>
<p>GetHostByName() soll undefiniert sein, aba ich finde den void net <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title="=/"
      alt="😕"
    /><br />
Kann mir jemand helfen oda mich zurchtweisen ? ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/240798/ip-kriegen-gethostbyname</link><generator>RSS for Node</generator><lastBuildDate>Mon, 21 Sep 2026 19:05:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/240798.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 11 May 2009 18:50:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to IP kriegen ?? GetHostByName on Mon, 11 May 2009 18:50:48 GMT]]></title><description><![CDATA[<pre><code>#include &lt;windows.h&gt;
#include &lt;conio.h&gt;
#include &lt;iostream&gt;
using namespace std;
//#pragma comment(lib,&quot;ws2_32.lib&quot;)  // für MSV C++

int main()
{
 char hostname[255];
 char *szIPAddress;
 WORD wVer;
 WSADATA wData;
 PHOSTENT hostinfo;
 wVer = MAKEWORD( 2, 0 );

 if ( WSAStartup( wVer, &amp;wData ) == 0 )
 {
  if( gethostname ( hostname, sizeof(hostname)) == 0)
  {
   if((hostinfo = gethostbyname(hostname)) != NULL)
   {
    szIPAddress = inet_ntoa (*(struct in_addr *)*hostinfo-&gt;h_addr_list);
   }
  }
 WSACleanup();
 }

  cout&lt;&lt;szIPAddress&lt;&lt;endl;
  getch();
  return 0;
}
</code></pre>
<p>GetHostByName() soll undefiniert sein, aba ich finde den void net <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title="=/"
      alt="😕"
    /><br />
Kann mir jemand helfen oda mich zurchtweisen ? ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1709146</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1709146</guid><dc:creator><![CDATA[Bearfist]]></dc:creator><pubDate>Mon, 11 May 2009 18:50:48 GMT</pubDate></item><item><title><![CDATA[Reply to IP kriegen ?? GetHostByName on Mon, 11 May 2009 18:58:56 GMT]]></title><description><![CDATA[<p>Ich verstehe dein Problem / Frage nicht.<br />
Stell sie präziser.<br />
Simon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1709156</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1709156</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Mon, 11 May 2009 18:58:56 GMT</pubDate></item><item><title><![CDATA[Reply to IP kriegen ?? GetHostByName on Mon, 11 May 2009 19:01:28 GMT]]></title><description><![CDATA[<p>Ok dann versuch ich es nochmal XD</p>
<pre><code>if( gethostname ( hostname, sizeof(hostname)) == 0)
</code></pre>
<p>soll undefiniert sein<br />
also muss ja eine definition von &quot;gethostbyname&quot; zu finden sein ^^<br />
und ich finde die net</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1709158</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1709158</guid><dc:creator><![CDATA[Bearfist]]></dc:creator><pubDate>Mon, 11 May 2009 19:01:28 GMT</pubDate></item><item><title><![CDATA[Reply to IP kriegen ?? GetHostByName on Mon, 11 May 2009 19:04:00 GMT]]></title><description><![CDATA[<p><a href="http://msdn.microsoft.com/en-us/library/ms738527.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms738527.aspx</a><br />
1. winsock2.h inkludieren<br />
2. ws2_32.lib linken (ist bei Dir auskommentiert)</p>
<p>Simon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1709159</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1709159</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Mon, 11 May 2009 19:04:00 GMT</pubDate></item><item><title><![CDATA[Reply to IP kriegen ?? GetHostByName on Mon, 11 May 2009 19:13:21 GMT]]></title><description><![CDATA[<p>theta schrieb:</p>
<blockquote>
<p><a href="http://msdn.microsoft.com/en-us/library/ms738527.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms738527.aspx</a><br />
1. winsock2.h inkludieren<br />
2. ws2_32.lib linken (ist bei Dir auskommentiert)</p>
<p>Simon</p>
</blockquote>
<p>ok hab ich gemacht jetzt sieht es so aus:</p>
<pre><code>#include &lt;iostream.h&gt;
#include &lt;winsock.h&gt;
#include &lt;winsock2.h&gt;

#pragma comment(lib, &quot;ws2_32.lib&quot;)

int doit(int, char **)
{
    char ac[80];
    if (gethostname(ac, sizeof(ac)) == SOCKET_ERROR) {
        cerr &lt;&lt; &quot;Error &quot; &lt;&lt; WSAGetLastError() &lt;&lt;
                &quot; when getting local host name.&quot; &lt;&lt; endl;
        return 1;
    }
    cout &lt;&lt; &quot;Host name is &quot; &lt;&lt; ac &lt;&lt; &quot;.&quot; &lt;&lt; endl;

    struct hostent *phe = gethostbyname(ac);
    if (phe == 0) {
        cerr &lt;&lt; &quot;Yow! Bad host lookup.&quot; &lt;&lt; endl;
        return 1;
    }

    for (int i = 0; phe-&gt;h_addr_list[i] != 0; ++i) {
        struct in_addr addr;
        memcpy(&amp;addr, phe-&gt;h_addr_list[i], sizeof(struct in_addr));
        cout &lt;&lt; &quot;Address &quot; &lt;&lt; i &lt;&lt; &quot;: &quot; &lt;&lt; inet_ntoa(addr) &lt;&lt; endl;
    }

    return 0;
}

int main(int argc, char *argv[])
{
    WSAData wsaData;
    if (WSAStartup(MAKEWORD(1, 1), &amp;wsaData) != 0) {
        return 255;
    }

    int retval = doit(argc, argv);

    WSACleanup();

    return retval;
}
</code></pre>
<p>undefined reference GetHostName@8<br />
undefined reference WSAGetLastError@0<br />
undefined reference GetHostByName@4<br />
undefined reference inet_ntoa @4<br />
undefined reference WSAStartup@8<br />
undefined reference WSACleanup@0</p>
<p>Hat sich nix geändert<br />
PS: Ich benutze CODE:BLOCKS</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1709162</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1709162</guid><dc:creator><![CDATA[Bearfist]]></dc:creator><pubDate>Mon, 11 May 2009 19:13:21 GMT</pubDate></item><item><title><![CDATA[Reply to IP kriegen ?? GetHostByName on Mon, 11 May 2009 19:50:02 GMT]]></title><description><![CDATA[<p>Bearfist schrieb:</p>
<blockquote>
<p>#pragma comment(lib, &quot;ws2_32.lib&quot;)</p>
</blockquote>
<p>DAS geht glaube ich nur mit MS-Compilern. Das wirst Du mit CodeBlocks anders lösen müssen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1709178</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1709178</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Mon, 11 May 2009 19:50:02 GMT</pubDate></item><item><title><![CDATA[Reply to IP kriegen ?? GetHostByName on Mon, 11 May 2009 20:01:12 GMT]]></title><description><![CDATA[<p>Wenn Du mit Deinem CodeBlocks den MinGW benutzt, dann heißt die lib dort: libws2_32.a</p>
<p>Wie man CodeBlocks dazu bewegt, die mitzulinken, weiß ich nicht, frag mal im entsprechenden Forum nach.<br />
Ansonsten kannst Du das Programm auf der Kommandozeile mit:<br />
g++ prog.cpp -lws2_32 -o prog.exe<br />
selbst erstellen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1709181</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1709181</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Mon, 11 May 2009 20:01:12 GMT</pubDate></item><item><title><![CDATA[Reply to IP kriegen ?? GetHostByName on Mon, 11 May 2009 20:03:53 GMT]]></title><description><![CDATA[<p>Aso ok..<br />
hab mir jez Visual Studio 2008 von MS runtergeladen<br />
...werds ma da versuchen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1709182</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1709182</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Mon, 11 May 2009 20:03:53 GMT</pubDate></item></channel></rss>