MCPcopy Create free account
hub / github.com/EIPStackGroup/OpENer / EncapsulateIpAddress

Function EncapsulateIpAddress

source/src/enet_encap/endianconv.c:197–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

195
196
197int EncapsulateIpAddress(EipUint16 port,
198 EipUint32 address,
199 EipByte **communication_buffer) {
200 int size = 0;
201 if (kOpENerEndianessLittle == g_opener_platform_endianess) {
202 size += AddIntToMessage(htons(AF_INET), communication_buffer);
203 size += AddIntToMessage(port, communication_buffer);
204 size += AddDintToMessage(address, communication_buffer);
205
206 } else {
207 if (kOpENerEndianessBig == g_opener_platform_endianess) {
208 (*communication_buffer)[0] = (unsigned char) (AF_INET >> 8);
209 (*communication_buffer)[1] = (unsigned char) AF_INET;
210 *communication_buffer += 2;
211 size += 2;
212
213 (*communication_buffer)[0] = (unsigned char) (port >> 8);
214 (*communication_buffer)[1] = (unsigned char) port;
215 *communication_buffer += 2;
216 size += 2;
217
218 (*communication_buffer)[3] = (unsigned char) address;
219 (*communication_buffer)[2] = (unsigned char) (address >> 8);
220 (*communication_buffer)[1] = (unsigned char) (address >> 16);
221 (*communication_buffer)[0] = (unsigned char) (address >> 24);
222 *communication_buffer += 4;
223 size += 4;
224 } else {
225 fprintf(stderr,
226 "No endianess detected! Probably the DetermineEndianess function was not executed!");
227 exit (EXIT_FAILURE);
228 }
229 }
230 return size;
231}
232
233/**
234 * @brief Detects Endianess of the platform and sets global g_nOpENerPlatformEndianess variable accordingly

Callers 3

AssembleLinearMessageFunction · 0.85
TESTFunction · 0.85

Calls 2

AddIntToMessageFunction · 0.85
AddDintToMessageFunction · 0.85

Tested by 1

TESTFunction · 0.68