send_v4.c 523 B

1234567891011121314151617181920212223
  1. #include "ping.h"
  2. void
  3. send_v4(void)
  4. {
  5. int len;
  6. struct icmp *icmp;
  7. icmp = (struct icmp *) sendbuf;
  8. icmp->icmp_type = ICMP_ECHO;
  9. icmp->icmp_code = 0;
  10. icmp->icmp_id = pid;
  11. icmp->icmp_seq = nsent++;
  12. memset(icmp->icmp_data, 0xa5, datalen); /* fill with pattern */
  13. Gettimeofday((struct timeval *) icmp->icmp_data, NULL);
  14. len = 8 + datalen; /* checksum ICMP header and data */
  15. icmp->icmp_cksum = 0;
  16. icmp->icmp_cksum = in_cksum((u_short *) icmp, len);
  17. Sendto(sockfd, sendbuf, len, 0, pr->sasend, pr->salen);
  18. }