OpenNet
IPv4.h
Aller à la documentation de ce fichier.
1 
2 // Product OpenNet
3 
7 
8 // TEST COVERAGE 2019-05-10 KMS - Martin Dubois, ing.
9 
10 #pragma once
11 
12 // Includes
14 
15 // ===== Includes ===========================================================
16 #include <OpenNetK/ByteOrder.h>
17 
18 // Constants
20 
27 #define IPv4_ETHERNET_TYPE_nh (0x0008)
28 
29 #ifndef _OPEN_NET_NO_FUNCTION_
30 
31 // Functions
33 
46 OPEN_NET_GLOBAL unsigned short * IPv4_Destination(OPEN_NET_GLOBAL unsigned char * aData)
47 {
48  return ((OPEN_NET_GLOBAL unsigned short *)(aData + 16));
49 }
50 
61 unsigned int IPv4_HeaderSize(OPEN_NET_GLOBAL unsigned char * aData)
62 {
63  return ( (aData[0] & 0x0f) * 4 );
64 }
65 
76 unsigned char IPv4_Protocol(OPEN_NET_GLOBAL unsigned char * aData)
77 {
78  return aData[9];
79 }
80 
91 OPEN_NET_GLOBAL unsigned short * IPv4_Source(OPEN_NET_GLOBAL unsigned char * aData)
92 {
93  return ((OPEN_NET_GLOBAL unsigned short *)(aData + 12));
94 }
95 
96 // --------------------------------------------------------------------------
97 
108 OPEN_NET_GLOBAL unsigned char * IPv4_Data(OPEN_NET_GLOBAL unsigned char * aData)
109 {
110  return (aData + IPv4_HeaderSize(aData));
111 }
112 
123 unsigned int IPv4_DataSize(OPEN_NET_GLOBAL unsigned char * aData)
124 {
125  return (ByteOrder_Swap16(*((OPEN_NET_GLOBAL unsigned short *)(aData + 2))) - IPv4_HeaderSize(aData));
126 }
127 
128 #endif // ! _OPEN_NET_NO_FUNCTION_
unsigned char IPv4_Protocol(OPEN_NET_GLOBAL unsigned char *aData)
Cette fonction retourne le protocole.
Definition: IPv4.h:76
OPEN_NET_GLOBAL unsigned short * IPv4_Destination(OPEN_NET_GLOBAL unsigned char *aData)
Cette fonction retourne un pointeur vers l'adresse de destination.
Definition: IPv4.h:46
unsigned short ByteOrder_Swap16(unsigned short aIn)
Renverse l'ordre des octets.
Definition: ByteOrder.h:29
OPEN_NET_GLOBAL unsigned char * IPv4_Data(OPEN_NET_GLOBAL unsigned char *aData)
Cette fonction retourne un pointeur vers la charge utile.
Definition: IPv4.h:108
ByteOrder_Swap16, ByteOrder_Swap32 (RT)
unsigned int IPv4_DataSize(OPEN_NET_GLOBAL unsigned char *aData)
Cette fonction retourne la taille de la charge utile.
Definition: IPv4.h:123
OPEN_NET_GLOBAL unsigned short * IPv4_Source(OPEN_NET_GLOBAL unsigned char *aData)
Cette fonction retourne un pointeur vers l'adresse de provenance.
Definition: IPv4.h:91
unsigned int IPv4_HeaderSize(OPEN_NET_GLOBAL unsigned char *aData)
Cette fonction retourne la taille de l'entête IP.
Definition: IPv4.h:61