<?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[winsocket - warten bis eine verbindung beendet ist]]></title><description><![CDATA[<p>Hi,</p>
<p>Ich versuche mich grade an einer simplen Remoteshell, diese funktioniert beim ersten Zugriff auch. Jedoch möchte ich das der Socket danach nicht geschlossen wird sondern wieder in den accept modus geht und auf neue Verbindungen wartet.</p>
<p>Hier mein jetziger code ( thx @ <a href="http://c-worker.ch" rel="nofollow">c-worker.ch</a> für das socket tut )</p>
<pre><code>#include &lt;windows.h&gt;
#include &lt;winsock2.h&gt;
#include &lt;stdio.h&gt;

int startWinsock(void);

int main(int argc, char *argv[]){

  long rc;

  SOCKET acceptSocket;
  SOCKET connectedSocket;
  SOCKADDR_IN addr;

        STARTUPINFO si;
        PROCESS_INFORMATION pi;
        struct sockaddr_in adik_sin;
        memset(&amp;si,0,sizeof(si));

  rc=startWinsock();	//winsock start

  if(rc!=0){
  		printf(&quot;Fehler: startWinsock, fehler code: %d\n&quot;,rc);
		return 1;
  }

while(1){
  acceptSocket=WSASocket(AF_INET,SOCK_STREAM,0,NULL,NULL,NULL);

  if(acceptSocket==INVALID_SOCKET){
    printf(&quot;Fehler: Der Socket konnte nicht erstellt werden, fehler code: %d\n&quot;,WSAGetLastError());
    return 1;
  }

  memset(&amp;addr,0,sizeof(SOCKADDR_IN));

  addr.sin_family=AF_INET;
  addr.sin_port=htons(1010);
  addr.sin_addr.s_addr=ADDR_ANY;

  rc=bind(acceptSocket,(SOCKADDR*)&amp;addr,sizeof(SOCKADDR_IN));

  if(rc==SOCKET_ERROR){
	printf(&quot;Fehler: bind, fehler code: %d\n&quot;,WSAGetLastError());
	return 1;
  }

  rc=listen(acceptSocket,10);
  if(rc==SOCKET_ERROR){
  	printf(&quot;Fehler: listen, fehler code: %d\n&quot;,WSAGetLastError());
  	return 1;
  }

  connectedSocket=accept(acceptSocket,NULL,NULL);

  if(connectedSocket==INVALID_SOCKET){
  	printf(&quot;Fehler: accept, fehler code: %d\n&quot;,WSAGetLastError());
  	return 1;
  }

  //socketstream wird mit cmd.exe stream verbunden
  si.cb = sizeof(si);
  si.dwFlags = STARTF_USESTDHANDLES;
  si.hStdInput = si.hStdOutput = si.hStdError = (void *)connectedSocket;
  CreateProcess(NULL,&quot;cmd&quot;,NULL,NULL,1,NULL,NULL,NULL,&amp;si,&amp;pi);
  ExitProcess(0);
}
  return 0;

}

int startWinsock(void){

  WSADATA wsa;

  return WSAStartup(MAKEWORD(2,0),&amp;wsa);

}
</code></pre>
<p>Fehlerausgabe nach dem ersten Verbindungsaufbau:</p>
<pre><code>Fehler: bind, fehler code: 10048
</code></pre>
<p>Ich denke er kann den Socket nicht an den gewünschten Port binden da dieser noch blockiert ist.</p>
<p>Wie kann ich das besser machen ?</p>
<p>Thanx in advance c°h°</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/136736/winsocket-warten-bis-eine-verbindung-beendet-ist</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Jul 2026 00:51:26 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/136736.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 12 Feb 2006 19:12:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to winsocket - warten bis eine verbindung beendet ist on Sun, 12 Feb 2006 19:12:51 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>Ich versuche mich grade an einer simplen Remoteshell, diese funktioniert beim ersten Zugriff auch. Jedoch möchte ich das der Socket danach nicht geschlossen wird sondern wieder in den accept modus geht und auf neue Verbindungen wartet.</p>
<p>Hier mein jetziger code ( thx @ <a href="http://c-worker.ch" rel="nofollow">c-worker.ch</a> für das socket tut )</p>
<pre><code>#include &lt;windows.h&gt;
#include &lt;winsock2.h&gt;
#include &lt;stdio.h&gt;

int startWinsock(void);

int main(int argc, char *argv[]){

  long rc;

  SOCKET acceptSocket;
  SOCKET connectedSocket;
  SOCKADDR_IN addr;

        STARTUPINFO si;
        PROCESS_INFORMATION pi;
        struct sockaddr_in adik_sin;
        memset(&amp;si,0,sizeof(si));

  rc=startWinsock();	//winsock start

  if(rc!=0){
  		printf(&quot;Fehler: startWinsock, fehler code: %d\n&quot;,rc);
		return 1;
  }

while(1){
  acceptSocket=WSASocket(AF_INET,SOCK_STREAM,0,NULL,NULL,NULL);

  if(acceptSocket==INVALID_SOCKET){
    printf(&quot;Fehler: Der Socket konnte nicht erstellt werden, fehler code: %d\n&quot;,WSAGetLastError());
    return 1;
  }

  memset(&amp;addr,0,sizeof(SOCKADDR_IN));

  addr.sin_family=AF_INET;
  addr.sin_port=htons(1010);
  addr.sin_addr.s_addr=ADDR_ANY;

  rc=bind(acceptSocket,(SOCKADDR*)&amp;addr,sizeof(SOCKADDR_IN));

  if(rc==SOCKET_ERROR){
	printf(&quot;Fehler: bind, fehler code: %d\n&quot;,WSAGetLastError());
	return 1;
  }

  rc=listen(acceptSocket,10);
  if(rc==SOCKET_ERROR){
  	printf(&quot;Fehler: listen, fehler code: %d\n&quot;,WSAGetLastError());
  	return 1;
  }

  connectedSocket=accept(acceptSocket,NULL,NULL);

  if(connectedSocket==INVALID_SOCKET){
  	printf(&quot;Fehler: accept, fehler code: %d\n&quot;,WSAGetLastError());
  	return 1;
  }

  //socketstream wird mit cmd.exe stream verbunden
  si.cb = sizeof(si);
  si.dwFlags = STARTF_USESTDHANDLES;
  si.hStdInput = si.hStdOutput = si.hStdError = (void *)connectedSocket;
  CreateProcess(NULL,&quot;cmd&quot;,NULL,NULL,1,NULL,NULL,NULL,&amp;si,&amp;pi);
  ExitProcess(0);
}
  return 0;

}

int startWinsock(void){

  WSADATA wsa;

  return WSAStartup(MAKEWORD(2,0),&amp;wsa);

}
</code></pre>
<p>Fehlerausgabe nach dem ersten Verbindungsaufbau:</p>
<pre><code>Fehler: bind, fehler code: 10048
</code></pre>
<p>Ich denke er kann den Socket nicht an den gewünschten Port binden da dieser noch blockiert ist.</p>
<p>Wie kann ich das besser machen ?</p>
<p>Thanx in advance c°h°</p>
]]></description><link>https://www.c-plusplus.net/forum/post/992530</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/992530</guid><dc:creator><![CDATA[c°h°]]></dc:creator><pubDate>Sun, 12 Feb 2006 19:12:51 GMT</pubDate></item><item><title><![CDATA[Reply to winsocket - warten bis eine verbindung beendet ist on Sun, 12 Feb 2006 23:20:17 GMT]]></title><description><![CDATA[<p>habs hier mein code jetzt sogar mit pwabfrage <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="🙂"
    /> mfg</p>
