10 #include <netinet/in.h>
11 #include <sys/socket.h>
30 const unsigned char *
const buffer_address = (
unsigned char *) *buffer;
37 const CipOctet *buffer = *buffer_address;
44 const CipOctet *buffer = *buffer_address;
58 const unsigned char *
const buffer_address = (
unsigned char *) *buffer;
59 EipUint16 data = buffer_address[0] | buffer_address[1] << 8;
65 const CipOctet *buffer = *buffer_address;
66 EipUint16 data = buffer[0] | buffer[1] << 8;
72 const CipOctet *buffer = *buffer_address;
73 EipUint16 data = buffer[0] | buffer[1] << 8;
84 const unsigned char *p = (
unsigned char *) *buffer;
85 EipUint32 data = p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
91 const CipOctet *buffer = *buffer_address;
92 CipUdint data = buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer[3] <<
105 unsigned char *p = (
unsigned char *) *buffer;
107 p[0] = (
unsigned char) data;
119 unsigned char *p = (
unsigned char *) *buffer;
121 p[0] = (
unsigned char) data;
122 p[1] = (
unsigned char) (data >> 8);
134 unsigned char *p = (
unsigned char *) *buffer;
136 p[0] = (
unsigned char) data;
137 p[1] = (
unsigned char) (data >> 8);
138 p[2] = (
unsigned char) (data >> 16);
139 p[3] = (
unsigned char) (data >> 24);
145 #ifdef OPENER_SUPPORT_64BIT_DATATYPES
152 EipUint64 GetLintFromMessage(
const EipUint8 **
const buffer) {
153 const EipUint8 *buffer_address = *buffer;
154 EipUint64 data = ( ( ( (EipUint64) buffer_address[0] ) << 56 )
155 & 0xFF00000000000000LL )
156 + ( ( ( (EipUint64) buffer_address[1] ) << 48 ) &
157 0x00FF000000000000LL )
158 + ( ( ( (EipUint64) buffer_address[2] ) << 40 ) &
159 0x0000FF0000000000LL )
160 + ( ( ( (EipUint64) buffer_address[3] ) << 32 ) &
161 0x000000FF00000000LL )
162 + ( ( ( (EipUint64) buffer_address[4] ) << 24 ) &
164 + ( ( ( (EipUint64) buffer_address[5] ) << 16 ) &
166 + ( ( ( (EipUint64) buffer_address[6] ) << 8 ) &
168 + ( ( (EipUint64) buffer_address[7] ) & 0x00000000000000FF );
178 int AddLintToMessage(
const EipUint64 data,
181 buffer_address[0] = (
EipUint8) (data >> 56) & 0xFF;
182 buffer_address[1] = (
EipUint8) (data >> 48) & 0xFF;
183 buffer_address[2] = (
EipUint8) (data >> 40) & 0xFF;
184 buffer_address[3] = (
EipUint8) (data >> 32) & 0xFF;
185 buffer_address[4] = (
EipUint8) (data >> 24) & 0xFF;
186 buffer_address[5] = (
EipUint8) (data >> 16) & 0xFF;
187 buffer_address[6] = (
EipUint8) (data >> 8) & 0xFF;
188 buffer_address[7] = (
EipUint8) (data) & 0xFF;
199 EipByte **communication_buffer) {
208 (*communication_buffer)[0] = (
unsigned char) (AF_INET >> 8);
209 (*communication_buffer)[1] = (
unsigned char) AF_INET;
210 *communication_buffer += 2;
213 (*communication_buffer)[0] = (
unsigned char) (port >> 8);
214 (*communication_buffer)[1] = (
unsigned char) port;
215 *communication_buffer += 2;
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;
226 "No endianess detected! Probably the DetermineEndianess function was not executed!");
241 char *p = (
char *) &i;
260 (*message_runner) += amount_of_bytes_moved;
261 return amount_of_bytes_moved;
265 unsigned int amount_of_bytes_written,
267 memset(*message, value, amount_of_bytes_written);
268 return amount_of_bytes_written;
272 unsigned int amount_of_filled_bytes,
276 return amount_of_filled_bytes;
CipUint GetUintFromMessage(const CipOctet **const buffer_address)
int FillNextNMessageOctetsWithValueAndMoveToNextPosition(CipOctet value, unsigned int amount_of_filled_bytes, CipOctet **message)
EipUint32 GetDintFromMessage(const EipUint8 **const buffer)
Reads EIP_UINT32 from *buffer and converts little endian to host.
Responsible for Endianess conversion.
EipUint8 GetSintFromMessage(const EipUint8 **const buffer)
Reads EIP_UINT8 from *buffer and converts little endian to host.
int GetEndianess()
Returns global variable g_nOpENerPlatformEndianess, whereas 0 equals little endian and 1 equals big e...
uint8_t CipOctet
Data types as defined in the CIP Specification Vol 1 Appendix C.
int AddIntToMessage(const EipUint16 data, EipUint8 **const buffer)
converts UINT16 data from host to little endian an writes it to buffer.
int AddDintToMessage(const EipUint32 data, EipUint8 **const buffer)
Converts UINT32 data from host to little endian and writes it to buffer.
int AddSintToMessage(const EipUint8 data, EipUint8 **const buffer)
converts UINT8 data from host to little endian an writes it to buffer.
int MoveMessageNOctets(const int amount_of_bytes_moved, const CipOctet **message_runner)
int FillNextNMessageOctetsWith(CipOctet value, unsigned int amount_of_bytes_written, CipOctet **message)
uint8_t EipByte
EIP Data type definitions.
CipUdint GetUdintFromMessage(const CipOctet **const buffer_address)
CipWord GetWordFromMessage(const CipOctet **const buffer_address)
CipByte GetByteFromMessage(const CipOctet **const buffer_address)
EipUint16 GetIntFromMessage(const EipUint8 **const buffer)
Reads EIP_UINT16 from *buffer and converts little endian to host.
OpenerEndianess g_opener_platform_endianess
int EncapsulateIpAddress(EipUint16 port, EipUint32 address, EipByte **communication_buffer)
Encapsulate the sockaddr information as necessary for the Common Packet Format data items...
void DetermineEndianess()
Detects Endianess of the platform and sets global g_nOpENerPlatformEndianess variable accordingly...
CipUsint GetUsintFromMessage(const CipOctet **const buffer_address)