EMANE  1.2.1
netadaptermessage.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2017 - Adjacent Link LLC, Bridgewater, New Jersey
3  * Copyright (c) 2008-2009 - DRS CenGen, LLC, Columbia, Maryland
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of DRS CenGen, LLC nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef EMANENETADAPTERMESSAGE_HEADER_
35 #define EMANENETADAPTERMESSAGE_HEADER_
36 
37 #include <cstdint>
38 
39 namespace EMANE
40 {
41  const std::uint16_t NETADAPTER_DATA_MSG = 1;
42  const std::uint16_t NETADAPTER_CTRL_MSG = 2;
43 
50  {
51  std::uint16_t u16Id_;
52  std::uint32_t u32Length_;
53  std::uint8_t data_[0];
54  } __attribute__((packed));
55 
63  inline
65  {
66  pMsg->u16Id_ = ntohs(pMsg->u16Id_);
67  pMsg->u32Length_ = ntohl(pMsg->u32Length_);
68  return pMsg;
69  }
70 
78  inline
80  {
81  pMsg->u16Id_ = htons(pMsg->u16Id_);
82  pMsg->u32Length_ = htonl(pMsg->u32Length_);
83  return pMsg;
84  }
85 
92  {
93  std::uint16_t u16Src_;
94  std::uint16_t u16Dst_;
95  std::uint32_t u32DataLen_;
96  std::uint32_t u32CtrlLen_;
97  std::uint8_t u8Priority_;
98  std::uint8_t data_[0];
99  } __attribute__((packed));
100 
107  {
108  std::uint32_t u32CtrlLen_;
109  std::uint8_t data_[0];
110  } __attribute__((packed));
111 
112 
113  inline
115  {
116  ctrl->u32CtrlLen_ = ntohl(ctrl->u32CtrlLen_);
117  return ctrl;
118  }
119 
120  inline
122  {
123  ctrl->u32CtrlLen_ = htonl(ctrl->u32CtrlLen_);
124  return ctrl;
125  }
126 
132  inline
134  {
135  pkt->u16Src_ = ntohs(pkt->u16Src_);
136  pkt->u16Dst_ = ntohs(pkt->u16Dst_);
137  pkt->u32DataLen_ = ntohl(pkt->u32DataLen_);
138  pkt->u32CtrlLen_ = ntohl(pkt->u32CtrlLen_);
139 
140  return pkt;
141  }
142 
148  inline
150  {
151  pkt->u16Src_ = htons(pkt->u16Src_);
152  pkt->u16Dst_ = htons(pkt->u16Dst_);
153  pkt->u32DataLen_ = htonl(pkt->u32DataLen_);
154  pkt->u32CtrlLen_ = htonl(pkt->u32CtrlLen_);
155 
156  return pkt;
157  }
158 
159 
165  const std::uint16_t NETADAPTER_BROADCAST_ADDRESS = 0xFFFF;
166 }
167 
168 #endif //EMANENETADAPTERMESSAGE_HEADER_
NetAdapterHeader * NetAdapterHeaderToHost(NetAdapterHeader *pMsg)
data shared between network adapter and nem.
NetAdapterControlMessage * NetAdapterControlMessageToHost(NetAdapterControlMessage *ctrl)
information shared between network adapter and nem.
NetAdapterDataMessage * NetAdapterDataMessageToNet(NetAdapterDataMessage *pkt)
converts netadapter data message from host to network byte order.
EMANE::NetworkAdapterException __attribute__
NetAdapter message header.
NetAdapterControlMessage * NetAdapterControlMessageToNet(NetAdapterControlMessage *ctrl)
const std::uint16_t NETADAPTER_DATA_MSG
const std::uint16_t NETADAPTER_CTRL_MSG
NetAdapterHeader * NetAdapterHeaderToNet(NetAdapterHeader *pMsg)
NetAdapterDataMessage * NetAdapterDataMessageToHost(NetAdapterDataMessage *pkt)
converts netadapter data message from network to host byte order.
const std::uint16_t NETADAPTER_BROADCAST_ADDRESS
definition of the broadcast address used between network adapter and nem.
Definition: agent.h:43