<?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[Ist diese Frage schwer?]]></title><description><![CDATA[<p>Guten Morgen,</p>
<p>folgendes Problem habe ich:<br />
- Die Klasse END_POINTS enthält 1- einen <strong>Konstruktor</strong> 2- Die Public-Methode <strong>getSourceAddress</strong> 3- Das <strong>Array src</strong> als privates Element (uint8_t* src;)</p>
<p>Hier ist der <strong>Konstruktor</strong>:</p>
<pre><code>// for IPv4 type
END_POINTS::END_POINTS(uint8_t srcB4, uint8_t srcB3, uint8_t srcB2, uint8_t srcB1,
	uint8_t destB4, uint8_t destB3, uint8_t destB2, uint8_t destB1) 
								   :Obj(ENDPOINTS_OBJ_CLASS, ENDPOINTS_IPV4_OBJ_TYPE)
{
	src = new uint8_t[4];
	END_POINTS::initIPv4Address(srcB4,  srcB3,	 srcB2,  srcB1, src);
	// das gleiche für dest
}

void END_POINTS::initIPv4Address (uint8_t b4, uint8_t b3, uint8_t b2, uint8_t b1, uint8_t* addr) {
	addr[0] = b1;
	addr[1] = b2;
	addr[2] = b3;
	addr[3] = b4; 
}
</code></pre>
<p>Hier ist die Funktion <strong>getSourceAddress</strong>:</p>
<pre><code>uint8_t* END_POINTS::getSourceAddress(uint8_t* source) const {
	uint16_t bytesNumber = 4;
	// copy source address to the return value
	for (int i=0; i&lt;bytesNumber; i++) {
		source[i] = src[ i ];
	}

	return source;
}
</code></pre>
<p>Im Programm wird ein Objekt endp der Klasse END_POINTS wie folgt definiert:</p>
<pre><code>END_POINTS endp(10, 149, 49, 49, 10, 149, 49, 55);
</code></pre>
<p>Mein Ziel ist es das letze Byte der Source aus der IP-Adresse zu lesen, also hier das 49. Wie kann ich das machen? Ich weiss, dass es eigentlich das Eleemnt src[3] ist, aber nachdem src private ist, weiss ich nicht, wie ich das machen soll.</p>
<p>Kann mir jemand einen Tipp geben?</p>
<p>Danke im Voraus,</p>
<p>CL</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/193868/ist-diese-frage-schwer</link><generator>RSS for Node</generator><lastBuildDate>Mon, 28 Sep 2026 06:35:07 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/193868.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 01 Oct 2007 07:42:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Ist diese Frage schwer? on Mon, 01 Oct 2007 07:42:20 GMT]]></title><description><![CDATA[<p>Guten Morgen,</p>
<p>folgendes Problem habe ich:<br />
- Die Klasse END_POINTS enthält 1- einen <strong>Konstruktor</strong> 2- Die Public-Methode <strong>getSourceAddress</strong> 3- Das <strong>Array src</strong> als privates Element (uint8_t* src;)</p>
<p>Hier ist der <strong>Konstruktor</strong>:</p>
<pre><code>// for IPv4 type
END_POINTS::END_POINTS(uint8_t srcB4, uint8_t srcB3, uint8_t srcB2, uint8_t srcB1,
	uint8_t destB4, uint8_t destB3, uint8_t destB2, uint8_t destB1) 
								   :Obj(ENDPOINTS_OBJ_CLASS, ENDPOINTS_IPV4_OBJ_TYPE)
{
	src = new uint8_t[4];
	END_POINTS::initIPv4Address(srcB4,  srcB3,	 srcB2,  srcB1, src);
	// das gleiche für dest
}

void END_POINTS::initIPv4Address (uint8_t b4, uint8_t b3, uint8_t b2, uint8_t b1, uint8_t* addr) {
	addr[0] = b1;
	addr[1] = b2;
	addr[2] = b3;
	addr[3] = b4; 
}
</code></pre>
<p>Hier ist die Funktion <strong>getSourceAddress</strong>:</p>
<pre><code>uint8_t* END_POINTS::getSourceAddress(uint8_t* source) const {
	uint16_t bytesNumber = 4;
	// copy source address to the return value
	for (int i=0; i&lt;bytesNumber; i++) {
		source[i] = src[ i ];
	}

	return source;
}
</code></pre>
<p>Im Programm wird ein Objekt endp der Klasse END_POINTS wie folgt definiert:</p>
<pre><code>END_POINTS endp(10, 149, 49, 49, 10, 149, 49, 55);
</code></pre>
<p>Mein Ziel ist es das letze Byte der Source aus der IP-Adresse zu lesen, also hier das 49. Wie kann ich das machen? Ich weiss, dass es eigentlich das Eleemnt src[3] ist, aber nachdem src private ist, weiss ich nicht, wie ich das machen soll.</p>
<p>Kann mir jemand einen Tipp geben?</p>
<p>Danke im Voraus,</p>
<p>CL</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1375709</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1375709</guid><dc:creator><![CDATA[cpplinux]]></dc:creator><pubDate>Mon, 01 Oct 2007 07:42:20 GMT</pubDate></item><item><title><![CDATA[Reply to Ist diese Frage schwer? on Mon, 01 Oct 2007 07:50:20 GMT]]></title><description><![CDATA[<p>source ist privat, aber in getSourceAdress() hast du seinen Inhalt nach source kopiert (und das lebt außerhalb deines Objekts) - d.h. du kannst dein letztes Byte dort auslesen.</p>
<p>PS: Ich hoffe, die Klasse hat auch die großen drei (Dtor, Copy-Ctor und op=).</p>
<p>PPS: Wenn dein Array immer 4 Byte groß ist, mußt du es nicht dynamisch anlegen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1375716</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1375716</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 01 Oct 2007 07:50:20 GMT</pubDate></item><item><title><![CDATA[Reply to Ist diese Frage schwer? on Mon, 01 Oct 2007 08:10:51 GMT]]></title><description><![CDATA[<blockquote>
<p>source ist privat, aber in getSourceAdress() hast du seinen Inhalt nach source kopiert (und das lebt außerhalb deines Objekts) - d.h. du kannst dein letztes Byte dort auslesen.</p>
</blockquote>
<p>Wie würde aber ein Aufruf der Funktion getSourceAddress ausschauen?</p>
<blockquote>
<p>PS: Ich hoffe, die Klasse hat auch die großen drei (Dtor, Copy-Ctor und op=).</p>
</blockquote>
<p>Ist alles da. Danke für den Hinweis :0)</p>
<blockquote>
<p>PPS: Wenn dein Array immer 4 Byte groß ist, mußt du es nicht dynamisch anlegen.</p>
</blockquote>
<p>Eigentlich nicht immer. 4 Byte bei IPv4 und 16 Byte bei IPv6. Damit es übersichtlich bleibt, habe ich hier den zweiten Fall nicht erwähnt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1375730</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1375730</guid><dc:creator><![CDATA[cpplinux]]></dc:creator><pubDate>Mon, 01 Oct 2007 08:10:51 GMT</pubDate></item><item><title><![CDATA[Reply to Ist diese Frage schwer? on Mon, 01 Oct 2007 08:13:26 GMT]]></title><description><![CDATA[<p>cpplinux schrieb:</p>
<blockquote>
<blockquote>
<p>source ist privat, aber in getSourceAdress() hast du seinen Inhalt nach source kopiert (und das lebt außerhalb deines Objekts) - d.h. du kannst dein letztes Byte dort auslesen.</p>
</blockquote>
<p>Wie würde aber ein Aufruf der Funktion getSourceAddress ausschauen?</p>
</blockquote>
<p>Etwa so:</p>
<pre><code class="language-cpp">char adress[4];
ep.SourceAdress(adress);
cout&lt;&lt;adress[3]&lt;&lt;endl;
</code></pre>
<p>PS: Ich würde die nackte Speicherverwaltung ganz weglassen (außer du hast es sehr eilig) und mit std::string oder std::vector&lt;char&gt; arbeiten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1375731</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1375731</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 01 Oct 2007 08:13:26 GMT</pubDate></item><item><title><![CDATA[Reply to Ist diese Frage schwer? on Mon, 01 Oct 2007 09:00:22 GMT]]></title><description><![CDATA[<blockquote>
<p>PS: Ich würde die nackte Speicherverwaltung ganz weglassen (außer du hast es sehr eilig) und mit std::string oder std::vector&lt;char&gt; arbeiten.</p>
</blockquote>
<p>Kann ich nicht weglassen, weil es eigentlich eine Bibliothek ist. Ich möchte bloss dieses verd****** letzte Byte lesen.</p>
<p>Ich habe es so probiert:</p>
<pre><code>END_POINTS endp(10, 149, 49, 49, 10, 149, 49, 55);
uint8_t* address;
address = new uint8_t[4];							
endp.getSourceAddress(address);

cout&lt;&lt;&quot;address[0]   &quot;&lt;&lt;address[0]&lt;&lt;endl;
cout&lt;&lt;&quot;address[1]   &quot;&lt;&lt;address[1]&lt;&lt;endl;
cout&lt;&lt;&quot;address[2]   &quot;&lt;&lt;address[2]&lt;&lt;endl;
cout&lt;&lt;&quot;address[3]   &quot;&lt;&lt;address[3]&lt;&lt;endl;
</code></pre>
<p>Aber an Stelle von 10 , 149 , 49 , 49 kriege ich</p>
<pre><code>address[0]   1
address[1]   1
address[2]   ?
address[3]
</code></pre>
<p>Bin ich zu blöd <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="😕"
    /></p>
<p>Mit char address[4] habe ich das bekommen</p>
<pre><code>invalid conversion from 'char*' to 'uint8_t*'
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1375767</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1375767</guid><dc:creator><![CDATA[cpplinux]]></dc:creator><pubDate>Mon, 01 Oct 2007 09:00:22 GMT</pubDate></item><item><title><![CDATA[Reply to Ist diese Frage schwer? on Mon, 01 Oct 2007 09:01:48 GMT]]></title><description><![CDATA[<p>uint8_t müsste ein typedef auf unsigned char sein, oder? Wenn ja, gibt cout das als ASCII-Zeichen aus und du müsstest die Werte nach int casten, wenn du den Zahlenwert brauchst.</p>
<p>PS: Ist es übrigens Absicht, daß die Bytes rückwärts eingetragen werden? Dein &quot;letztes Byte&quot; landet in src[0] und das erste Byte (10) in src[3].</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1375771</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1375771</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 01 Oct 2007 09:01:48 GMT</pubDate></item><item><title><![CDATA[Reply to Ist diese Frage schwer? on Mon, 01 Oct 2007 09:12:58 GMT]]></title><description><![CDATA[<p>cpplinux schrieb:</p>
<blockquote>
<blockquote>
<p>PPS: Wenn dein Array immer 4 Byte groß ist, mußt du es nicht dynamisch anlegen.</p>
</blockquote>
<p>Eigentlich nicht immer. 4 Byte bei IPv4 und 16 Byte bei IPv6.</p>
</blockquote>
<p>Ein union ist in diesem Falle wahrscheinlich effizienter sowohl hinsichtlich Laufzeit als auch Speicherverbrauch und macht weniger Probleme in anderer Hinsicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1375781</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1375781</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 01 Oct 2007 09:12:58 GMT</pubDate></item><item><title><![CDATA[Reply to Ist diese Frage schwer? on Mon, 01 Oct 2007 09:19:40 GMT]]></title><description><![CDATA[<p>Mit Casten habe ich die richtigen Werte bekommen</p>
<pre><code>cout&lt;&lt;&quot;address[0]  = &quot;&lt;&lt;(int) address[0]&lt;&lt;endl;
</code></pre>
<blockquote>
<p>PS: Ist es übrigens Absicht, daß die Bytes rückwärts eingetragen werden? Dein &quot;letztes Byte&quot; landet in src[0] und das erste Byte (10) in src[3].</p>
</blockquote>
<p>Ich weiss nicht, ob es absichtlich gemacht wurde, aber du hast recht, ich brauche das erste Element vom Array und nicht das letzte.</p>
<p>Danke Moderator! Programmieren ist wirklich eine schöne Sache....wenn man sie kann <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/1375791</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1375791</guid><dc:creator><![CDATA[cpplinux]]></dc:creator><pubDate>Mon, 01 Oct 2007 09:19:40 GMT</pubDate></item></channel></rss>