F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
IpCfg.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title IpCfg.hpp
3 // \author mstarch
4 // \brief hpp file for SocketIpDriver component implementation class
5 //
6 // \copyright
7 // Copyright 2009-2015, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12 #include <Fw/Time/TimeInterval.hpp>
13 #ifndef REF_IPCFG_HPP
14 #define REF_IPCFG_HPP
15 
16 enum IpCfg {
17  SOCKET_SEND_TIMEOUT_SECONDS = 1, // Seconds component of timeout to an individual send
18  SOCKET_SEND_TIMEOUT_MICROSECONDS = 0, // Milliseconds component of timeout to an individual send
19  SOCKET_IP_SEND_FLAGS = 0, // send, sendto FLAGS argument
20  SOCKET_IP_RECV_FLAGS = 0, // recv FLAGS argument
21  SOCKET_MAX_ITERATIONS = 0xFFFF, // Maximum send/recv attempts before an error is returned
22  SOCKET_MAX_HOSTNAME_SIZE = 256 // Maximum stored hostname
23 };
25 
26 #ifdef TGT_OS_TYPE_VXWORKS
27 #include <socket.h>
28 #elif defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN
29 #include <sys/socket.h>
30 #else
31 #error OS not supported for IP Socket Communications
32 #endif
33 
34 // Value type enumeration
36  SOCK_OPT_INT, // Integer value
37  SOCK_OPT_SIZE_T, // size_t value
38 };
39 
40 // Socket option structure with flexible value types
41 struct IpSocketOptions {
42  int option; // Socket option name
43  int level; // Socket level
44  SocketOptionValueType type; // Type of value stored
45 
46  union {
47  int intVal; // Integer value
48  size_t sizeVal; // Size_t value
49  } value;
50 };
51 
52 // Helper functions to create different types of socket options
53 inline IpSocketOptions makeIntOption(int opt, int level, int val) {
54  IpSocketOptions option;
55  option.option = opt;
56  option.level = level;
57  option.type = SOCK_OPT_INT;
58  option.value.intVal = val;
59  return option;
60 }
61 
62 inline IpSocketOptions makeSizeOption(int opt, int level, size_t val) {
63  IpSocketOptions option;
64  option.option = opt;
65  option.level = level;
66  option.type = SOCK_OPT_SIZE_T;
67  option.value.sizeVal = val;
68  return option;
69 }
70 
71 // Array of socket options to explicitly set using setsockopt
72 // Use the dedicated helper functions to create options of the correct type
73 // makeIntOption -> for int values
74 // makeSizeOption -> for size_t values
75 // NOTE: Socket options should be chosen based on project needs and with
76 // consideration of their implications with regard to security.
77 // For example, if enabling S_REUSEADDR and there is a hostile actor on the same
78 // machine, they could potentially bind to the same port and intercept messages.
79 // Projects should evaluate their threat model and choose options accordingly.
80 static const IpSocketOptions IP_SOCKET_OPTIONS[] = {
81  makeIntOption(SO_REUSEADDR, SOL_SOCKET, 0), // Example
82  // Add other socket options as needed, and expand above helper functions
83  // if other types are needed
84 };
85 
86 #endif // REF_IPCFG_HPP
size_t sizeVal
Definition: IpCfg.hpp:48
union IpSocketOptions::@5 value
SocketOptionValueType
Definition: IpCfg.hpp:35
IpCfg
Definition: IpCfg.hpp:16
IpSocketOptions makeIntOption(int opt, int level, int val)
Definition: IpCfg.hpp:53
static const IpSocketOptions IP_SOCKET_OPTIONS[]
Definition: IpCfg.hpp:80
static const Fw::TimeInterval SOCKET_RETRY_INTERVAL
Definition: IpCfg.hpp:24
SocketOptionValueType type
Definition: IpCfg.hpp:44
IpSocketOptions makeSizeOption(int opt, int level, size_t val)
Definition: IpCfg.hpp:62