home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / SRC / SRC15B97.ZIP / WATTSRC.ZIP / PCPING.C < prev    next >
Text File  |  1997-03-08  |  2KB  |  60 lines

  1. #include <mem.h>
  2. #include <copyright.h>
  3. #include <wattcp.h>
  4.  
  5. #include <icmp.h>
  6.  
  7. int _send_ping( longword host, longword countnum, byte ttl, byte tos, longword *theid )
  8. {
  9.     eth_address dest;
  10.     struct _pkt *p;
  11.     in_Header *ip;
  12.     struct icmp_echo *icmp;
  13.     static word icmp_id = 0;
  14.  
  15.     if ((host & 0xff) == 0xff ) {
  16.         outs( "Cannot ping a network!\n\r");
  17.         return( -1 );
  18.     }
  19.     if ( ! _arp_resolve( host, &dest, 0 )) {
  20.         outs( "Cannot resolve host's hardware address\n\r");
  21.         return( -1 );
  22.     }
  23.  
  24.     p = (struct _pkt*)_eth_formatpacket( &dest, 8 );
  25.  
  26.     ip = &p->in;
  27.     memset( ip, 0, sizeof( in_Header ));
  28.     icmp = &(p->icmp.echo);
  29.  
  30.     icmp->type = 8;
  31.     icmp->code = 0;
  32.     icmp->index = countnum;
  33.     *(longword *)(&icmp->identifier) = set_timeout( 1 );
  34.     if( theid ) *theid = *(longword *)(&icmp->identifier);
  35. /*
  36.     icmp->identifier = ++icmp_id;
  37.     icmp->sequence = icmp_id;
  38. */
  39.     /* finish the icmp checksum portion */
  40.     icmp->checksum = 0;
  41.     icmp->checksum = ~checksum( icmp, sizeof(struct icmp_echo) );
  42.  
  43.     /* encapsulate into a nice ip packet */
  44.     ip->ver = 4;
  45.     ip->hdrlen = 5;
  46.     ip->length = intel16( sizeof( in_Header ) + sizeof( struct icmp_echo));
  47.     ip->tos = tos;
  48.     ip->identification = intel16( icmp_id ++);  /* not using ip id */
  49. //    ip->frag = 0;
  50.     ip->ttl = ttl;
  51.     ip->proto = ICMP_PROTO;
  52.     ip->checksum = 0;
  53.     ip->source = intel( my_ip_addr );
  54.     ip->destination = intel( host );
  55.     ip->checksum = ~ checksum( ip, sizeof( in_Header ));
  56.  
  57.     return( _eth_send( intel16( ip->length )));
  58. }
  59.  
  60.