<?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[String-Ip in Char-IP umwandlen]]></title><description><![CDATA[<p>Hallo,</p>
<p>wie kann man einen String &quot;192.168.12.1&quot; umwandeln in ein char array</p>
<p>char IP[4] = {192, 168, 12, 1}</p>
<p>Die IP kann variieren - sprich in der Anzahl der Stellen (drei: 192, zwei: 12, oder eine Stelle)</p>
<p>Gruß<br />
Gerhard</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/267639/string-ip-in-char-ip-umwandlen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 02 Sep 2026 09:37:49 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/267639.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 27 May 2010 15:45:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to String-Ip in Char-IP umwandlen on Thu, 27 May 2010 15:45:17 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>wie kann man einen String &quot;192.168.12.1&quot; umwandeln in ein char array</p>
<p>char IP[4] = {192, 168, 12, 1}</p>
<p>Die IP kann variieren - sprich in der Anzahl der Stellen (drei: 192, zwei: 12, oder eine Stelle)</p>
<p>Gruß<br />
Gerhard</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1903291</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1903291</guid><dc:creator><![CDATA[Gerhard Stingler]]></dc:creator><pubDate>Thu, 27 May 2010 15:45:17 GMT</pubDate></item><item><title><![CDATA[Reply to String-Ip in Char-IP umwandlen on Thu, 27 May 2010 16:00:38 GMT]]></title><description><![CDATA[<p>Benutze die API Funkion inet_addr(..).<br />
<a href="http://msdn.microsoft.com/en-us/library/ms738563(VS.85).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms738563(VS.85).aspx</a></p>
<p>Leider weiss ich nicht ob die Funktion von den BSD Sockets ist od. etwas windows sepezifisches.</p>
<p>Simon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1903298</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1903298</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Thu, 27 May 2010 16:00:38 GMT</pubDate></item><item><title><![CDATA[Reply to String-Ip in Char-IP umwandlen on Thu, 27 May 2010 16:03:03 GMT]]></title><description><![CDATA[<p>Falls du plattformunabhängig bleiben willst: In einen Stringstream schreiben. Dann einfach mit die Streamoperatoren die Zahlen parsen lassen und die Punkte zwischendrin überspringen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1903300</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1903300</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 27 May 2010 16:03:03 GMT</pubDate></item><item><title><![CDATA[Reply to String-Ip in Char-IP umwandlen on Thu, 27 May 2010 16:06:40 GMT]]></title><description><![CDATA[<p>char ist sowieso ein ungeeigneter Datentyp.<br />
Char geht von -128 bis 127</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1903301</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1903301</guid><dc:creator><![CDATA[BigNeal]]></dc:creator><pubDate>Thu, 27 May 2010 16:06:40 GMT</pubDate></item><item><title><![CDATA[Reply to String-Ip in Char-IP umwandlen on Thu, 27 May 2010 16:12:46 GMT]]></title><description><![CDATA[<p>BigNeal schrieb:</p>
<blockquote>
<p>char ist sowieso ein ungeeigneter Datentyp.<br />
Char geht von -128 bis 127</p>
</blockquote>
<p>meinte natürlich unsigned char</p>
<blockquote>
<p>Benutze die API Funkion inet_addr(..).<br />
komm mit dieser Funktion noch nicht klar; die liefert mir doch nur einen unsigned long wert von der kompletten IP, oder?</p>
</blockquote>
<pre><code class="language-cpp">unsigned long ulAddr = inet_addr((const char *)lpData);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1903304</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1903304</guid><dc:creator><![CDATA[Gerhard Stingler]]></dc:creator><pubDate>Thu, 27 May 2010 16:12:46 GMT</pubDate></item><item><title><![CDATA[Reply to String-Ip in Char-IP umwandlen on Thu, 27 May 2010 16:13:00 GMT]]></title><description><![CDATA[<p>BigNeal schrieb:</p>
<blockquote>
<p>char ist sowieso ein ungeeigneter Datentyp.<br />
Char geht von -128 bis 127</p>
</blockquote>
<p>Nö. Ob char vorzeichenbehaftet ist, ist implementationsabhängig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1903305</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1903305</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Thu, 27 May 2010 16:13:00 GMT</pubDate></item><item><title><![CDATA[Reply to String-Ip in Char-IP umwandlen on Thu, 27 May 2010 16:16:44 GMT]]></title><description><![CDATA[<p>BigNeal schrieb:</p>
<blockquote>
<p>char ist sowieso ein ungeeigneter Datentyp.<br />
Char geht von -128 bis 127</p>
</blockquote>
<p>Das ist implementierungsabhängig. Du kannst Dich also nicht darauf verlassen, dass das überall so ist. char hat entweder denselben Wertebereich wie signed char oder den von unsigned char. Der von signed char enthält garantiert -127...127 und der Wertebereich von unsigned char umfasst mindestens die Ganzzahlen 0,1,2,...255.</p>
<p>Trotzdem hast Du recht, dass unsigned char[4] wahrscheinlich angebrachter wäre.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1903306</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1903306</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Thu, 27 May 2010 16:16:44 GMT</pubDate></item><item><title><![CDATA[Reply to String-Ip in Char-IP umwandlen on Thu, 27 May 2010 16:30:54 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">unsigned long ulAddr = inet_addr((const char *)lpData);
</code></pre>
<p>gibt es eine ander möglichkeit, welche mir gleich ein unsigned char array als ip ausgibt??? und keine ganze ulong ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1903312</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1903312</guid><dc:creator><![CDATA[Gerhard Stingler]]></dc:creator><pubDate>Thu, 27 May 2010 16:30:54 GMT</pubDate></item><item><title><![CDATA[Reply to String-Ip in Char-IP umwandlen on Thu, 27 May 2010 16:35:14 GMT]]></title><description><![CDATA[<p>Hau nen reinterpret_cast drauf und gut ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1903314</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1903314</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Thu, 27 May 2010 16:35:14 GMT</pubDate></item><item><title><![CDATA[Reply to String-Ip in Char-IP umwandlen on Thu, 27 May 2010 17:05:56 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;array&gt;
#include &lt;string&gt;

#include &lt;winsock2.h&gt;

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

std::tr1::array&lt;unsigned char, 4&gt; to_bytes(const std::string&amp; ip)
{
    unsigned long addr = inet_addr(ip.c_str());

    std::tr1::array&lt;unsigned char, 4&gt; buf;
    buf[0] = static_cast&lt;unsigned char&gt;((addr &amp; 0x000000FF) &gt;&gt; 0);
    buf[1] = static_cast&lt;unsigned char&gt;((addr &amp; 0x0000FF00) &gt;&gt; 8);
    buf[2] = static_cast&lt;unsigned char&gt;((addr &amp; 0x00FF0000) &gt;&gt; 16);
    buf[3] = static_cast&lt;unsigned char&gt;((addr &amp; 0xFF000000) &gt;&gt; 24);
    return buf;
}

int _tmain(int /*argc*/, _TCHAR* /*argv*/[])
{
    std::tr1::array&lt;unsigned char, 4&gt; bytes = to_bytes(&quot;192.168.1.32&quot;);
    bytes;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1903327</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1903327</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Thu, 27 May 2010 17:05:56 GMT</pubDate></item><item><title><![CDATA[Reply to String-Ip in Char-IP umwandlen on Thu, 27 May 2010 19:02:32 GMT]]></title><description><![CDATA[<p>Michael E. schrieb:</p>
<blockquote>
<p>Hau nen reinterpret_cast drauf und gut ist.</p>
</blockquote>
<pre><code class="language-cpp">unsigned char ip[4]; 
ip[0] = reinterpret_cast&lt;unsigned char&gt;inet_addr((const char *)lpData);
</code></pre>
<p>so ungefähr?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1903393</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1903393</guid><dc:creator><![CDATA[Gerhard Stingler]]></dc:creator><pubDate>Thu, 27 May 2010 19:02:32 GMT</pubDate></item><item><title><![CDATA[Reply to String-Ip in Char-IP umwandlen on Thu, 27 May 2010 19:34:16 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">unsigned long ulAddr = inet_addr((const char *)lpData);
unsigned char* ip = reinterpret_cast&lt;unsigned char*&gt;(&amp;ulAddr);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1903407</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1903407</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Thu, 27 May 2010 19:34:16 GMT</pubDate></item><item><title><![CDATA[Reply to String-Ip in Char-IP umwandlen on Thu, 27 May 2010 20:11:25 GMT]]></title><description><![CDATA[<p>Michael E. schrieb:</p>
<blockquote>
<p>Hau nen reinterpret_cast drauf und gut ist.</p>
</blockquote>
<p>Kann funktionieren, muss aber nicht - sizeof(unsigned long) muss nicht 4 sein, außerdem gibts da noch die endianess... Portabel ist das also auf keinen Fall.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1903424</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1903424</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Thu, 27 May 2010 20:11:25 GMT</pubDate></item><item><title><![CDATA[Reply to String-Ip in Char-IP umwandlen on Thu, 27 May 2010 20:27:05 GMT]]></title><description><![CDATA[<p>pumuckl schrieb:</p>
<blockquote>
<p>Michael E. schrieb:</p>
<blockquote>
<p>Hau nen reinterpret_cast drauf und gut ist.</p>
</blockquote>
<p>Kann funktionieren, muss aber nicht - sizeof(unsigned long) muss nicht 4 sein, außerdem gibts da noch die endianess... Portabel ist das also auf keinen Fall.</p>
</blockquote>
<p>Das hab ich mir auch zuerst überlegt. Aber dann bin ich zum Schluss gekommen, dass ich nicht portableren Code schreiben muss als inet_addr mir liefert <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f576.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--sunglasses"
      title=":sunglasses:"
      alt="🕶"
    /></p>
<p>Übrigens wirds in der Dokue (<a href="http://msdn.microsoft.com/en-us/library/ms738563%28VS.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms738563(VS.85).aspx</a>) analog mit C-Casts gemacht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1903431</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1903431</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Thu, 27 May 2010 20:27:05 GMT</pubDate></item></channel></rss>