ip.h@2:98b11b7dd7b2, 2011-02-13 (annotated)
- Committer:
- jp
- Date:
- Sun Feb 13 02:12:32 2011 +0000
- Revision:
- 2:98b11b7dd7b2
- Parent:
- 0:cf255d2aa92f
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jp | 2:98b11b7dd7b2 | 1 | /* |
jp | 2:98b11b7dd7b2 | 2 | * Copyright or © or Copr. 2010, Thomas SOETE |
jp | 2:98b11b7dd7b2 | 3 | * |
jp | 2:98b11b7dd7b2 | 4 | * Author e-mail: thomas@soete.org |
jp | 2:98b11b7dd7b2 | 5 | * Library website : http://mbed.org/users/Alkorin/libraries/SimpleLib/ |
jp | 2:98b11b7dd7b2 | 6 | * |
jp | 2:98b11b7dd7b2 | 7 | * This software is governed by the CeCILL license under French law and |
jp | 2:98b11b7dd7b2 | 8 | * abiding by the rules of distribution of free software. You can use, |
jp | 2:98b11b7dd7b2 | 9 | * modify and/ or redistribute the software under the terms of the CeCILL |
jp | 2:98b11b7dd7b2 | 10 | * license as circulated by CEA, CNRS and INRIA at the following URL |
jp | 2:98b11b7dd7b2 | 11 | * "http://www.cecill.info". |
jp | 2:98b11b7dd7b2 | 12 | * |
jp | 2:98b11b7dd7b2 | 13 | * As a counterpart to the access to the source code and rights to copy, |
jp | 2:98b11b7dd7b2 | 14 | * modify and redistribute granted by the license, users are provided only |
jp | 2:98b11b7dd7b2 | 15 | * with a limited warranty and the software's author, the holder of the |
jp | 2:98b11b7dd7b2 | 16 | * economic rights, and the successive licensors have only limited |
jp | 2:98b11b7dd7b2 | 17 | * liability. |
jp | 2:98b11b7dd7b2 | 18 | * |
jp | 2:98b11b7dd7b2 | 19 | * In this respect, the user's attention is drawn to the risks associated |
jp | 2:98b11b7dd7b2 | 20 | * with loading, using, modifying and/or developing or reproducing the |
jp | 2:98b11b7dd7b2 | 21 | * software by the user in light of its specific status of free software, |
jp | 2:98b11b7dd7b2 | 22 | * that may mean that it is complicated to manipulate, and that also |
jp | 2:98b11b7dd7b2 | 23 | * therefore means that it is reserved for developers and experienced |
jp | 2:98b11b7dd7b2 | 24 | * professionals having in-depth computer knowledge. Users are therefore |
jp | 2:98b11b7dd7b2 | 25 | * encouraged to load and test the software's suitability as regards their |
jp | 2:98b11b7dd7b2 | 26 | * requirements in conditions enabling the security of their systems and/or |
jp | 2:98b11b7dd7b2 | 27 | * data to be ensured and, more generally, to use and operate it in the |
jp | 2:98b11b7dd7b2 | 28 | * same conditions as regards security. |
jp | 2:98b11b7dd7b2 | 29 | * |
jp | 2:98b11b7dd7b2 | 30 | * The fact that you are presently reading this means that you have had |
jp | 2:98b11b7dd7b2 | 31 | * knowledge of the CeCILL license and that you accept its terms. |
jp | 2:98b11b7dd7b2 | 32 | */ |
jp | 2:98b11b7dd7b2 | 33 | |
jp | 2:98b11b7dd7b2 | 34 | #ifndef __SIMPLELIB_IP_H__ |
jp | 2:98b11b7dd7b2 | 35 | #define __SIMPLELIB_IP_H__ |
jp | 2:98b11b7dd7b2 | 36 | |
jp | 2:98b11b7dd7b2 | 37 | #include "ip.h" |
jp | 2:98b11b7dd7b2 | 38 | |
jp | 2:98b11b7dd7b2 | 39 | typedef __packed struct { |
jp | 2:98b11b7dd7b2 | 40 | unsigned char version:4; |
jp | 2:98b11b7dd7b2 | 41 | unsigned char length:4; |
jp | 2:98b11b7dd7b2 | 42 | unsigned char services; |
jp | 2:98b11b7dd7b2 | 43 | uint16_t total_length; |
jp | 2:98b11b7dd7b2 | 44 | uint16_t identification; |
jp | 2:98b11b7dd7b2 | 45 | unsigned int flags:3; |
jp | 2:98b11b7dd7b2 | 46 | unsigned fragment_offset:13; |
jp | 2:98b11b7dd7b2 | 47 | unsigned char ttl; |
jp | 2:98b11b7dd7b2 | 48 | unsigned char protocol; |
jp | 2:98b11b7dd7b2 | 49 | uint16_t header_checksum; |
jp | 2:98b11b7dd7b2 | 50 | unsigned char source[4]; |
jp | 2:98b11b7dd7b2 | 51 | unsigned char destination[4]; |
jp | 2:98b11b7dd7b2 | 52 | } s_ip; |
jp | 2:98b11b7dd7b2 | 53 | |
jp | 2:98b11b7dd7b2 | 54 | typedef __packed struct { |
jp | 2:98b11b7dd7b2 | 55 | ethernet_packet eth; |
jp | 2:98b11b7dd7b2 | 56 | s_ip ip; |
jp | 2:98b11b7dd7b2 | 57 | } ipv4_packet; |
jp | 2:98b11b7dd7b2 | 58 | #define asIPV4(x) ((ipv4_packet*)(x)) |
jp | 2:98b11b7dd7b2 | 59 | |
jp | 2:98b11b7dd7b2 | 60 | #define PROTO_ICMP 0x01 |
jp | 2:98b11b7dd7b2 | 61 | |
jp | 2:98b11b7dd7b2 | 62 | typedef __packed struct { |
jp | 2:98b11b7dd7b2 | 63 | ethernet_packet eth; |
jp | 2:98b11b7dd7b2 | 64 | s_ip ip; |
jp | 2:98b11b7dd7b2 | 65 | __packed struct { |
jp | 2:98b11b7dd7b2 | 66 | unsigned char type; |
jp | 2:98b11b7dd7b2 | 67 | unsigned char code; |
jp | 2:98b11b7dd7b2 | 68 | uint16_t checksum; |
jp | 2:98b11b7dd7b2 | 69 | uint16_t identifier; |
jp | 2:98b11b7dd7b2 | 70 | uint16_t sequence_number; |
jp | 2:98b11b7dd7b2 | 71 | unsigned char data[]; |
jp | 2:98b11b7dd7b2 | 72 | } icmp; |
jp | 2:98b11b7dd7b2 | 73 | } icmp_packet; |
jp | 2:98b11b7dd7b2 | 74 | #define asICMP(x) ((icmp_packet*)(x)) |
jp | 2:98b11b7dd7b2 | 75 | |
jp | 2:98b11b7dd7b2 | 76 | #define ICMP_REQUEST 0x08 |
jp | 2:98b11b7dd7b2 | 77 | #define ICMP_REPLY 0x00 |
jp | 2:98b11b7dd7b2 | 78 | |
jp | 0:cf255d2aa92f | 79 | #endif |