OpENer - Open Source EtherNet/IP(TM) I/O Target Stack  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
udp_protocol.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright (c) 2018, Rockwell Automation, Inc.
3  * All rights reserved.
4  *
5  ******************************************************************************/
6 
16 #ifndef SRC_PORTS_UDP_PROTOCOL_H_
17 #define SRC_PORTS_UDP_PROTOCOL_H_
18 
19 #include <stdint.h>
20 #include <stddef.h>
21 #ifdef OPENER_POSIX
22 #include <netinet/in.h>
23 #elif WIN32
24 typedef uint32_t in_addr_t;
25 #endif
26 
27 static size_t kUpdHeaderLength = 8U;
33 typedef struct {
34  uint16_t source_port;
35  uint16_t destination_port;
36  uint16_t packet_length;
37  uint16_t checksum;
38 } UDPHeader;
39 
45 void UDPHeaderSetSourcePort(UDPHeader *const header, const uint16_t source_port);
46 
52 uint16_t UDPHeaderGetSourcePort(const UDPHeader *const header);
53 
59 void UDPHeaderSetDestinationPort(UDPHeader *const header, const uint16_t destination_port);
60 
66 uint16_t UDPHeaderGetDestinationPort(const UDPHeader *const header);
67 
73 void UDPHeaderSetPacketLength(UDPHeader *const header, const uint16_t packet_length);
74 
80 uint16_t UDPHeaderGetPacketLength(const UDPHeader *const header);
81 
87 void UDPHeaderSetChecksum(UDPHeader *const header, const uint16_t checksum);
88 
94 uint16_t UDPHeaderGetChecksum(const UDPHeader *const header);
95 
104 uint16_t UDPHeaderCalculateChecksum(const void *udp_packet, const size_t udp_packet_length, const in_addr_t source_addr, const in_addr_t destination_addr);
105 
114 void UDPHeaderGenerate(const UDPHeader *header, char* message);
115 
116 #endif /* SRC_PORTS_UDP_PROTOCOL_H_ */
uint16_t UDPHeaderGetPacketLength(const UDPHeader *const header)
Gets packet length field.
Definition: udp_protocol.c:36
uint16_t UDPHeaderGetSourcePort(const UDPHeader *const header)
Gets source port field.
Definition: udp_protocol.c:18
uint16_t source_port
Definition: udp_protocol.h:34
void UDPHeaderGenerate(const UDPHeader *header, char *message)
Generate the UDP header in the message according to the header.
Definition: udp_protocol.c:49
Representing the needed information for the UDP header.
Definition: udp_protocol.h:33
uint16_t UDPHeaderGetDestinationPort(const UDPHeader *const header)
Gets destination port field.
Definition: udp_protocol.c:27
void UDPHeaderSetPacketLength(UDPHeader *const header, const uint16_t packet_length)
Sets packet length field.
Definition: udp_protocol.c:31
uint16_t packet_length
Definition: udp_protocol.h:36
uint16_t checksum
Definition: udp_protocol.h:37
void UDPHeaderSetChecksum(UDPHeader *const header, const uint16_t checksum)
Sets checksum field.
Definition: udp_protocol.c:40
void UDPHeaderSetDestinationPort(UDPHeader *const header, const uint16_t destination_port)
Sets destination port field.
Definition: udp_protocol.c:22
uint16_t UDPHeaderGetChecksum(const UDPHeader *const header)
Gets checksum field.
Definition: udp_protocol.c:45
uint16_t UDPHeaderCalculateChecksum(const void *udp_packet, const size_t udp_packet_length, const in_addr_t source_addr, const in_addr_t destination_addr)
Calculates the checksum based on the set UDP packet data and pseudo IP header.
Definition: udp_protocol.c:61
uint16_t destination_port
Definition: udp_protocol.h:35
void UDPHeaderSetSourcePort(UDPHeader *const header, const uint16_t source_port)
Sets source port field.
Definition: udp_protocol.c:13