<pre><code>#include &lt;windows.h&gt;
#include &lt;winsock2.h&gt;
#include &lt;stdio.h&gt;

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

int startWinsock(void);

int main(int argc, char *argv[]){

  if( argc &lt; 1 ) return 1;

  long rc;

  SOCKET acceptSocket;
  SOCKET connectedSocket;
  SOCKADDR_IN addr;

  STARTUPINFO si;
  PROCESS_INFORMATION pi;
  struct sockaddr_in adik_sin;
  memset(&amp;si,0,sizeof(si));

  char buf[10];

  while(1){

  		rc=startWinsock();

  		if(rc!=0){
  			printf(&quot;Fehler: startWinsock, fehler code: %d\n&quot;,rc);
			return 1;
  		}

  		acceptSocket=WSASocket(AF_INET,SOCK_STREAM,0,NULL,NULL,NULL);

  		if(acceptSocket==INVALID_SOCKET){
    		printf(&quot;Fehler: Der Socket konnte nicht erstellt werden, fehler code: %d\n&quot;,WSAGetLastError());
    		return 1;
  		}

  		memset(&amp;addr,0,sizeof(SOCKADDR_IN));

  		addr.sin_family=AF_INET;
 		 addr.sin_port=htons(atoi(argv[1]));
 		 addr.sin_addr.s_addr=ADDR_ANY;

  		rc=bind(acceptSocket,(SOCKADDR*)&amp;addr,sizeof(SOCKADDR_IN));

  		if(rc==SOCKET_ERROR){
			printf(&quot;Fehler: bind, fehler code: %d\n&quot;,WSAGetLastError());
			return 1;
  		}

  		rc=listen(acceptSocket,10);
  		if(rc==SOCKET_ERROR){
  			printf(&quot;Fehler: listen, fehler code: %d\n&quot;,WSAGetLastError());
  			return 1;
  		}

  		connectedSocket=accept(acceptSocket,NULL,NULL);

  		if(connectedSocket==INVALID_SOCKET){
  			printf(&quot;Fehler: accept, fehler code: %d\n&quot;,WSAGetLastError());
  			return 1;
  		}

  		strcpy(buf,&quot;GiMMiX&quot;);
  		rc=send(connectedSocket,buf,6,0);

  		rc=recv(connectedSocket,buf,10,0);

		if(strncmp(buf,&quot;passwort&quot;,8)==0){
  		//socketstream wird mit cmd.exe stream verbunden
  		si.cb = sizeof(si);
  		si.dwFlags = STARTF_USESTDHANDLES;
  		si.hStdInput = si.hStdOutput = si.hStdError = (void *)connectedSocket;
  		CreateProcess(NULL,&quot;cmd&quot;,NULL,NULL,1,NULL,NULL,NULL,&amp;si,&amp;pi);

  		WaitForSingleObject(pi.hProcess,INFINITE);
		}
  		closesocket(acceptSocket);
  		closesocket(connectedSocket);
		WSACleanup();

  }
  return 0;

}

//-----------------startWinsock-----------------------
int startWinsock(void){

  WSADATA wsa;

  return WSAStartup(MAKEWORD(2,0),&amp;wsa);

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/992731</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/992731</guid><dc:creator><![CDATA[c°h°]]></dc:creator><pubDate>Sun, 12 Feb 2006 23:20:17 GMT</pubDate></item><item><title><![CDATA[Reply to winsocket - warten bis eine verbindung beendet ist on Sun, 12 Feb 2006 23:43:36 GMT]]></title><description><![CDATA[<p>Es ist aber nicht garantiert das du das ganze Passwort mit einem Aufruf von recv bekommst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/992744</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/992744</guid><dc:creator><![CDATA[tja]]></dc:creator><pubDate>Sun, 12 Feb 2006 23:43:36 GMT</pubDate></item></channel></rss>