home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / MSDOS / WATTCP / UNZIPPED / WNWATTCP / SRC / PCPING.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-06  |  1.7 KB  |  81 lines

  1. #include "copyright.h"
  2. #include "wattcp.h"
  3. #include "errors.h"
  4.  
  5. typedef struct icmp_echo {
  6.     byte    type;
  7.     byte    code;
  8.     word    checksum;
  9.     word    identifier;
  10.     word    sequence;
  11.     longword    index;
  12. };
  13.  
  14. typedef struct _pkt {
  15.     in_Header     in;
  16.     struct icmp_echo icmp;
  17.     in_Header    data;
  18. };
  19.  
  20.  
  21.  
  22. int _ping( longword host, longword countnum )
  23. {
  24.     eth_address dest;
  25.     struct _pkt *p;
  26.     in_Header *ip;
  27.     struct icmp_echo *icmp;
  28.     static word icmp_id = 0;
  29.  
  30.     if ((host & 0xff) == 0xff ) {
  31.     return(ER_PINGNET);
  32.     }
  33.     if ( ! _arp_resolve( host, &dest )) {
  34.     return(ER_RESOLVE);
  35.     }
  36.  
  37. #ifdef WINDOWS
  38.     /* nothing */
  39. #else
  40.     if (debug_on) {
  41.     outs("\n\rDEBUG: destination hardware :");
  42.     outhexes( &dest, 6 );
  43.     outs("\n\r");
  44.     }
  45. #endif
  46.  
  47.     p = (struct _pkt*)_eth_formatpacket( &dest, 8 );
  48.  
  49.     ip = &p->in;
  50.     icmp = &p->icmp;
  51.  
  52.     icmp->type = 8;
  53.     icmp->code = 0;
  54.     icmp->index = countnum;
  55.     *(longword *)(&icmp->identifier) = set_timeout( 1 );
  56. /*
  57.     icmp->identifier = ++icmp_id;
  58.     icmp->sequence = icmp_id;
  59. */
  60.     /* finish the icmp checksum portion */
  61.     icmp->checksum = 0;
  62.     icmp->checksum = ~checksum( icmp, sizeof( struct icmp_echo));
  63.  
  64.     /* encapsulate into a nice ip packet */
  65.     ip->ver = 4;
  66.     ip->hdrlen = 5;
  67.     ip->length = intel16( sizeof( in_Header ) + sizeof( struct icmp_echo));
  68.     ip->tos = 0;
  69.     ip->identification = intel16( icmp_id ++);    /* not using ip id */
  70.     ip->frag = 0;
  71.     ip->ttl = 250;
  72.     ip->proto = ICMP_PROTO;
  73.     ip->checksum = 0;
  74.     ip->source = intel( my_ip_addr );
  75.     ip->destination = intel( host );
  76.     ip->checksum = ~ checksum( ip, sizeof( in_Header ));
  77.  
  78.     return( _eth_send( intel16( ip->length )));
  79. }
  80.  
  81.