[21580dd] | 1 | /*
|
---|
| 2 | * Copyright (c) 2009 Lukas Mejdrech
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup icmp
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | /** @file
|
---|
| 34 | * ICMP header definition.
|
---|
| 35 | * Based on the RFC~792.
|
---|
| 36 | */
|
---|
| 37 |
|
---|
| 38 | #ifndef __NET_ICMP_HEADER_H__
|
---|
| 39 | #define __NET_ICMP_HEADER_H__
|
---|
| 40 |
|
---|
| 41 | #include <sys/types.h>
|
---|
| 42 |
|
---|
[849ed54] | 43 | #include <in.h>
|
---|
| 44 | #include <icmp_codes.h>
|
---|
[21580dd] | 45 |
|
---|
[ede63e4] | 46 | /** ICMP header size in bytes.
|
---|
| 47 | */
|
---|
[aadf01e] | 48 | #define ICMP_HEADER_SIZE sizeof(icmp_header_t)
|
---|
[ede63e4] | 49 |
|
---|
[21580dd] | 50 | /** Type definition of the echo specific data.
|
---|
| 51 | * @see icmp_echo
|
---|
| 52 | */
|
---|
| 53 | typedef struct icmp_echo icmp_echo_t;
|
---|
| 54 |
|
---|
| 55 | /** Type definition of the echo specific data pointer.
|
---|
| 56 | * @see icmp_echo
|
---|
| 57 | */
|
---|
| 58 | typedef icmp_echo_t * icmp_echo_ref;
|
---|
| 59 |
|
---|
| 60 | /** Echo specific data.
|
---|
| 61 | */
|
---|
| 62 | struct icmp_echo{
|
---|
| 63 | /** Message idintifier.
|
---|
| 64 | */
|
---|
[aadf01e] | 65 | icmp_param_t identifier;
|
---|
[21580dd] | 66 | /** Message sequence number.
|
---|
| 67 | */
|
---|
[aadf01e] | 68 | icmp_param_t sequence_number;
|
---|
[21580dd] | 69 | } __attribute__ ((packed));
|
---|
| 70 |
|
---|
| 71 | /** Type definition of the internet control message header.
|
---|
| 72 | * @see icmp_header
|
---|
| 73 | */
|
---|
| 74 | typedef struct icmp_header icmp_header_t;
|
---|
| 75 |
|
---|
| 76 | /** Type definition of the internet control message header pointer.
|
---|
| 77 | * @see icmp_header
|
---|
| 78 | */
|
---|
| 79 | typedef icmp_header_t * icmp_header_ref;
|
---|
| 80 |
|
---|
| 81 | /** Internet control message header.
|
---|
| 82 | */
|
---|
| 83 | struct icmp_header{
|
---|
| 84 | /** The type of the message.
|
---|
| 85 | */
|
---|
[aadf01e] | 86 | uint8_t type;
|
---|
[21580dd] | 87 | /** The error code for the datagram reported by the ICMP message.
|
---|
| 88 | * The interpretation is dependent on the message type.
|
---|
| 89 | */
|
---|
[aadf01e] | 90 | uint8_t code;
|
---|
[21580dd] | 91 | /** The checksum is the 16-bit ones's complement of the one's complement sum of the ICMP message starting with the ICMP Type.
|
---|
| 92 | * For computing the checksum, the checksum field should be zero.
|
---|
| 93 | * If the checksum does not match the contents, the datagram is discarded.
|
---|
| 94 | */
|
---|
[aadf01e] | 95 | uint16_t checksum;
|
---|
[21580dd] | 96 | /** Message specific data.
|
---|
| 97 | */
|
---|
| 98 | union{
|
---|
| 99 | /** Echo specific data.
|
---|
| 100 | */
|
---|
[aadf01e] | 101 | icmp_echo_t echo;
|
---|
[21580dd] | 102 | /** Proposed gateway value.
|
---|
| 103 | */
|
---|
[aadf01e] | 104 | in_addr_t gateway;
|
---|
[21580dd] | 105 | /** Fragmentation needed specific data.
|
---|
| 106 | */
|
---|
| 107 | struct{
|
---|
| 108 | /** Reserved field.
|
---|
| 109 | * Must be zero.
|
---|
| 110 | */
|
---|
[aadf01e] | 111 | icmp_param_t reserved;
|
---|
[21580dd] | 112 | /** Proposed MTU.
|
---|
| 113 | */
|
---|
[aadf01e] | 114 | icmp_param_t mtu;
|
---|
[21580dd] | 115 | } frag;
|
---|
| 116 | /** Parameter problem specific data.
|
---|
| 117 | */
|
---|
| 118 | struct{
|
---|
| 119 | /** Problem pointer.
|
---|
| 120 | */
|
---|
[aadf01e] | 121 | icmp_param_t pointer;
|
---|
[21580dd] | 122 | /** Reserved field.
|
---|
| 123 | * Must be zero.
|
---|
| 124 | */
|
---|
[aadf01e] | 125 | icmp_param_t reserved;
|
---|
[21580dd] | 126 | } param;
|
---|
| 127 | } un;
|
---|
| 128 | } __attribute__ ((packed));
|
---|
| 129 |
|
---|
| 130 | #endif
|
---|
| 131 |
|
---|
| 132 | /** @}
|
---|
| 133 | */
|
---|