C++ common classes
General purpose classes for use across projects (Apache license)
icmp.h
Go to the documentation of this file.
00001 /*
00002    Copyright [2010] [Richard Bross]
00003 
00004    Licensed under the Apache License, Version 2.0 (the "License");
00005    you may not use this file except in compliance with the License.
00006    You may obtain a copy of the License at
00007 
00008        http://www.apache.org/licenses/LICENSE-2.0
00009 
00010    Unless required by applicable law or agreed to in writing, software
00011    distributed under the License is distributed on an "AS IS" BASIS,
00012    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013    See the License for the specific language governing permissions and
00014    limitations under the License.
00015 */
00016 #ifndef __ICMP_H
00017 #define __ICMP_H
00018 
00019 // Definition of type field values.
00020 #define ICMP_ECHOREPLY          0               // echo reply
00021 #define ICMP_UNREACH            3               // dest unreachable, codes:
00022 #define ICMP_SOURCEQUENCH       4               // packet lost, slow down
00023 #define ICMP_REDIRECT           5               // shorter route, codes:
00024 #define ICMP_ECHO                       8               // echo service
00025 #define ICMP_ROUTERADVERT       9               // router advertisement
00026 #define ICMP_ROUTERSOLICIT      10              // router solicitation
00027 #define ICMP_TIMXCEED           11              // time exceeded, code:
00028 #define ICMP_PARAMPROB          12              // ip header bad
00029 #define ICMP_TSTAMP                     13              // timestamp request
00030 #define ICMP_TSTAMPREPLY        14              // timestamp reply
00031 #define ICMP_IREQ                       15              // information request
00032 #define ICMP_IREQREPLY          16              // information reply
00033 #define ICMP_MASKREQ            17              // address mask request
00034 #define ICMP_MASKREPLY          18              // address mask reply
00035 #define ICMP_MAXTYPE            18
00036 
00037 // Code field values
00038         // ICMP_UNREACH codes
00039 #define         ICMP_UNREACH_NET                        0               // bad net
00040 #define         ICMP_UNREACH_HOST                       1               // bad host
00041 #define         ICMP_UNREACH_PROTOCOL           2               // bad protocol
00042 #define         ICMP_UNREACH_PORT                       3               // bad port
00043 #define         ICMP_UNREACH_NEEDFRAG           4               // IP_DF caused drop
00044 #define         ICMP_UNREACH_SRCFAIL            5               // src route failed
00045 #define         ICMP_UNREACH_NET_UNKNOWN        6               // unknown net
00046 #define         ICMP_UNREACH_HOST_UNKNOWN       7               // unknown host
00047 #define         ICMP_UNREACH_ISOLATED           8               // src host isolated
00048 #define         ICMP_UNREACH_NET_PROHIB         9               // prohibited access
00049 #define         ICMP_UNREACH_HOST_PROHIB        10              // ditto
00050 #define         ICMP_UNREACH_TOSNET                     11              // bad tos for net
00051 #define         ICMP_UNREACH_TOSHOST            12              // bad tos for host
00052         // ICMP_REDIRECT codes
00053 #define         ICMP_REDIRECT_NET                       0               // for network
00054 #define         ICMP_REDIRECT_HOST                      1               // for host
00055 #define         ICMP_REDIRECT_TOSNET            2               // for tos and net
00056 #define         ICMP_REDIRECT_TOSHOST           3               // for tos and host
00057         //ICMP_PARAMPROB codes
00058 #define         ICMP_TIMXCEED_INTRANS           0               // ttl==0 in transit
00059 #define         ICMP_TIMXCEED_REASS                     1               // ttl==0 in reass
00060 #define         ICMP_PARAMPROB_OPTABSENT        1               // req. opt. absent
00061 
00062 #define ICMP_RESPONSE_TOOFEW    -1
00063 #define ICMP_RESPONSE_NONECHO   -2
00064 #define ICMP_RESPONSE_INVID             -3
00065 
00066 #define PING_RESPONSE_SUCCESS                   1000
00067 #define PING_RESPONSE_TIMEOUT                   1001
00068 #define PING_RESPONSE_ERROR                             1002
00069 #define PING_RESPONSE_TRACING                   1003
00070 #define PING_RESPONSE_CANCELLED                 1004
00071 #define PING_RESPONSE_UNREACHABLE               1005
00072 #define PING_RESPONSE_SOURCEROUTEFAIL   1006
00073 
00074 #define ICMP_PACKET_MIN         8                       // Minimum 8 byte icmp packet (just header)
00075 #define IP_PACKET_MIN           64                      // Minimum 64 byte ip packet
00076 #define ICMP_RETURNED_DATA      8                       // ICMP returns first 8 bytes of data from original packet
00077 
00078 #define PING_COUNT      3
00079 #define DATA_PORTION_SIZE   32
00080 
00081 //
00082 //  The IP header
00083 //
00084 typedef struct iphdr {
00085 #if defined(UNIX)
00086 /* Unix compilers pack bit fields from high order to low order bits, so this
00087    ordering puts the version in the high four bits of the byte. */
00088         unsigned char   version:4;      // Version of IP
00089         unsigned char   h_len:4;        // Length of the header
00090 #else
00091 /* Microsoft compiler packs bit fields from low order to high order bits, so
00092    this ordering puts the version in the high four bits. */
00093         unsigned char   h_len:4;        // Length of the header
00094         unsigned char   version:4;      // Version of IP
00095 #endif
00096         unsigned char   tos;            // Type of service
00097         unsigned short  total_len;      // Total length of the packet
00098         unsigned short  ident;          // Unique identifier
00099         unsigned short  frag_and_flags; // Flags
00100         unsigned char   ttl;
00101         unsigned char   proto;          // Protocol (TCP, UDP etc)
00102         unsigned short  checksum;       // IP checksum
00103         unsigned long   sourceIP;
00104         unsigned long   destIP;
00105 } IpHeader;
00106 
00107 //
00108 // ICMP header
00109 //
00110 typedef struct _ihdr
00111         {
00112     unsigned char   i_type;
00113     unsigned char   i_code;                             // Type sub code
00114     unsigned short      i_cksum;
00115         union {
00116                 unsigned char   ih_pptr;                // ICMP_PARAMPROB
00117                 struct in_addr  ih_gwaddr;              // ICMP_REDIRECT
00118                 struct ih_idseq {
00119                                         unsigned short  icd_id;
00120                                         unsigned short  icd_seq;
00121                                                 } ih_idseq;
00122 
00123                 int                             ih_void;
00124 
00125                         // ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191)
00126                 struct ih_pmtu {
00127                                         short                   ipm_void;
00128                                         short                   ipm_nextmtu;
00129                                                 } ih_pmtu;
00130                         } icmp_hun;                                             
00131 
00132         union   {
00133                 struct id_ts {
00134                                         unsigned long   its_otime;
00135                                         unsigned long   its_rtime;
00136                                         unsigned long   its_ttime;
00137                                         } id_ts;
00138                 struct id_ip    {
00139                                         struct                  iphdr idi_ip;
00140                                                 // options and then 64 bits of data
00141                                                 } id_ip;
00142                 unsigned long   id_mask;
00143                 char                    id_data[1];
00144                         } icmp_dun;
00145         }       IcmpHeader;
00146 
00147 
00148 typedef struct _i_LSRR  {               // Loose routing format
00149         unsigned char   nopt;
00150         unsigned char   code;
00151         unsigned char   len;
00152         unsigned char   ptr;
00153         unsigned long   ip_addr[9];
00154 } IPLooseRoute;
00155 
00156 #endif
00157 
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines