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