reactor-c 1.0
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
net_util.h
Go to the documentation of this file.
1
16
17#ifndef NET_UTIL_H
18#define NET_UTIL_H
19
20#ifdef PLATFORM_ARDUINO
21#error To be implemented. No support for federation on Arduino yet.
22#else
23#include <sys/socket.h>
24#include <regex.h>
25#endif
26
27#include <sys/types.h>
28#include <stdbool.h>
29
30#include "low_level_platform.h"
31#include "tag.h"
32
33#ifdef FEDERATED
34#include "socket_common.h"
35#endif
36
37#define HOST_LITTLE_ENDIAN 1
38#define HOST_BIG_ENDIAN 2
39
45
54void encode_int64(int64_t data, unsigned char* buffer);
55
65void encode_int32(int32_t data, unsigned char* buffer);
66
76void encode_uint32(uint32_t data, unsigned char* buffer);
77
86void encode_uint16(uint16_t data, unsigned char* buffer);
87
101
113
126uint16_t swap_bytes_if_big_endian_uint16(uint16_t src);
127
134int32_t extract_int32(unsigned char* bytes);
135
142int64_t extract_int64(unsigned char* bytes);
143
151uint16_t extract_uint16(unsigned char* bytes);
152
153#ifdef FEDERATED
154
167void extract_header(unsigned char* buffer, uint16_t* port_id, uint16_t* federate_id, size_t* length);
168
181void extract_timed_header(unsigned char* buffer, uint16_t* port_id, uint16_t* federate_id, size_t* length, tag_t* tag);
182
192tag_t extract_tag(unsigned char* buffer);
193
202void encode_tag(unsigned char* buffer, tag_t tag);
203
217
226bool match_regex(const char* str, char* regex);
227
235bool validate_port(char* port);
236
244bool validate_host(const char* host);
245
253bool validate_user(const char* user);
254
267bool extract_match_group(const char* rti_addr, char* dest, regmatch_t group, size_t max_len, size_t min_len,
268 const char* err_msg);
269
284bool extract_match_groups(const char* rti_addr, char** rti_addr_strs, bool** rti_addr_flags, regmatch_t* group_array,
285 int* gids, size_t* max_lens, size_t* min_lens, const char** err_msgs);
286
294void extract_rti_addr_info(const char* rti_addr, rti_addr_info_t* rti_addr_info);
295
296#endif // FEDERATED
297
298#endif /* NET_UTIL_H */
void extract_rti_addr_info(const char *rti_addr, rti_addr_info_t *rti_addr_info)
Extract the host, port and user from rti_addr.
bool validate_host(const char *host)
Check whether host is valid.
bool validate_user(const char *user)
Check whether user is valid.
uint16_t extract_uint16(unsigned char *bytes)
Extract an uint16_t from the specified byte sequence.
uint16_t swap_bytes_if_big_endian_uint16(uint16_t src)
If this host is little endian, then reverse the order of the bytes of the argument.
bool extract_match_groups(const char *rti_addr, char **rti_addr_strs, bool **rti_addr_flags, regmatch_t *group_array, int *gids, size_t *max_lens, size_t *min_lens, const char **err_msgs)
Extract match groups from the rti_addr regex.
bool match_regex(const char *str, char *regex)
Check whether str matches regex.
void encode_tag(unsigned char *buffer, tag_t tag)
Encode tag information into buffer.
void extract_header(unsigned char *buffer, uint16_t *port_id, uint16_t *federate_id, size_t *length)
Extract the core header information that all messages between federates share.
bool validate_port(char *port)
Check whether port is valid.
int64_t extract_int64(unsigned char *bytes)
This will swap the order of the bytes if this machine is big endian.
void extract_timed_header(unsigned char *buffer, uint16_t *port_id, uint16_t *federate_id, size_t *length, tag_t *tag)
Extract the timed header information for timed messages between federates.
bool extract_match_group(const char *rti_addr, char *dest, regmatch_t group, size_t max_len, size_t min_len, const char *err_msg)
Extract one match group from the rti_addr regex .
int32_t extract_int32(unsigned char *bytes)
This will swap the order of the bytes if this machine is big endian.
void encode_uint32(uint32_t data, unsigned char *buffer)
Write the specified data as a sequence of bytes starting at the specified address.
tag_t extract_tag(unsigned char *buffer)
Extract tag information from buffer.
int64_t swap_bytes_if_big_endian_int64(int64_t src)
If this host is little endian, then reverse the order of the bytes of the argument.
int host_is_big_endian(void)
Return true (1) if the host is big endian.
void encode_int64(int64_t data, unsigned char *buffer)
Write the specified data as a sequence of bytes starting at the specified address.
int32_t swap_bytes_if_big_endian_int32(int32_t src)
If this host is little endian, then reverse the order of the bytes of the argument.
void encode_uint16(uint16_t data, unsigned char *buffer)
Write the specified data as a sequence of bytes starting at the specified address.
void encode_int32(int32_t data, unsigned char *buffer)
Write the specified data as a sequence of bytes starting at the specified address.
Platform API support for the C target of Lingua Franca.
Common socket operations and utilities for federated Lingua Franca programs.
A helper struct for passing rti_addr information between lf_parse_rti_addr and extract_rti_addr_info.
Definition net_util.h:209
char rti_port_str[6]
Definition net_util.h:211
char rti_user_str[256]
Definition net_util.h:212
bool has_user
Definition net_util.h:215
bool has_host
Definition net_util.h:213
bool has_port
Definition net_util.h:214
char rti_host_str[256]
Definition net_util.h:210
A tag is a time, microstep pair.
Definition tag.h:119
Time and tag definitions and functions for Lingua Franca.