2929#include < iostream>
3030#include < cstring>
3131
32+ #include < ipfixprobe/utils.hpp>
33+
3234#include " wg.hpp"
3335
3436namespace ipxp {
@@ -145,23 +147,23 @@ bool WGPlugin::parse_wg(const char *data, unsigned int payload_len, bool source_
145147 // compare the current dst_peer and see if it matches the original source.
146148 // If not, the flow flush may be needed to create a new flow.
147149 cmp_peer = source_pkt ? ext->src_peer : ext->dst_peer ;
148- memcpy (&cmp_new_peer, (data + 4 ), sizeof ( uint32_t ));
150+ memcpy_le32toh (&cmp_new_peer, reinterpret_cast < const uint32_t *> (data + 4 ));
149151
150152 if (cmp_peer != 0 && cmp_peer != cmp_new_peer) {
151153 flow_flush = true ;
152154 return false ;
153155 }
154156
155- memcpy (source_pkt ? &(ext->src_peer ) : &(ext->dst_peer ), (data + 4 ), sizeof ( uint32_t ));
157+ memcpy_le32toh (source_pkt ? &(ext->src_peer ) : &(ext->dst_peer ), reinterpret_cast < const uint32_t *> (data + 4 ));
156158 break ;
157159
158160 case WG_PACKETTYPE_RESP_TO_INIT:
159161 if (payload_len != WG_PACKETLEN_RESP_TO_INIT) {
160162 return false ;
161163 }
162164
163- memcpy (&(ext->src_peer ), (data + 4 ), sizeof ( uint32_t ));
164- memcpy (&(ext->dst_peer ), (data + 8 ), sizeof ( uint32_t ));
165+ memcpy_le32toh (&(ext->src_peer ), reinterpret_cast < const uint32_t *> (data + 4 ));
166+ memcpy_le32toh (&(ext->dst_peer ), reinterpret_cast < const uint32_t *> (data + 8 ));
165167
166168 // let's swap for the opposite direction
167169 if (!source_pkt) {
@@ -174,15 +176,15 @@ bool WGPlugin::parse_wg(const char *data, unsigned int payload_len, bool source_
174176 return false ;
175177 }
176178
177- memcpy (source_pkt ? &(ext->dst_peer ) : &(ext->src_peer ), (data + 4 ), sizeof ( uint32_t ));
179+ memcpy_le32toh (source_pkt ? &(ext->dst_peer ) : &(ext->src_peer ), reinterpret_cast < const uint32_t *> (data + 4 ));
178180 break ;
179181
180182 case WG_PACKETTYPE_TRANSPORT_DATA:
181183 if (payload_len < WG_PACKETLEN_MIN_TRANSPORT_DATA) {
182184 return false ;
183185 }
184186
185- memcpy (source_pkt ? &(ext->dst_peer ) : &(ext->src_peer ), (data + 4 ), sizeof ( uint32_t ));
187+ memcpy_le32toh (source_pkt ? &(ext->dst_peer ) : &(ext->src_peer ), reinterpret_cast < const uint32_t *> (data + 4 ));
186188 break ;
187189 }
188190
0 commit comments