You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

libping.h 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**
  2. * PING header
  3. *
  4. * Copyright (C) 2001 Jeffrey Fulmer <jdfulmer@armstrong.com>
  5. * This file is part of LIBPING
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. *
  21. */
  22. #ifndef PING_H
  23. #define PING_H
  24. #include "includes.h"
  25. #if defined( __linux__ )
  26. #define ICMP_ECHOREPLY 0
  27. #define ICMP_ECHO 8
  28. #define ICMP_MINLEN 8
  29. struct ip {
  30. #if (BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN)
  31. u_char ip_hl:4, /* header length */
  32. ip_v:4; /* version */
  33. #else
  34. u_char ip_v:4, /* version */
  35. ip_hl:4; /* header length */
  36. #endif
  37. u_char ip_tos; /* type of service */
  38. short ip_len; /* total length */
  39. u_short ip_id; /* identification */
  40. short ip_off; /* fragment offset field */
  41. #define IP_DF 0x4000 /* dont fragment flag */
  42. #define IP_MF 0x2000 /* more fragments flag */
  43. u_char ip_ttl; /* time to live */
  44. u_char ip_p; /* protocol */
  45. u_short ip_sum; /* checksum */
  46. struct in_addr ip_src, ip_dst; /* source and dest address */
  47. };
  48. #define n_short u_short /* normally defined in in_systm.h */
  49. #define n_long u_int /* redefine for 64-bit machines */
  50. #define n_time u_int /* redefine for 64-bit machines */
  51. struct icmp {
  52. u_char icmp_type; /* type of message, see below */
  53. u_char icmp_code; /* type sub code */
  54. u_short icmp_cksum; /* ones complement cksum of struct */
  55. union {
  56. u_char ih_pptr; /* ICMP_PARAMPROB */
  57. struct in_addr ih_gwaddr; /* ICMP_REDIRECT */
  58. struct ih_idseq {
  59. n_short icd_id;
  60. n_short icd_seq;
  61. } ih_idseq;
  62. int ih_void;
  63. } icmp_hun;
  64. #define icmp_pptr icmp_hun.ih_pptr
  65. #define icmp_gwaddr icmp_hun.ih_gwaddr
  66. #define icmp_id icmp_hun.ih_idseq.icd_id
  67. #define icmp_seq icmp_hun.ih_idseq.icd_seq
  68. #define icmp_void icmp_hun.ih_void
  69. union {
  70. struct id_ts {
  71. n_time its_otime;
  72. n_time its_rtime;
  73. n_time its_ttime;
  74. } id_ts;
  75. struct id_ip {
  76. struct ip idi_ip;
  77. /* options and then 64 bits of data */
  78. } id_ip;
  79. n_long id_mask;
  80. char id_data[1];
  81. } icmp_dun;
  82. #define icmp_otime icmp_dun.id_ts.its_otime
  83. #define icmp_rtime icmp_dun.id_ts.its_rtime
  84. #define icmp_ttime icmp_dun.id_ts.its_ttime
  85. #define icmp_ip icmp_dun.id_ip.idi_ip
  86. #define icmp_mask icmp_dun.id_mask
  87. #define icmp_data icmp_dun.id_data
  88. };
  89. #else
  90. #include <netinet/ip.h>
  91. #include <netinet/ip_icmp.h>
  92. #endif /* defined(__linux__) */
  93. #define IDENT_DEFAULT 0
  94. #define TIMO_DEFAULT 2
  95. struct ping_priv {
  96. int ident;
  97. int timo;
  98. int rrt;
  99. int sock;
  100. };
  101. struct ping_priv ping_priv_default(void);
  102. int pinghost(const char *hostname);
  103. int pingthost(const char *hostname, int t);
  104. int tpinghost(const char *hostname);
  105. int tpingthost(const char *hostname, int t);
  106. #endif /*PING_H */