<?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[internet_connection_new]]></title><description><![CDATA[<p>hi@all<br />
ich musst den thread hier her verlegen...da man komischer weiße im alten das nicht mehr genau lesen kan...ka was da los ist...</p>
<p>ok letzter post von webfritzi:</p>
<p>So, ich hab mich jetzt auch mal schlau gemacht. In den Google-Groups<br />
habe ich etwas gefunden: HIER. <a href="http://groups.google.de/groups?hl=de&amp;lr=&amp;ie=UTF-8&amp;oe=UTF-8&amp;threadm=4tt509%246lh%40rap.SanDiegoCA.NCR.COM&amp;rnum=5&amp;prev=/groups%3Fq%3Dping%2Bwinsock%26hl%3Dde%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3D4tt509%25246lh%2540rap.SanDiegoCA.NCR.COM%26rnum%3D5" rel="nofollow">Ergebnis der Google-Suche</a><br />
Hab den Code etwas umgemodelt, so dass er<br />
auf meine Bedürfnisse zugeschnitten ist. Leider habe ich noch ein Problem dabei.<br />
Das erste Pingen geht wunderbar. Naja, fast, denn der IP-String &quot;lpszIP&quot; wird nur einmal<br />
ordentlich angezeigt. Dann steht da nur noch scheiße drin. WIESO? Der (Compiler) kann doch<br />
nicht einfach in meinem Speicher rumpfuschen! Naja, ein zweiter Ping schlägt bei mir auch fehl.</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt; 
#include &lt;winsock2.h&gt; 
#include &lt;stdio.h&gt; 

/* Program provided as is.  It might be awful or worse. It may not 
   work tomorrow. For novelty use only - do not mistake for 
   a real program. 

     Bernard S. Greenberg bsg@basistech.com    25 May 1995 
     Thanks to Andrew Carlson for revealing the Microsoft ICMP API. 

   build: cl ping.c wsock32.lib    (used Microsoft C 9.0 (VC2.0)) 

*/ 

typedef struct ip_option_information 
{ 
   UCHAR Ttl; 
   UCHAR Tos; 
   UCHAR Flags; 
   UCHAR OptionsSize; 
   PUCHAR OptionsData; 
} IP_OPTION_INFORMATION, *PIP_OPTION_INFORMATION; 

typedef struct icmp_echo_reply 
{ 
   ULONG Address; 
   ULONG Status; 
   ULONG RoundTripTime; 
   USHORT DataSize; 
   USHORT Reserved; 
   PVOID Data; 
   IP_OPTION_INFORMATION Options; 
} ICMP_ECHO_REPLY, *PICMP_ECHO_REPLY; 

typedef HANDLE (*LPICMPCREATEFILE)(VOID); 
typedef DWORD (*LPICMPSENDECHO)(HANDLE,LONG,LPVOID,WORD,PIP_OPTION_INFORMATION,LPVOID,DWORD,DWORD); 
typedef BOOL (*LPICMPCLOSEHANDLE)(HANDLE); 

#pragma argsused 
int main(int argc, char ** argv) 
{ 
    HANDLE hh; 
    DWORD dwv; 
    HINSTANCE module; 
    PHOSTENT host; 
    ULONG addr; 
    WSADATA WSAData; 
    char rbuf[5000]; 
    LPICMPCREATEFILE IcmpCreateFile; 
    LPICMPSENDECHO IcmpSendEcho; 
    LPICMPCLOSEHANDLE IcmpCloseHandle; 
    LPCTSTR lpszHost = TEXT(&quot;www.web.de&quot;); 
    char lpszIP[16]; 

    if(WSAStartup(MAKEWORD(2,0), &amp;WSAData) != 0) 
    { 
        fprintf (stderr, &quot;Can't start up winsock.\n&quot;); 
        return 0; 
    } 

    addr = inet_addr(lpszHost); 
    if(addr == (ULONG)INADDR_NONE) 
    { 
        host = gethostbyname(lpszHost); 
        if(host == NULL) 
        { 
            fprintf (stderr, &quot;Can't figure out host name/ID %s.\n&quot;, lpszHost); 
            getchar(); 
            return 0; 
        } 
        addr = *(ULONG*)(*host-&gt;h_addr_list); 
        lstrcpy( lpszIP, inet_ntoa(*(in_addr*)&amp;addr)); 
    } 
    else 
        lstrcpy( lpszIP, lpszHost ); 

    module = LoadLibrary(&quot;ICMP.DLL&quot;); 
    if(module == NULL) 
    { 
        fprintf (stderr, &quot;Can't load module ICMP.DLL\n&quot;); 
        getchar(); 
        return 0; 
    } 

    IcmpCreateFile = (LPICMPCREATEFILE)GetProcAddress(module, &quot;IcmpCreateFile&quot;); 
    IcmpSendEcho =  (LPICMPSENDECHO)GetProcAddress(module, &quot;IcmpSendEcho&quot;); 
    IcmpCloseHandle = (LPICMPCLOSEHANDLE)GetProcAddress(module, &quot;IcmpCloseHandle&quot;); 

    if ( !IcmpCreateFile || !IcmpSendEcho || !IcmpCloseHandle ) 
    { 
        fprintf(stderr, &quot;Can't find module entry points.\n&quot;); 
        getchar(); 
        return 0; 
    } 

    hh = IcmpCreateFile(); 

    if(!hh) 
    { 
        fprintf(stderr, &quot;Can't open the icmp handle.\n&quot;); 
        getchar(); 
        return 0; 
    } 

    printf (&quot;Ping %s [%s] mit 32 Bytes Daten:\n\n&quot;, lpszHost, lpszIP); 
    for(int i = 0; i &lt; 1; i++) 
    { 
       LPVOID reqData = (LPVOID)new BYTE[32]; 

       dwv = IcmpSendEcho(hh,                     /* Handle of ICMP &quot;file&quot; */ 
                          addr,                   /* IP address of host */ 
                          reqData,                /* ICMP request data */ 
                          32,                     /* sizeof above */ 
                          NULL,                   /* IP request options TBS */ 
                          rbuf,                   /* reply buffer */ 
                          sizeof(rbuf),           /* size of above */ 
                          3000);                  /* timeout, millisecondsp */ 

       for(unsigned int j=0; j&lt;dwv; j++) 
       { 
          ICMP_ECHO_REPLY* er = (ICMP_ECHO_REPLY*)rbuf; 
          printf(&quot;Antwort von %s: Bytes=%d Zeit=%dms TTL=%d\n&quot;, lpszIP, 32, er-&gt;RoundTripTime, er-&gt;Options.Ttl); 
       } 

       delete reqData; 
    } 

    printf (&quot;%s\n&quot;, dwv ? &quot;PING!&quot; : &quot;Pffft.&quot;); 

    IcmpCloseHandle(hh); 
    FreeLibrary(module); 
    WSACleanup(); 

    getchar(); 
    return 0; 
}
</code></pre>
<p>code besser zu lesen da: <a href="http://rafb.net/paste/results/b3086750.html" rel="nofollow">http://rafb.net/paste/results/b3086750.html</a><br />
hier kann man code nicht als cpp posten da funzt hier was net!!!</p>
<p><strong>edit:</strong> Google-URL gekürzt und Codetags hinzugefügt. Der rafb-Paste ist bereits verschollen, du solltest es besser hier posten.<br />
sfds</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/64112/internet_connection_new</link><generator>RSS for Node</generator><lastBuildDate>Tue, 07 Apr 2026 08:42:45 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/64112.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 08 Feb 2004 03:02:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to internet_connection_new on Mon, 09 Feb 2004 14:55:40 GMT]]></title><description><![CDATA[<p>hi@all<br />
ich musst den thread hier her verlegen...da man komischer weiße im alten das nicht mehr genau lesen kan...ka was da los ist...</p>
<p>ok letzter post von webfritzi:</p>
<p>So, ich hab mich jetzt auch mal schlau gemacht. In den Google-Groups<br />
habe ich etwas gefunden: HIER. <a href="http://groups.google.de/groups?hl=de&amp;lr=&amp;ie=UTF-8&amp;oe=UTF-8&amp;threadm=4tt509%246lh%40rap.SanDiegoCA.NCR.COM&amp;rnum=5&amp;prev=/groups%3Fq%3Dping%2Bwinsock%26hl%3Dde%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3D4tt509%25246lh%2540rap.SanDiegoCA.NCR.COM%26rnum%3D5" rel="nofollow">Ergebnis der Google-Suche</a><br />
Hab den Code etwas umgemodelt, so dass er<br />
auf meine Bedürfnisse zugeschnitten ist. Leider habe ich noch ein Problem dabei.<br />
Das erste Pingen geht wunderbar. Naja, fast, denn der IP-String &quot;lpszIP&quot; wird nur einmal<br />
ordentlich angezeigt. Dann steht da nur noch scheiße drin. WIESO? Der (Compiler) kann doch<br />
nicht einfach in meinem Speicher rumpfuschen! Naja, ein zweiter Ping schlägt bei mir auch fehl.</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt; 
#include &lt;winsock2.h&gt; 
#include &lt;stdio.h&gt; 

/* Program provided as is.  It might be awful or worse. It may not 
   work tomorrow. For novelty use only - do not mistake for 
   a real program. 

     Bernard S. Greenberg bsg@basistech.com    25 May 1995 
     Thanks to Andrew Carlson for revealing the Microsoft ICMP API. 

   build: cl ping.c wsock32.lib    (used Microsoft C 9.0 (VC2.0)) 

*/ 

typedef struct ip_option_information 
{ 
   UCHAR Ttl; 
   UCHAR Tos; 
   UCHAR Flags; 
   UCHAR OptionsSize; 
   PUCHAR OptionsData; 
} IP_OPTION_INFORMATION, *PIP_OPTION_INFORMATION; 

typedef struct icmp_echo_reply 
{ 
   ULONG Address; 
   ULONG Status; 
   ULONG RoundTripTime; 
   USHORT DataSize; 
   USHORT Reserved; 
   PVOID Data; 
   IP_OPTION_INFORMATION Options; 
} ICMP_ECHO_REPLY, *PICMP_ECHO_REPLY; 

typedef HANDLE (*LPICMPCREATEFILE)(VOID); 
typedef DWORD (*LPICMPSENDECHO)(HANDLE,LONG,LPVOID,WORD,PIP_OPTION_INFORMATION,LPVOID,DWORD,DWORD); 
typedef BOOL (*LPICMPCLOSEHANDLE)(HANDLE); 

#pragma argsused 
int main(int argc, char ** argv) 
{ 
    HANDLE hh; 
    DWORD dwv; 
    HINSTANCE module; 
    PHOSTENT host; 
    ULONG addr; 
    WSADATA WSAData; 
    char rbuf[5000]; 
    LPICMPCREATEFILE IcmpCreateFile; 
    LPICMPSENDECHO IcmpSendEcho; 
    LPICMPCLOSEHANDLE IcmpCloseHandle; 
    LPCTSTR lpszHost = TEXT(&quot;www.web.de&quot;); 
    char lpszIP[16]; 

    if(WSAStartup(MAKEWORD(2,0), &amp;WSAData) != 0) 
    { 
        fprintf (stderr, &quot;Can't start up winsock.\n&quot;); 
        return 0; 
    } 

    addr = inet_addr(lpszHost); 
    if(addr == (ULONG)INADDR_NONE) 
    { 
        host = gethostbyname(lpszHost); 
        if(host == NULL) 
        { 
            fprintf (stderr, &quot;Can't figure out host name/ID %s.\n&quot;, lpszHost); 
            getchar(); 
            return 0; 
        } 
        addr = *(ULONG*)(*host-&gt;h_addr_list); 
        lstrcpy( lpszIP, inet_ntoa(*(in_addr*)&amp;addr)); 
    } 
    else 
        lstrcpy( lpszIP, lpszHost ); 

    module = LoadLibrary(&quot;ICMP.DLL&quot;); 
    if(module == NULL) 
    { 
        fprintf (stderr, &quot;Can't load module ICMP.DLL\n&quot;); 
        getchar(); 
        return 0; 
    } 

    IcmpCreateFile = (LPICMPCREATEFILE)GetProcAddress(module, &quot;IcmpCreateFile&quot;); 
    IcmpSendEcho =  (LPICMPSENDECHO)GetProcAddress(module, &quot;IcmpSendEcho&quot;); 
    IcmpCloseHandle = (LPICMPCLOSEHANDLE)GetProcAddress(module, &quot;IcmpCloseHandle&quot;); 

    if ( !IcmpCreateFile || !IcmpSendEcho || !IcmpCloseHandle ) 
    { 
        fprintf(stderr, &quot;Can't find module entry points.\n&quot;); 
        getchar(); 
        return 0; 
    } 

    hh = IcmpCreateFile(); 

    if(!hh) 
    { 
        fprintf(stderr, &quot;Can't open the icmp handle.\n&quot;); 
        getchar(); 
        return 0; 
    } 

    printf (&quot;Ping %s [%s] mit 32 Bytes Daten:\n\n&quot;, lpszHost, lpszIP); 
    for(int i = 0; i &lt; 1; i++) 
    { 
       LPVOID reqData = (LPVOID)new BYTE[32]; 

       dwv = IcmpSendEcho(hh,                     /* Handle of ICMP &quot;file&quot; */ 
                          addr,                   /* IP address of host */ 
                          reqData,                /* ICMP request data */ 
                          32,                     /* sizeof above */ 
                          NULL,                   /* IP request options TBS */ 
                          rbuf,                   /* reply buffer */ 
                          sizeof(rbuf),           /* size of above */ 
                          3000);                  /* timeout, millisecondsp */ 

       for(unsigned int j=0; j&lt;dwv; j++) 
       { 
          ICMP_ECHO_REPLY* er = (ICMP_ECHO_REPLY*)rbuf; 
          printf(&quot;Antwort von %s: Bytes=%d Zeit=%dms TTL=%d\n&quot;, lpszIP, 32, er-&gt;RoundTripTime, er-&gt;Options.Ttl); 
       } 

       delete reqData; 
    } 

    printf (&quot;%s\n&quot;, dwv ? &quot;PING!&quot; : &quot;Pffft.&quot;); 

    IcmpCloseHandle(hh); 
    FreeLibrary(module); 
    WSACleanup(); 

    getchar(); 
    return 0; 
}
</code></pre>
<p>code besser zu lesen da: <a href="http://rafb.net/paste/results/b3086750.html" rel="nofollow">http://rafb.net/paste/results/b3086750.html</a><br />
hier kann man code nicht als cpp posten da funzt hier was net!!!</p>
<p><strong>edit:</strong> Google-URL gekürzt und Codetags hinzugefügt. Der rafb-Paste ist bereits verschollen, du solltest es besser hier posten.<br />
sfds</p>
]]></description><link>https://www.c-plusplus.net/forum/post/454218</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/454218</guid><dc:creator><![CDATA[Surfman]]></dc:creator><pubDate>Mon, 09 Feb 2004 14:55:40 GMT</pubDate></item><item><title><![CDATA[Reply to internet_connection_new on Sun, 08 Feb 2004 03:08:27 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/358">@webfritzi</a> schau mal da:<br />
<a href="http://www.crazylabs.info/crazylabs_download.php?rel=pingStat&amp;app=-v1.1.zip" rel="nofollow">http://www.crazylabs.info/crazylabs_download.php?rel=pingStat&amp;app=-v1.1.zip</a></p>
<p>da hat auch einer so einen eigenen ping geschrieben..ich kenn mich aber mit rawsockets nicht aus;-( vielleicht kannst du da war rausholen...!??</p>
<p>cu</p>
]]></description><link>https://www.c-plusplus.net/forum/post/454220</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/454220</guid><dc:creator><![CDATA[Surfman]]></dc:creator><pubDate>Sun, 08 Feb 2004 03:08:27 GMT</pubDate></item><item><title><![CDATA[Reply to internet_connection_new on Sun, 08 Feb 2004 08:32:23 GMT]]></title><description><![CDATA[<p>hi leute!! ich will das mit fets da mit mit ner pipe machen!!! wie impementiere ich das da im meinem pinp?</p>
<p>mein ping:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;string&gt; 
#include &lt;iostream&gt; 
using namespace std; 

int WinMain(HINSTANCE hInstance, HINSTANCE hPrevIsntance, LPSTR lpCmdine, int nShowCmd)
{
  WNDCLASS WndClass;
  HWND hWnd;
  MSG Msg;

  char* ptr; 
  string command; 
  string ip; 

  ptr = new char[512]; 

  ip=&quot;195.135.220.3&quot;; 

  command = &quot;PING &quot; + ip + &quot; -n 1&quot;; 
  FILE *fp= _popen(command.c_str(),&quot;r&quot;); 

  sprintf(ptr,command.c_str()); 

  while(fgets(ptr,512,fp)!=NULL) 
  { 
    command = ptr; 
    if(command.find(&quot;Antwort&quot;,0)==0){
      _pclose(fp); 
      delete [] ptr;
      MessageBox(NULL, &quot;Your are offline&quot;, &quot;info&quot;, MB_OK | MB_ICONINFORMATION);
      return(Msg.wParam); 
    } 
  } 
  _pclose(fp); 
  delete [] ptr; 
  MessageBox(NULL, &quot;Your are online&quot;, &quot;info&quot;, MB_OK | MB_ICONINFORMATION);
  return(Msg.wParam);
}

wie kann ich fets über ne pipe realisieren!!!
so wie da:
http://www.c-plusplus.net/forum/topic,14249.html

pipe code:
#include &lt;windows.h&gt; 
#include &lt;stdlib.h&gt; 
#include &lt;tchar.h&gt; 

VOID ReadConsoleApplicationHandler(LPSTR lpszBuffer) { 
MessageBoxA(NULL, lpszBuffer, &quot;Information&quot;, MB_OK); 
} 

BOOL ReadConsoleApplication(LPTSTR lpszApplication, VOID (*lpfnHandler)(LPSTR lpszBuffer)) { 
HANDLE hOutputReadTemporary = NULL; 
HANDLE hOutputRead = NULL; 
HANDLE hOutputWrite = NULL; 
HANDLE hInputWriteTemporary = NULL; 
HANDLE hInputRead = NULL; 
HANDLE hInputWrite = NULL; 
HANDLE hErrorWrite = NULL; 
SECURITY_ATTRIBUTES sa = {0}; 
PROCESS_INFORMATION pi = {0}; 
STARTUPINFO si = {0}; 
CHAR lpBuffer[256] = {0}; 
DWORD nBytesRead = 0; 

sa.nLength = sizeof(SECURITY_ATTRIBUTES); 
sa.lpSecurityDescriptor = NULL; 
sa.bInheritHandle = TRUE; 

if(CreatePipe(&amp;hOutputReadTemporary, &amp;hOutputWrite, &amp;sa, 0) == FALSE) { 
return FALSE; 
} 

if(DuplicateHandle(GetCurrentProcess(), hOutputWrite, GetCurrentProcess(), 
&amp;hErrorWrite, 0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE) { 
return FALSE; 
} 

if(CreatePipe(&amp;hInputRead, &amp;hInputWriteTemporary, &amp;sa, 0) == FALSE) { 
return FALSE; 
} 

if(DuplicateHandle(GetCurrentProcess(), hOutputReadTemporary, GetCurrentProcess(), 
&amp;hOutputRead, 0, FALSE, DUPLICATE_SAME_ACCESS) == FALSE) { 
return FALSE; 
} 

if(DuplicateHandle(GetCurrentProcess(), hInputWriteTemporary, GetCurrentProcess(), 
&amp;hInputWrite, 0, FALSE, DUPLICATE_SAME_ACCESS) == FALSE) { 
return FALSE; 
} 

if(CloseHandle(hOutputReadTemporary) == FALSE) { 
return FALSE; 
} 

if(CloseHandle(hInputWriteTemporary) == FALSE) { 
return FALSE; 
} 

si.cb = sizeof(STARTUPINFO); 
si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; 
si.hStdOutput = hOutputWrite; 
si.hStdInput = hInputRead; 
si.hStdError = hErrorWrite; 
si.wShowWindow = SW_HIDE; 

if(CreateProcess(NULL, lpszApplication, NULL, NULL, TRUE, 
CREATE_NEW_CONSOLE, NULL, NULL, &amp;si, &amp;pi) == FALSE) { 
return FALSE; 
} 

if(CloseHandle(pi.hThread) == FALSE) { 
return FALSE; 
} 

if(CloseHandle(hOutputWrite) == FALSE) { 
return FALSE; 
} 

if(CloseHandle(hInputRead) == FALSE) { 
return FALSE; 
} 

if(CloseHandle(hErrorWrite) == FALSE) { 
return FALSE; 
} 

while(TRUE) { 
if(ReadFile(hOutputRead, lpBuffer, 255, &amp;nBytesRead, NULL) == FALSE) { 
if(GetLastError() == ERROR_BROKEN_PIPE) { 
break; 
} else { 
return FALSE; 
} 
} 

lpBuffer[nBytesRead] = '\0'; 
lpfnHandler(lpBuffer); 
} 

if(CloseHandle(hOutputRead) == FALSE) { 
return FALSE; 
} 

if(CloseHandle(hInputWrite) == FALSE) { 
return FALSE; 
} 

return TRUE; 
} 

///////////////////////////////////////////////////// 
// Application's entry point 
///////////////////////////////////////////////////// 

INT WINAPI _tWinMain(HINSTANCE hInstance, 
HINSTANCE hPreviousInstance, 
LPTSTR lpszCommandLine, 
INT nShowState) { 

if(ReadConsoleApplication(TEXT(&quot;net.exe&quot;), ReadConsoleApplicationHandler) == FALSE) { 
MessageBox(NULL, TEXT(&quot;ReadConsoleApplication failed!&quot;), TEXT(&quot;Information&quot;), MB_OK); 
return EXIT_FAILURE; 
} 

return EXIT_SUCCESS; 
}
</code></pre>
<p>cu surf.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/454233</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/454233</guid><dc:creator><![CDATA[surfman.]]></dc:creator><pubDate>Sun, 08 Feb 2004 08:32:23 GMT</pubDate></item><item><title><![CDATA[Reply to internet_connection_new on Sun, 08 Feb 2004 12:05:49 GMT]]></title><description><![CDATA[<p>Ist doch alles Blödsinn. Mach das mit den Sockets.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/454338</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/454338</guid><dc:creator><![CDATA[WebFritzi]]></dc:creator><pubDate>Sun, 08 Feb 2004 12:05:49 GMT</pubDate></item><item><title><![CDATA[Reply to internet_connection_new on Sun, 08 Feb 2004 13:15:44 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/358">@webfritzi</a>: aso...ja wenn meinst....ok<br />
frage zu deinem prog. ich hab die wsock32.lib von visual studio 6 oder und bekomm paar error da bei struct usw... normal?<br />
oder soll ich das rawsockets machen, was das für vor -ode nachteil hat ka!???</p>
<p>cu surf.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/454384</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/454384</guid><dc:creator><![CDATA[surfman.]]></dc:creator><pubDate>Sun, 08 Feb 2004 13:15:44 GMT</pubDate></item><item><title><![CDATA[Reply to internet_connection_new on Sun, 08 Feb 2004 13:25:04 GMT]]></title><description><![CDATA[<p>In der MSDN/PSDK steht bei den Socket-Funktionen überall:<br />
Library: Use Ws2_32.lib</p>
]]></description><link>https://www.c-plusplus.net/forum/post/454397</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/454397</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Sun, 08 Feb 2004 13:25:04 GMT</pubDate></item><item><title><![CDATA[Reply to internet_connection_new on Sun, 08 Feb 2004 13:35:15 GMT]]></title><description><![CDATA[<p>hab auch diese ws2_32.lib unnd wsock32.lib auch dabei...aber beim compelieren sind paar error mit winsock2.h weiß jemand warum???<br />
error:</p>
<pre><code class="language-cpp">c:\programme\microsoft visual studio 6\vc98\include\winsock2.h(99) : error C2011: 'fd_set' : 'struct'-Typ-Neudefinition
c:\programme\microsoft visual studio 6\vc98\include\winsock2.h(134) : warning C4005: 'FD_SET' : Makro-Neudefinition
        c:\programme\microsoft visual studio 6\vc98\include\winsock.h(83) : Siehe vorherige Definition von 'FD_SET'
c:\programme\microsoft visual studio 6\vc98\include\winsock2.h(143) : error C2011: 'timeval' : 'struct'-Typ-Neudefinition
c:\programme\microsoft visual studio 6\vc98\include\winsock2.h(199) : error C2011: 'hostent' : 'struct'-Typ-Neudefinition
c:\programme\microsoft visual studio 6\vc98\include\winsock2.h(212) : error C2011: 'netent' : 'struct'-Typ-Neudefinition
</code></pre>
<p>usw usw.....möchte jetzt nicht error flodden!!!<br />
pingen.exe - 60 Fehler, 12 Warnung(en)</p>
<p>cu surf.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/454409</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/454409</guid><dc:creator><![CDATA[surfman.]]></dc:creator><pubDate>Sun, 08 Feb 2004 13:35:15 GMT</pubDate></item><item><title><![CDATA[Reply to internet_connection_new on Sun, 08 Feb 2004 16:12:22 GMT]]></title><description><![CDATA[<p>der code wird nicht richtig angezeigt da, deshalb musste ich neu posten!!</p>
<pre><code>#include &lt;windows.h&gt;
//#include &lt;winsock2.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;iostream.h&gt;

#define ICMP_ECHOREPLY                 0
#define ICMP_UNREACHABLE               3
#define ICMP_ECHO                      8

// 0 = Netz nicht erreichbar
#define ICMP_CODE_NETWORK_UNREACHABLE  0
// 1 = Rechner nicht erreichbar
#define ICMP_CODE_HOST_UNREACHABLE     1

// Minimalgrösse 8 Byte
#define ICMP_MIN            8

#define STATUS_FAILED       0xFFFF
#define DEF_PACKET_SIZE     32
#define MAX_PACKET          65000

/*
Der IP Header:
--------------

|  Byte 0       |   Byte 1      |  Byte 2       |  Byte 3       |

0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version|  IHL  |Type of Service|          Total Length         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|         Identification        |Flags|      Fragment Offset    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Time to Live |    Protocol   |         Header Checksum       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                       Source Address                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Destination Address                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/

struct IP_HEADER
{
  unsigned int   h_len:4;          // Länge des Headers
  unsigned int   version:4;        // IP Version
  unsigned char  tos;              // Type of service
  unsigned short total_len;        // Gesamt länge des Pakets
  unsigned short ident;            // unique identifier
  unsigned short frag_and_flags;   // flags
  unsigned char  ttl;              // TTL
  unsigned char  proto;            // Protokoll (TCP, UDP etc)
  unsigned short checksum;         // IP Checksumme
  unsigned int   sourceIP;         // Source IP
  unsigned int   destIP;           // Ziel IP
};

/*
Der ICMP Header:
----------------

|  Byte 0       |   Byte 1      |  Byte 2       |  Byte 3       |

0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type          | Code          |     ICMP Header Prüfsumme     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Identifikatior |Sequenz Nummer |                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                      Timestamp                                |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

*/

struct ICMP_HEADER
{
  char           i_type;    // Type
  char           i_code;    // Code
  unsigned short i_cksum;   // Prüfsumme
  unsigned short i_id;      // Identifikatior
  unsigned short i_seq;     // Sequenz Nummer
  unsigned long  timestamp; // Um die benötigte Zeit zu messen
};

long WinsockStartup();
void FillIcmpData(char* icmp_data, int datasize);
unsigned short checksum(unsigned short *buffer, int size);
void DecodeResponse(char *buf, int bytes, SOCKADDR_IN *from);

//int main(int argc, char** argv)
int main()
{
  SOCKET sockRaw;
  SOCKADDR_IN addrDest;
  SOCKADDR_IN addrFrom;
  int addrFromLen = sizeof(addrFrom);
  HOSTENT* ptrHostent;
  unsigned long datasize;
  int RecvTimeout = 1000;
  char *dest_ip;
  char *icmp_data;
  char *recvbuf;
  unsigned int addr=0;
  unsigned short seq_no = 0;
  int BytesReceived;
  int BytesSent;
  long rc;
  //const char* ip=&quot;195.135.220.3&quot;;

  /*if(argc &lt; 2)
  {
    cout &lt;&lt; &quot;Error: To few Arguments &quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;\nUsage: ping &lt;host&gt; [Bytes to send]&quot; &lt;&lt; endl;
    return 0;
  }*/

  rc = WinsockStartup();
  if (rc == SOCKET_ERROR)
  {
    cout &lt;&lt; &quot;Error: WinsockStartup failed: &quot; &lt;&lt; WSAGetLastError() &lt;&lt; endl;
    return SOCKET_ERROR;
  }
  sockRaw = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
  if (sockRaw == INVALID_SOCKET)
  {
    cout &lt;&lt; &quot;Error: Cannot create Socket: &quot; &lt;&lt; WSAGetLastError() &lt;&lt; endl;
    return SOCKET_ERROR;
  }
  rc = setsockopt(sockRaw,SOL_SOCKET,SO_RCVTIMEO,(char*)&amp;RecvTimeout, sizeof(RecvTimeout));
  if(rc == SOCKET_ERROR)
  {
    cout &lt;&lt; &quot;Error: Cannot set Recv Timeout: &quot; &lt;&lt; WSAGetLastError() &lt;&lt; endl;
    return SOCKET_ERROR;
  }

  ptrHostent = &quot;195.135.220.3&quot;;
  /*ptrHostent = gethostbyname(argv[1]);
  if (!ptrHostent)
  {
    addr = inet_addr(argv[1]);
  }*/

  if ((!ptrHostent)  &amp;&amp; (addr == INADDR_NONE) )
  {
    cout &lt;&lt; &quot;Error: Cannot resolve Host: &quot; &lt;&lt; WSAGetLastError() &lt;&lt; endl;
    return SOCKET_ERROR;
  }
  if (ptrHostent != NULL)
  {
    memcpy(&amp;(addrDest.sin_addr),ptrHostent-&gt;h_addr, ptrHostent-&gt;h_length);
  }
  else
  {
    addrDest.sin_addr.s_addr = addr;
  }
  if (ptrHostent)
  {
    addrDest.sin_family = ptrHostent-&gt;h_addrtype;
  }
  else
  {
    addrDest.sin_family = AF_INET;
  }

  // Konvertiert eine Netzwerk Adresse (SOCKADDR_IN) in einen String im Punkt Format (x.x.x.x)
  dest_ip = inet_ntoa(addrDest.sin_addr);

  //if (argc &gt;2)
  //{
    datasize = 2;
    //datasize = atoi(argv[2]);
    if (datasize == 0)
    {
      datasize = DEF_PACKET_SIZE;
    }
    if (datasize &gt; MAX_PACKET)
    {
      cout &lt;&lt; &quot;Error: Data size more then &quot; &lt;&lt; MAX_PACKET &lt;&lt; &quot; Bytes or less then 0 Bytes&quot; &lt;&lt; endl;
      cout &lt;&lt; &quot;I'll take the default size...&quot; &lt;&lt; endl;
      datasize = DEF_PACKET_SIZE;
    }
  /*}
  else
  {
    datasize = DEF_PACKET_SIZE;
  }*/
  datasize += sizeof(ICMP_HEADER);

  icmp_data = (char*)malloc(MAX_PACKET);
  recvbuf = (char*)malloc(MAX_PACKET+sizeof(IP_HEADER)+sizeof(ICMP_HEADER));

  if (!icmp_data || !recvbuf)
  {
    cout &lt;&lt; &quot;Error: Not enough Memory: &quot; &lt;&lt; GetLastError() &lt;&lt; endl;
    return 0;
  }

  FillIcmpData(icmp_data,datasize);

  while(1)
  {
    ((ICMP_HEADER*)icmp_data)-&gt;i_cksum = 0;
    ((ICMP_HEADER*)icmp_data)-&gt;timestamp = GetTickCount();

    ((ICMP_HEADER*)icmp_data)-&gt;i_seq = seq_no++;
    ((ICMP_HEADER*)icmp_data)-&gt;i_cksum = checksum((unsigned short*)icmp_data, datasize);

    BytesSent = sendto(sockRaw,icmp_data,datasize,0,(SOCKADDR*)&amp;addrDest, sizeof(addrDest));
    if (BytesSent == SOCKET_ERROR)
    {
      if (WSAGetLastError() == WSAETIMEDOUT)
      {
        cout &lt;&lt; &quot;timed out\n&quot; &lt;&lt; endl;
        continue;
      }
      cout &lt;&lt; &quot;sendto failed: &quot; &lt;&lt; WSAGetLastError() &lt;&lt; endl;
      return 0;
    }
    if (BytesSent &lt; datasize )
    {
      cout &lt;&lt;&quot;Wrote &quot; &lt;&lt; BytesSent &lt;&lt; &quot; bytes&quot; &lt;&lt; endl;
    }
    BytesReceived = recvfrom(sockRaw,recvbuf,MAX_PACKET+sizeof(IP_HEADER)+sizeof(ICMP_HEADER),0,(SOCKADDR*)&amp;addrFrom, &amp;addrFromLen);
    if (BytesReceived == SOCKET_ERROR)
    {
      if (WSAGetLastError() == WSAETIMEDOUT)
      {
        cout &lt;&lt; &quot;timed out&quot; &lt;&lt; endl;
        continue;
      }
      cout &lt;&lt; &quot;recvfrom failed: &quot; &lt;&lt; WSAGetLastError() &lt;&lt; endl;
      return 0;
    }
    DecodeResponse(recvbuf,BytesReceived,&amp;addrFrom);
    Sleep(1000);
  }
}

/*
Die Antwort die wir empfangen ist ein IP Paket. Wir müssen nun den IP
Header decodieren um die ICMP Daten lesen zu können
*/

void DecodeResponse(char *buf, int bytes, SOCKADDR_IN *from)
{
  IP_HEADER   *IpHeader;
  ICMP_HEADER *IcmpHeader;
  unsigned short IpHeaderLen;

  IpHeader = (IP_HEADER*)buf;
  IpHeaderLen = IpHeader-&gt;h_len * 4 ; // number of 32-bit words *4 = bytes

  if (bytes  &lt; IpHeaderLen + ICMP_MIN)
  {
    cout &lt;&lt; &quot;Too few bytes from &quot; &lt;&lt; inet_ntoa(from-&gt;sin_addr) &lt;&lt; endl;
  }
  IcmpHeader = (ICMP_HEADER*)(buf + IpHeaderLen);

  if (IcmpHeader-&gt;i_type != ICMP_ECHOREPLY)
  {
    if (IcmpHeader-&gt;i_type == ICMP_UNREACHABLE)
    {
      cout &lt;&lt; &quot;Reply from &quot; &lt;&lt; inet_ntoa(from-&gt;sin_addr);
      if(IcmpHeader-&gt;i_code == ICMP_CODE_HOST_UNREACHABLE)
      {
        cout &lt;&lt; &quot;: Destination Host unreachable !&quot; &lt;&lt; endl;
        return;
      }
      if(IcmpHeader-&gt;i_code == ICMP_CODE_NETWORK_UNREACHABLE)
      {
        cout &lt;&lt; &quot;: Destination Network unreachable !&quot; &lt;&lt; endl;
        return;
      }
    }
    else
    {
      cout &lt;&lt; &quot;non-echo type &quot; &lt;&lt; (int)IcmpHeader-&gt;i_type &lt;&lt;&quot; received&quot; &lt;&lt; endl;
      return;
    }
  }

  if (IcmpHeader-&gt;i_id != (unsigned short)GetCurrentProcessId())
  {
    cout &lt;&lt; &quot;someone else's packet!&quot; &lt;&lt; endl;
    return ;
  }

  cout &lt;&lt; bytes &lt;&lt; &quot; bytes from &quot; &lt;&lt; inet_ntoa(from-&gt;sin_addr);
  cout &lt;&lt; &quot; icmp_seq = &quot; &lt;&lt; IcmpHeader-&gt;i_seq;
  cout &lt;&lt; &quot; time: &quot; &lt;&lt; GetTickCount()-IcmpHeader-&gt;timestamp &lt;&lt; &quot; ms &quot; &lt;&lt; endl;
}

unsigned short checksum(unsigned short *buffer, int size)
{
  unsigned long cksum=0;
  while(size &gt;1)
  {
    cksum+=*buffer++;
    size -=sizeof(unsigned short);
  }

  if(size)
  {
    cksum += *(unsigned char*)buffer;
  }

  cksum = (cksum &gt;&gt; 16) + (cksum &amp; 0xffff);
  cksum += (cksum &gt;&gt;16);
  return (unsigned short)(~cksum);
}

/*
Hilfs Funktion um unseren ICMP Header zu füllen
*/
void FillIcmpData(char * icmp_data, int datasize){

  ICMP_HEADER *icmp_hdr;
  char *datapart;

  icmp_hdr = (ICMP_HEADER*)icmp_data;

  icmp_hdr-&gt;i_type = ICMP_ECHO;
  icmp_hdr-&gt;i_code = 0;
  icmp_hdr-&gt;i_id = (unsigned short)GetCurrentProcessId();
  icmp_hdr-&gt;i_cksum = 0;
  icmp_hdr-&gt;i_seq = 0;

  datapart = icmp_data + sizeof(ICMP_HEADER);
  // Den Buffer mit etwas füllen
  memset(datapart,'C', datasize - sizeof(ICMP_HEADER));
}

long WinsockStartup()
{
  long rc;

  WORD wVersionRequested;
  WSADATA wsaData;
  wVersionRequested = MAKEWORD(2, 1);

  rc = WSAStartup( wVersionRequested, &amp;wsaData );
  return rc;
}

--------------------Konfiguration: pingen1 - Win32 Debug--------------------
Kompilierung läuft...
main.cpp
C:\Dokumente und Einstellungen\Gerald\Desktop\pingen1\main.cpp(138) : error C2440: '=' : 'char [14]' kann nicht in 'struct hostent *' konvertiert werden
        Die Typen, auf die verwiesen wird, sind nicht verwandt; die Konvertierung erfordert einen reinterpret_cast-Operator oder eine Typumwandlung im C- oder Funktionsformat
C:\Dokumente und Einstellungen\Gerald\Desktop\pingen1\main.cpp(221) : warning C4018: '&lt;' : Konflikt zwischen signed und unsigned
Fehler beim Ausführen von cl.exe.

pingen1.exe - 1 Fehler, 1 Warnung(en)
</code></pre>
<p>der error!??? cu</p>
]]></description><link>https://www.c-plusplus.net/forum/post/454531</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/454531</guid><dc:creator><![CDATA[surfman.]]></dc:creator><pubDate>Sun, 08 Feb 2004 16:12:22 GMT</pubDate></item><item><title><![CDATA[Reply to internet_connection_new on Sun, 08 Feb 2004 16:17:03 GMT]]></title><description><![CDATA[<p>Poste doch bitte erstmal nur die entsprechende Zeile - habe keine Lust zu zählen :p</p>
]]></description><link>https://www.c-plusplus.net/forum/post/454532</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/454532</guid><dc:creator><![CDATA[flenders]]></dc:creator><pubDate>Sun, 08 Feb 2004 16:17:03 GMT</pubDate></item><item><title><![CDATA[Reply to internet_connection_new on Sun, 08 Feb 2004 19:45:46 GMT]]></title><description><![CDATA[<p>ping ist fertig soweit: wird alles schön in message boxen ausgegeben;-)<br />
aber ich will noch so ne auswertung machen....wie viele pakete angekommen sind und<br />
gesendet wurden...so wie bei <a href="http://command.com" rel="nofollow">command.com</a> und dann ping!!!</p>
<p>was meint ihr zum programm funzt alles bei euch einwandfrei??</p>
<p>cu surf.</p>
<pre><code>/******************************************************************************

Programm: Ping

Allgemeines zu ICMP:
--------------------

Echo Request, Echo Reply
------------------------

Diese Meldungen dienen zur Überprüfung ob ein Ziel erreichbar und
aktiv ist. Der Sender des Echo Request wartet auf eine Echo Reply
Message, die er nur erhält, wenn der Zielrechner aktiv ist. Als ICMP
Typ wurde die Nummer 8 für den Request und 0 für den Echo Reply
definiert. Der Code ist in beiden Fällen auf 0 gesetzt. Außerdem ist ein
ICMP Echo Identifikator definiert, welcher vom Sender des
Datagramms erzeugt wird und zur Identifikation des Prozesses dient.
Der Empfänger schickt den Reply an diesen Port. Eine Echo Sequenz
Nummer wird zur fortlaufenden Numerierung des Datagramms
genutzt. Der Empfänger nutzt die Nummer bei der Antwort und
ermöglicht dem Sender des Echo Request die Überprüfung der
Richtigkeit der Antwort. Die ICMP Echo Daten enthalten einen Echo
String, der vom Empfänger an den Sender zurückgeschickt wird.

Destination Unreachable
-----------------------

Diese Nachricht wird an den Sender des Datagramms geschickt,
wenn ein Subnetzwerk oder Router den Zielrechner nicht erreichen
kann oder das Paket nicht ausgeliefert werden kann weil das Don´t
Fragment Bit gesetzt ist und das Paket für ein Netzwerk zu groß ist.
Die Nachricht wird vom Router generiert sofern es sich um ein nicht
erreichbares Netzwerk oder einen unerreichbaren Zielrechner handelt.
Sollte es sich jedoch um einen unerreichbaren Port handeln so schickt
diese Meldung der Zielrechner.

ICMP Typ

Zur Unterscheidung der einzelnen ICMP Meldungen wurden ICMP
Nummern definiert. Die Destination Unreachable Meldung hat die
Nummer 3.

ICMP Code

Der ICMP Code teilt dem Sender mit, weshalb sein Datagramm nicht
übermittelt werden konnte. Es sind die folgenden Destination
Unreachable Codes definiert:

0= Netz nicht erreichbar
1= Rechner nicht erreichbar
2= Protokoll nicht erreichbar
3= Port nicht erreichbar
4= Fragmentierung notwendig, jedoch nicht möglich wegen gesetztem DF Bit
5= Source Route nicht erreichbar

******************************************************************************/

#include &lt;windows.h&gt; 
#include &lt;stdlib.h&gt;
#include &lt;string&gt; 
#include &lt;sstream&gt; 
#include &lt;iostream&gt;
#include &lt;stdio.h&gt;
#include &lt;iostream.h&gt; 

using namespace std;

#define ICMP_ECHOREPLY                 0 
#define ICMP_UNREACHABLE               3 
#define ICMP_ECHO                      8 

// 0 = Netz nicht erreichbar 
#define ICMP_CODE_NETWORK_UNREACHABLE  0 
// 1 = Rechner nicht erreichbar 
#define ICMP_CODE_HOST_UNREACHABLE     1 

// Minimalgrösse 8 Byte 
#define ICMP_MIN            8 

#define STATUS_FAILED       0xFFFF 
#define DEF_PACKET_SIZE     32 
#define MAX_PACKET          65000 

/* 
Der IP Header: 
-------------- 

|  Byte 0       |   Byte 1      |  Byte 2       |  Byte 3       | 

0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
|Version|  IHL  |Type of Service|          Total Length         | 
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
|         Identification        |Flags|      Fragment Offset    | 
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
|  Time to Live |    Protocol   |         Header Checksum       | 
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
|                       Source Address                          | 
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
|                    Destination Address                        | 
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
*/ 

struct IP_HEADER 
{ 
  unsigned int   h_len:4;          // Länge des Headers 
  unsigned int   version:4;        // IP Version 
  unsigned char  tos;              // Type of service 
  unsigned short total_len;        // Gesamt länge des Pakets 
  unsigned short ident;            // unique identifier 
  unsigned short frag_and_flags;   // flags 
  unsigned char  ttl;              // TTL 
  unsigned char  proto;            // Protokoll (TCP, UDP etc) 
  unsigned short checksum;         // IP Checksumme 
  unsigned int   sourceIP;         // Source IP 
  unsigned int   destIP;           // Ziel IP 
}; 

/* 
Der ICMP Header: 
---------------- 

|  Byte 0       |   Byte 1      |  Byte 2       |  Byte 3       | 

0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
| Type          | Code          |     ICMP Header Prüfsumme     | 
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
|Identifikatior |Sequenz Nummer |                               | 
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
|                      Timestamp                                | 
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 

*/ 

struct ICMP_HEADER 
{ 
  char           i_type;    // Type 
  char           i_code;    // Code 
  unsigned short i_cksum;   // Prüfsumme 
  unsigned short i_id;      // Identifikatior 
  unsigned short i_seq;     // Sequenz Nummer 
  unsigned long  timestamp; // Um die benötigte Zeit zu messen 
}; 

long WinsockStartup(); 
void FillIcmpData(char* icmp_data, int datasize); 
unsigned short checksum(unsigned short *buffer, int size); 
void DecodeResponse(char *buf, int bytes, SOCKADDR_IN *from);

// Für Messagebox Ausgabe
ostringstream os; 

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevIsntance, LPSTR lpCmdine, int nShowCmd)
{
  WNDCLASS WndClass;
  HWND hWnd;
  MSG Msg;

  SOCKET sockRaw; 
  SOCKADDR_IN addrDest; 
  SOCKADDR_IN addrFrom; 
  int addrFromLen = sizeof(addrFrom); 
  HOSTENT* ptrHostent; 
  unsigned long datasize; 
  int RecvTimeout = 1000; 
  char *dest_ip; 
  char *icmp_data; 
  char *recvbuf; 
  unsigned int addr=0; 
  unsigned short seq_no = 0; 
  int BytesReceived; 
  int BytesSent; 
  long rc; 
  unsigned ping_anzahl=0;
  // Die IP fuer anpingen: http://suse.de
  const char* ip=&quot;195.135.220.3&quot;; 

  rc = WinsockStartup(); 
  if (rc == SOCKET_ERROR) 
  { 
	os &lt;&lt; &quot;Error: WinsockStartup failed: &quot; &lt;&lt; WSAGetLastError(); 
	MessageBox(NULL, os.str().c_str(), &quot;info&quot;, MB_OK | MB_ICONINFORMATION);
	os.str(&quot;&quot;);
    return SOCKET_ERROR; 
  } 
  sockRaw = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); 
  if (sockRaw == INVALID_SOCKET) 
  { 
	os &lt;&lt; &quot;Error: Cannot create Socket: &quot; &lt;&lt; WSAGetLastError(); 
	MessageBox(NULL, os.str().c_str(), &quot;info&quot;, MB_OK | MB_ICONINFORMATION);
	os.str(&quot;&quot;);
    return SOCKET_ERROR; 
  } 
  rc = setsockopt(sockRaw,SOL_SOCKET,SO_RCVTIMEO,(char*)&amp;RecvTimeout, sizeof(RecvTimeout)); 
  if(rc == SOCKET_ERROR) 
  { 
	os &lt;&lt; &quot;Error: Cannot set Recv Timeout: &quot; &lt;&lt; WSAGetLastError();
	MessageBox(NULL, os.str().c_str(), &quot;info&quot;, MB_OK | MB_ICONINFORMATION);
	os.str(&quot;&quot;);
    return SOCKET_ERROR; 
  } 

  // Ip Adresse in ptrHostent geben
  ptrHostent = gethostbyname(ip); 

  if ((!ptrHostent)  &amp;&amp; (addr == INADDR_NONE) ) 
  { 
	os &lt;&lt; &quot;Error: Cannot resolve Host: &quot; &lt;&lt; WSAGetLastError(); 
	MessageBox(NULL, os.str().c_str(), &quot;info&quot;, MB_OK | MB_ICONINFORMATION);
    return SOCKET_ERROR; 
  } 
  if (ptrHostent != NULL) 
  { 
    memcpy(&amp;(addrDest.sin_addr),ptrHostent-&gt;h_addr, ptrHostent-&gt;h_length); 
  } 
  else 
  { 
    addrDest.sin_addr.s_addr = addr; 
  } 
  if (ptrHostent) 
  { 
    addrDest.sin_family = ptrHostent-&gt;h_addrtype; 
  } 
  else 
  { 
    addrDest.sin_family = AF_INET; 
  } 

  // Konvertiert eine Netzwerk Adresse (SOCKADDR_IN) in einen String im Punkt Format (x.x.x.x) 
  dest_ip = inet_ntoa(addrDest.sin_addr); 

  // Gröss des Datenpaketes
  datasize = 32; 

  if (datasize == 0) 
  { 
     datasize = DEF_PACKET_SIZE; 
  } 

  if (datasize &gt; MAX_PACKET) 
  { 
     os &lt;&lt; &quot;Error: Data size more then &quot; &lt;&lt; MAX_PACKET &lt;&lt; &quot; Bytes or less then 0 Bytes&quot;; 
     MessageBox(NULL, os.str().c_str(), &quot;info&quot;, MB_OK | MB_ICONINFORMATION);
	 os.str(&quot;&quot;);

	 os &lt;&lt; &quot;I'll take the default size...&quot;;
	 MessageBox(NULL, os.str().c_str(), &quot;info&quot;, MB_OK | MB_ICONINFORMATION);
	 os.str(&quot;&quot;);
     datasize = DEF_PACKET_SIZE; 
  } 

  datasize += sizeof(ICMP_HEADER); 

  icmp_data = (char*)malloc(MAX_PACKET); 
  recvbuf = (char*)malloc(MAX_PACKET+sizeof(IP_HEADER)+sizeof(ICMP_HEADER)); 

  if (!icmp_data || !recvbuf) 
  { 
	os &lt;&lt; &quot;Error: Not enough Memory: &quot; &lt;&lt; GetLastError(); 
    MessageBox(NULL, os.str().c_str(), &quot;info&quot;, MB_OK | MB_ICONINFORMATION);
	os.str(&quot;&quot;);
    return 0; 
  } 

  FillIcmpData(icmp_data,datasize); 

  os &lt;&lt; &quot;Ping wird ausgefuehrt fuer &quot; &lt;&lt; ip &lt;&lt; &quot; mit &quot; &lt;&lt; datasize &lt;&lt; &quot; Bytes Daten&quot;;
  MessageBox(NULL, os.str().c_str(), &quot;info&quot;, MB_OK | MB_ICONINFORMATION);
  os.str(&quot;&quot;);

  while(ping_anzahl&lt;4) 
  { 
    ((ICMP_HEADER*)icmp_data)-&gt;i_cksum = 0; 
    ((ICMP_HEADER*)icmp_data)-&gt;timestamp = GetTickCount(); 

    ((ICMP_HEADER*)icmp_data)-&gt;i_seq = seq_no++; 
    ((ICMP_HEADER*)icmp_data)-&gt;i_cksum = checksum((unsigned short*)icmp_data, datasize); 

    BytesSent = sendto(sockRaw,icmp_data,datasize,0,(SOCKADDR*)&amp;addrDest, sizeof(addrDest)); 
    if (BytesSent == SOCKET_ERROR) 
    { 
      if (WSAGetLastError() == WSAETIMEDOUT) 
      { 
		os &lt;&lt; &quot;timed out&quot;; 
        MessageBox(NULL, os.str().c_str(), &quot;info&quot;, MB_OK | MB_ICONINFORMATION);
		os.str(&quot;&quot;);
        continue; 
      } 
	  os &lt;&lt; &quot;sendto failed: &quot; &lt;&lt; WSAGetLastError();
	  MessageBox(NULL, os.str().c_str(), &quot;info&quot;, MB_OK | MB_ICONINFORMATION);
	  os.str(&quot;&quot;);
      return 0; 
    } 
    if (BytesSent &lt; datasize ) 
    { 
	   os &lt;&lt;&quot;Wrote &quot; &lt;&lt; BytesSent &lt;&lt; &quot; bytes&quot;;
	   MessageBox(NULL, os.str().c_str(), &quot;info&quot;, MB_OK | MB_ICONINFORMATION);	
       os.str(&quot;&quot;);
	} 
    BytesReceived = recvfrom(sockRaw,recvbuf,MAX_PACKET+sizeof(IP_HEADER)+sizeof(ICMP_HEADER),0,(SOCKADDR*)&amp;addrFrom, &amp;addrFromLen); 
    if (BytesReceived == SOCKET_ERROR) 
    { 
      if (WSAGetLastError() == WSAETIMEDOUT) 
      { 
		os &lt;&lt; &quot;timed out&quot;; 
		MessageBox(NULL, os.str().c_str(), &quot;info&quot;, MB_OK | MB_ICONINFORMATION);
		os.str(&quot;&quot;);
        continue; 
      } 
	  os &lt;&lt; &quot;recvfrom failed: &quot; &lt;&lt; WSAGetLastError();
	  MessageBox(NULL, os.str().c_str(), &quot;info&quot;, MB_OK | MB_ICONINFORMATION);
	  os.str(&quot;&quot;);
      return 0; 
    } 
    DecodeResponse(recvbuf,BytesReceived,&amp;addrFrom); 
    Sleep(1000);
	ping_anzahl++;
  } 

  return(Msg.wParam);
} 

/* 
Die Antwort die wir empfangen ist ein IP Paket. Wir müssen nun den IP 
Header decodieren um die ICMP Daten lesen zu können 
*/ 

void DecodeResponse(char *buf, int bytes, SOCKADDR_IN *from) 
{ 
  IP_HEADER   *IpHeader; 
  ICMP_HEADER *IcmpHeader; 
  unsigned short IpHeaderLen; 

  IpHeader = (IP_HEADER*)buf; 
  IpHeaderLen = IpHeader-&gt;h_len * 4 ; // number of 32-bit words *4 = bytes 

  if (bytes  &lt; IpHeaderLen + ICMP_MIN) 
  { 
	 os &lt;&lt; &quot;Too few bytes from &quot; &lt;&lt; inet_ntoa(from-&gt;sin_addr);
	 MessageBox(NULL, os.str().c_str(), &quot;info&quot;, MB_OK | MB_ICONINFORMATION);
	 os.str(&quot;&quot;);
  } 
  IcmpHeader = (ICMP_HEADER*)(buf + IpHeaderLen); 

  if (IcmpHeader-&gt;i_type != ICMP_ECHOREPLY) 
  { 
    if (IcmpHeader-&gt;i_type == ICMP_UNREACHABLE) 
    { 
	  os &lt;&lt; &quot;Reply from &quot; &lt;&lt; inet_ntoa(from-&gt;sin_addr);
	  MessageBox(NULL, os.str().c_str(), &quot;info&quot;, MB_OK | MB_ICONINFORMATION);
	  os.str(&quot;&quot;);
      if(IcmpHeader-&gt;i_code == ICMP_CODE_HOST_UNREACHABLE) 
      { 
		os &lt;&lt; &quot;: Destination Host unreachable !&quot;; 
		MessageBox(NULL, os.str().c_str(), &quot;info&quot;, MB_OK | MB_ICONINFORMATION);
		os.str(&quot;&quot;);
        return; 
      } 
      if(IcmpHeader-&gt;i_code == ICMP_CODE_NETWORK_UNREACHABLE) 
      { 
		os &lt;&lt; &quot;: Destination Network unreachable !&quot;;
		MessageBox(NULL, os.str().c_str(), &quot;info&quot;, MB_OK | MB_ICONINFORMATION);
		os.str(&quot;&quot;);
        return; 
      } 
    } 
    else 
    { 
	  os &lt;&lt; &quot;non-echo type &quot; &lt;&lt; (int)IcmpHeader-&gt;i_type &lt;&lt;&quot; received&quot;;
	  MessageBox(NULL, os.str().c_str(), &quot;info&quot;, MB_OK | MB_ICONINFORMATION);
	  os.str(&quot;&quot;);
      return; 
    } 
  } 

  if (IcmpHeader-&gt;i_id != (unsigned short)GetCurrentProcessId()) 
  { 
	os &lt;&lt; &quot;someone else's packet!&quot; &lt;&lt; endl;
	MessageBox(NULL, os.str().c_str(), &quot;info&quot;, MB_OK | MB_ICONINFORMATION);
	os.str(&quot;&quot;);
    return ; 
  } 

  os &lt;&lt; bytes &lt;&lt; &quot; bytes from &quot; &lt;&lt; inet_ntoa(from-&gt;sin_addr);
  os &lt;&lt; &quot; icmp_seq = &quot; &lt;&lt; IcmpHeader-&gt;i_seq;
  os &lt;&lt; &quot; time: &quot; &lt;&lt; GetTickCount()-IcmpHeader-&gt;timestamp &lt;&lt; &quot; ms &quot;;
  MessageBox(NULL, os.str().c_str(), &quot;info&quot;, MB_OK | MB_ICONINFORMATION);
  os.str(&quot;&quot;);
} 

unsigned short checksum(unsigned short *buffer, int size) 
{ 
  unsigned long cksum=0; 
  while(size &gt;1) 
  { 
    cksum+=*buffer++; 
    size -=sizeof(unsigned short); 
  } 

  if(size) 
  { 
    cksum += *(unsigned char*)buffer; 
  } 

  cksum = (cksum &gt;&gt; 16) + (cksum &amp; 0xffff); 
  cksum += (cksum &gt;&gt;16); 
  return (unsigned short)(~cksum); 
} 

/* 
Hilfs Funktion um unseren ICMP Header zu füllen 
*/ 
void FillIcmpData(char * icmp_data, int datasize){ 

  ICMP_HEADER *icmp_hdr; 
  char *datapart; 

  icmp_hdr = (ICMP_HEADER*)icmp_data; 

  icmp_hdr-&gt;i_type = ICMP_ECHO; 
  icmp_hdr-&gt;i_code = 0; 
  icmp_hdr-&gt;i_id = (unsigned short)GetCurrentProcessId(); 
  icmp_hdr-&gt;i_cksum = 0; 
  icmp_hdr-&gt;i_seq = 0; 

  datapart = icmp_data + sizeof(ICMP_HEADER); 
  // Den Buffer mit etwas füllen 
  memset(datapart,'C', datasize - sizeof(ICMP_HEADER)); 
} 

long WinsockStartup() 
{ 
  long rc; 

  WORD wVersionRequested; 
  WSADATA wsaData; 
  wVersionRequested = MAKEWORD(2, 1); 

  rc = WSAStartup( wVersionRequested, &amp;wsaData ); 
  return rc; 
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/454706</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/454706</guid><dc:creator><![CDATA[Surfman]]></dc:creator><pubDate>Sun, 08 Feb 2004 19:45:46 GMT</pubDate></item><item><title><![CDATA[Reply to internet_connection_new on Sun, 08 Feb 2004 20:08:26 GMT]]></title><description><![CDATA[<p>Setzte doch bitte nicht immer wieder den ganzen Code ins Forum - Schreib es von mir aus einmal rein und editiere es dann</p>
]]></description><link>https://www.c-plusplus.net/forum/post/454726</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/454726</guid><dc:creator><![CDATA[flenders]]></dc:creator><pubDate>Sun, 08 Feb 2004 20:08:26 GMT</pubDate></item><item><title><![CDATA[Reply to internet_connection_new on Sun, 08 Feb 2004 21:59:19 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/1644">@flenders</a>: sorry mach ich nun....<br />
wenn wer den pinger getestet hat..bitte antworten!</p>
<p>cu surf.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/454794</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/454794</guid><dc:creator><![CDATA[surfman.]]></dc:creator><pubDate>Sun, 08 Feb 2004 21:59:19 GMT</pubDate></item><item><title><![CDATA[Reply to internet_connection_new on Mon, 09 Feb 2004 03:10:56 GMT]]></title><description><![CDATA[<p>Habs getestet. Erstens dauert das Pingen sehr lange (immer so um die 700 ms), und zweitens bekomme ich nach 3-4 Malen eine AccessViolation.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/454837</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/454837</guid><dc:creator><![CDATA[WebFritzi]]></dc:creator><pubDate>Mon, 09 Feb 2004 03:10:56 GMT</pubDate></item><item><title><![CDATA[Reply to internet_connection_new on Mon, 09 Feb 2004 12:14:51 GMT]]></title><description><![CDATA[<p>WebFritzi schrieb:</p>
<blockquote>
<p>Habs getestet. Erstens dauert das Pingen sehr lange (immer so um die 700 ms), und zweitens bekomme ich nach 3-4 Malen eine AccessViolation.</p>
</blockquote>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/358">@webfritzi</a>:<br />
komisch, komisch....dann ich hab grad noch mal getestet mein prog braucht so im schnitt 60-80ms fürs pingen und ich hab habs so eingestellt das er 4 mal datenpakete zum server schickt...so wies der <a href="http://command.com" rel="nofollow">command.com</a> ping auch tut!!<br />
und accessvoilation hab ich auch nie!! hast due den richtigen code? denn ich versteh das nicht ganz...wo gibs accessvoilation?</p>
<p>cu surf.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/455039</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/455039</guid><dc:creator><![CDATA[Surfman]]></dc:creator><pubDate>Mon, 09 Feb 2004 12:14:51 GMT</pubDate></item></channel></rss>