OpenNet
Ethernet.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 // Constant
14 
15 #define ETHERNET_VLAN_TAG_ID_nh (0x0081)
16 
17 #ifndef _OPEN_NET_NO_FUNCTION_
18 
19 // Functions
21 
38 OPEN_NET_GLOBAL unsigned char * Ethernet_Data( OPEN_NET_GLOBAL unsigned char * aBase, OPEN_NET_GLOBAL const OpenNet_PacketInfo * aPacketInfo)
39 {
40  unsigned short lType_nh = *((OPEN_NET_GLOBAL unsigned short *)(aBase + aPacketInfo->mOffset_byte + 12));
41 
42  return (aBase + aPacketInfo->mOffset_byte + ((ETHERNET_VLAN_TAG_ID_nh == lType_nh) ? 18 : 14));
43 }
44 
61 unsigned int Ethernet_DataSize(OPEN_NET_GLOBAL unsigned char * aBase, OPEN_NET_GLOBAL const OpenNet_PacketInfo * aPacketInfo)
62 {
63  unsigned short lType_nh = *((OPEN_NET_GLOBAL unsigned short *)(aBase + aPacketInfo->mOffset_byte + 12));
64 
65  return (aPacketInfo->mSize_byte - ((ETHERNET_VLAN_TAG_ID_nh == lType_nh) ? 18 : 14));
66 }
67 
86 OPEN_NET_GLOBAL unsigned short * Ethernet_Destination(OPEN_NET_GLOBAL unsigned char * aBase, OPEN_NET_GLOBAL const OpenNet_PacketInfo * aPacketInfo)
87 {
88  return ((OPEN_NET_GLOBAL unsigned short *)(aBase + aPacketInfo->mOffset_byte + 0));
89 }
90 
105 OPEN_NET_GLOBAL unsigned short * Ethernet_Source(OPEN_NET_GLOBAL unsigned char * aBase, OPEN_NET_GLOBAL const OpenNet_PacketInfo * aPacketInfo)
106 {
107  return ((OPEN_NET_GLOBAL unsigned short *)(aBase + aPacketInfo->mOffset_byte + 6));
108 }
109 
124 unsigned short Ethernet_Type(OPEN_NET_GLOBAL const unsigned char * aBase, OPEN_NET_GLOBAL const OpenNet_PacketInfo * aPacketInfo)
125 {
126  unsigned short lType_nh = *((OPEN_NET_GLOBAL const unsigned short *)(aBase + aPacketInfo->mOffset_byte + 12));
127 
128  return (ETHERNET_VLAN_TAG_ID_nh == lType_nh) ? (*((OPEN_NET_GLOBAL const unsigned short *)(aBase + aPacketInfo->mOffset_byte + 16))) : lType_nh;
129 }
130 
147 int Ethernet_Vlan(OPEN_NET_GLOBAL const unsigned char * aBase, OPEN_NET_GLOBAL const OpenNet_PacketInfo * aPacketInfo)
148 {
149  unsigned short lType_nh = *((OPEN_NET_GLOBAL const unsigned short *)(aBase + aPacketInfo->mOffset_byte + 12));
150 
151  return (ETHERNET_VLAN_TAG_ID_nh == lType_nh);
152 }
153 
170 unsigned short Ethernet_VlanTag(OPEN_NET_GLOBAL const unsigned char * aBase, OPEN_NET_GLOBAL const OpenNet_PacketInfo * aPacketInfo)
171 {
172  unsigned short lType_nh = *((OPEN_NET_GLOBAL const unsigned short *)(aBase + aPacketInfo->mOffset_byte + 12));
173 
174  return (ETHERNET_VLAN_TAG_ID_nh == lType_nh) ? (*((OPEN_NET_GLOBAL const unsigned short *)(aBase + aPacketInfo->mOffset_byte + 14))) : 0;
175 }
176 
177 #endif // ! _OPEN_NET_NO_FUNCTION_
unsigned int Ethernet_DataSize(OPEN_NET_GLOBAL unsigned char *aBase, OPEN_NET_GLOBAL const OpenNet_PacketInfo *aPacketInfo)
Cette fonction retourne la taille de la charge utile du paquet Ethernet.
Definition: Ethernet.h:61
OPEN_NET_GLOBAL unsigned char * Ethernet_Data(OPEN_NET_GLOBAL unsigned char *aBase, OPEN_NET_GLOBAL const OpenNet_PacketInfo *aPacketInfo)
Cette fonction retourne un pointeur vers la charge utile du paquet Ethernet.
Definition: Ethernet.h:38
OPEN_NET_GLOBAL unsigned short * Ethernet_Destination(OPEN_NET_GLOBAL unsigned char *aBase, OPEN_NET_GLOBAL const OpenNet_PacketInfo *aPacketInfo)
Cette fonction retourne un pointeur vers l'adresse de destination.
Definition: Ethernet.h:86
Cette structure est utilisée pour passer les informations au sujet d'un paquet.
Definition: Types.h:55
OPEN_NET_GLOBAL unsigned short * Ethernet_Source(OPEN_NET_GLOBAL unsigned char *aBase, OPEN_NET_GLOBAL const OpenNet_PacketInfo *aPacketInfo)
Cette fonction retourne un pointeur vers l'adresse de source.
Definition: Ethernet.h:105
unsigned short Ethernet_Type(OPEN_NET_GLOBAL const unsigned char *aBase, OPEN_NET_GLOBAL const OpenNet_PacketInfo *aPacketInfo)
Cette fonction retourne le type du paquet Ethernet.
Definition: Ethernet.h:124
unsigned short Ethernet_VlanTag(OPEN_NET_GLOBAL const unsigned char *aBase, OPEN_NET_GLOBAL const OpenNet_PacketInfo *aPacketInfo)
Cette fonction retourne le tag VLAN.
Definition: Ethernet.h:170
int Ethernet_Vlan(OPEN_NET_GLOBAL const unsigned char *aBase, OPEN_NET_GLOBAL const OpenNet_PacketInfo *aPacketInfo)
Cette fonction indique si un tag VLAN est présent.
Definition: Ethernet.h:147