<?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[Verbindung via IPv6 herstellen]]></title><description><![CDATA[<p>tach zusammen,</p>
<p>ich hätte da mal ein mittelschweres verständnisproblem zu einer sache die mir mein chef in der praxisphase von meinem studium aufgetragen hat. ich soll durch ein c++ programm (konsolenanwendung reicht) eine verbindung mit einem server, einer internetseite oder was auch immer herstellen und das ganze soll IPv6 kompatibel sein.<br />
jetzt ist mein chef nicht da und ich weiß nicht so richrig wo ich anfangen soll. bin auch c++ technisch noch relativ am anfang ... <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=":confused:"
      alt="😕"
    /><br />
er hat mir anfang noch einen codeausschnitt mit der übertragung via IPv4 geschickt.</p>
<pre><code>SOCKET ViaConnectConnect(char *host,int port) {
                SOCKET so=INVALID_SOCKET;

                SOCKADDR_IN sad;
                struct hostent *he;
                union u_ipadr {
                               unsigned long l;
                               unsigned char c[4];
                };
                union u_ipadr ipadr;

                // ggf. Server-Name nach IP-Adresse auflösen
                if(host[0]&gt;'9') { // nur wenn Name nicht schon eine IP-Adresse ist

                               if(!(he=gethostbyname(host))) {
                                               return(INVALID_SOCKET);
                               }      
                               if(!he-&gt;h_addr_list[0]) { 
                                               return(INVALID_SOCKET);
                               }

                               ipadr.c[0]=he-&gt;h_addr_list[0][0];
                               ipadr.c[1]=he-&gt;h_addr_list[0][1];
                               ipadr.c[2]=he-&gt;h_addr_list[0][2];
                               ipadr.c[3]=he-&gt;h_addr_list[0][3];
                }

                so=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); // Socket oeffnen
                if(so==INVALID_SOCKET) {
                               return(INVALID_SOCKET);
                } else {                                                                                                // Socket erfolgreich geoeffnet               
                               //connect to ip address and port
                               sad.sin_family=AF_INET;
                               if(host[0]&gt;'9') sad.sin_addr.s_addr=ipadr.l;
                               else sad.sin_addr.s_addr=inet_addr(host);
                               sad.sin_port=htons(port); // Port 
                               if(connect(so,(LPSOCKADDR)&amp;sad,sizeof(sad))) {
                                               closesocket(so);
                                               return(INVALID_SOCKET);
                               }
                }
                return(so);
}
</code></pre>
<p>jetzt würde ich gerne wissen, wie ich das problem am besten angehe. vielleicht hat schon jemand was ähnliches gemacht und kann mir helfen die sache zu verstehen.</p>
<p>danke schonmal im voraus</p>
<p>gruß bautzi <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/271297/verbindung-via-ipv6-herstellen</link><generator>RSS for Node</generator><lastBuildDate>Sat, 29 Aug 2026 14:05:05 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/271297.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 26 Jul 2010 08:57:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Verbindung via IPv6 herstellen on Mon, 26 Jul 2010 08:57:11 GMT]]></title><description><![CDATA[<p>tach zusammen,</p>
<p>ich hätte da mal ein mittelschweres verständnisproblem zu einer sache die mir mein chef in der praxisphase von meinem studium aufgetragen hat. ich soll durch ein c++ programm (konsolenanwendung reicht) eine verbindung mit einem server, einer internetseite oder was auch immer herstellen und das ganze soll IPv6 kompatibel sein.<br />
jetzt ist mein chef nicht da und ich weiß nicht so richrig wo ich anfangen soll. bin auch c++ technisch noch relativ am anfang ... <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=":confused:"
      alt="😕"
    /><br />
er hat mir anfang noch einen codeausschnitt mit der übertragung via IPv4 geschickt.</p>
<pre><code>SOCKET ViaConnectConnect(char *host,int port) {
                SOCKET so=INVALID_SOCKET;

                SOCKADDR_IN sad;
                struct hostent *he;
                union u_ipadr {
                               unsigned long l;
                               unsigned char c[4];
                };
                union u_ipadr ipadr;

                // ggf. Server-Name nach IP-Adresse auflösen
                if(host[0]&gt;'9') { // nur wenn Name nicht schon eine IP-Adresse ist

                               if(!(he=gethostbyname(host))) {
                                               return(INVALID_SOCKET);
                               }      
                               if(!he-&gt;h_addr_list[0]) { 
                                               return(INVALID_SOCKET);
                               }

                               ipadr.c[0]=he-&gt;h_addr_list[0][0];
                               ipadr.c[1]=he-&gt;h_addr_list[0][1];
                               ipadr.c[2]=he-&gt;h_addr_list[0][2];
                               ipadr.c[3]=he-&gt;h_addr_list[0][3];
                }

                so=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); // Socket oeffnen
                if(so==INVALID_SOCKET) {
                               return(INVALID_SOCKET);
                } else {                                                                                                // Socket erfolgreich geoeffnet               
                               //connect to ip address and port
                               sad.sin_family=AF_INET;
                               if(host[0]&gt;'9') sad.sin_addr.s_addr=ipadr.l;
                               else sad.sin_addr.s_addr=inet_addr(host);
                               sad.sin_port=htons(port); // Port 
                               if(connect(so,(LPSOCKADDR)&amp;sad,sizeof(sad))) {
                                               closesocket(so);
                                               return(INVALID_SOCKET);
                               }
                }
                return(so);
}
</code></pre>
<p>jetzt würde ich gerne wissen, wie ich das problem am besten angehe. vielleicht hat schon jemand was ähnliches gemacht und kann mir helfen die sache zu verstehen.</p>
<p>danke schonmal im voraus</p>
<p>gruß bautzi <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1931852</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1931852</guid><dc:creator><![CDATA[Bautzi]]></dc:creator><pubDate>Mon, 26 Jul 2010 08:57:11 GMT</pubDate></item><item><title><![CDATA[Reply to Verbindung via IPv6 herstellen on Mon, 26 Jul 2010 10:18:08 GMT]]></title><description><![CDATA[<p>Ok und was ist jetzt dein Problem? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1931902</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1931902</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Mon, 26 Jul 2010 10:18:08 GMT</pubDate></item><item><title><![CDATA[Reply to Verbindung via IPv6 herstellen on Mon, 26 Jul 2010 10:37:57 GMT]]></title><description><![CDATA[<p>naja ich weiß halt net so genau wie ich an das problem rangehen soll und was dann bei IPv6 anders sein soll. ich brauch net unbedingt eine fertige lösung, mir gehts mehr ums verständnis, dass ich weiß womit ich beschäftigen muss um die sache hinzubekommen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1931913</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1931913</guid><dc:creator><![CDATA[Bautzi]]></dc:creator><pubDate>Mon, 26 Jul 2010 10:37:57 GMT</pubDate></item><item><title><![CDATA[Reply to Verbindung via IPv6 herstellen on Mon, 26 Jul 2010 10:41:42 GMT]]></title><description><![CDATA[<p><a href="http://openbook.galileocomputing.de/c_von_a_bis_z/025_c_netzwerkprogrammierung_008.htm#mj46218b64e64226323710c041737ff1a5" rel="nofollow">http://openbook.galileocomputing.de/c_von_a_bis_z/025_c_netzwerkprogrammierung_008.htm#mj46218b64e64226323710c041737ff1a5</a> (Ja, ich weiß, sollte nicht die erste Wahl sein :))</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1931915</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1931915</guid><dc:creator><![CDATA[Ad aCTa]]></dc:creator><pubDate>Mon, 26 Jul 2010 10:41:42 GMT</pubDate></item><item><title><![CDATA[Reply to Verbindung via IPv6 herstellen on Mon, 26 Jul 2010 11:15:37 GMT]]></title><description><![CDATA[<p>danke! das hilft mir erstmal etwas weiter. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1931935</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1931935</guid><dc:creator><![CDATA[Bautzi]]></dc:creator><pubDate>Mon, 26 Jul 2010 11:15:37 GMT</pubDate></item><item><title><![CDATA[Reply to Verbindung via IPv6 herstellen on Mon, 26 Jul 2010 19:12:19 GMT]]></title><description><![CDATA[<p>int sock;<br />
struct sockaddr_in6 name;</p>
<p>/* Create the socket. */<br />
sock = socket (AF_INET6,SOCK_STREAM,0);<br />
if (sock &lt; 0)<br />
throw socket_error(&quot;Error when creating a socket.&quot;);</p>
<p>/* Set REUSE option (this makes rebinding after a server shutdown<br />
* quicker). */<br />
int reuse = 1;<br />
if (setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&amp;reuse,sizeof(reuse)) &lt; 0)<br />
throw socket_error(&quot;Error when setting socket options.&quot;);</p>
<p>/* Give the socket a name. */<br />
name.sin6_family = AF_INET6;<br />
name.sin6_port = htons(port);<br />
name.sin6_addr = in6addr_any;<br />
if (bind(sock,(struct sockaddr <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title="*)"
      alt="😉"
    /> &amp;name,sizeof (name)) &lt; 0)<br />
throw socket_error(&quot;Error when binding the server socket to its port.&quot;);</p>
<p>return sock;</p>
<p>Auch<br />
man 7 ipv6<br />
unter Linux kann sehr hilfreich sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1932239</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1932239</guid><dc:creator><![CDATA[__1&#x2F;128]]></dc:creator><pubDate>Mon, 26 Jul 2010 19:12:19 GMT</pubDate></item><item><title><![CDATA[Reply to Verbindung via IPv6 herstellen on Tue, 27 Jul 2010 06:23:07 GMT]]></title><description><![CDATA[<p>besten dank dafür.<br />
ich werd mal sehen wie ich das dann einbauen kann. muss mich erstmal noch intensiver mit dem thema beschäftigen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1932374</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1932374</guid><dc:creator><![CDATA[Bautzi]]></dc:creator><pubDate>Tue, 27 Jul 2010 06:23:07 GMT</pubDate></item></channel></rss>