OSAPI  0.29
Open System API
common_types_ip.h
1 // *****************************************************************************************
2 //
3 // File description:
4 //
5 // Author: Joao Costa
6 // Purpose: Common declarations for IP (IP type is used by several modules)
7 //
8 // *****************************************************************************************
9 
10 #ifndef OSAPI_COMMON_TYPES_IP_H_
11 #define OSAPI_COMMON_TYPES_IP_H_
12 
13 // *****************************************************************************************
14 //
15 // Section: Import headers
16 //
17 // *****************************************************************************************
18 
19 // System headers
20 #include <stdbool.h>
21 
22 // OSAPI headers
23 #include "general/general_types.h"
24 #include "general/general_protocol.h"
25 
26 // Include own headers
27 #include "common/types/common_types_if.h"
28 
29 // *****************************************************************************************
30 //
31 // Section: Macros/Constant definitions
32 //
33 // *****************************************************************************************
34 
35 #define osapi_is_ip_valid_selector( s ) ( s==osapi_protocol_ip || s==osapi_protocol_ipv4 || s==osapi_protocol_ipv6 ? true : false )
36 #define osapi_is_ip_valid_family( f ) ( f==osapi_protocol_ipv4 || f==osapi_protocol_ipv6 ? true : false )
37 #define osapi_is_ipv4_selection( s, f ) ( ( s==osapi_protocol_ip || s==osapi_protocol_ipv4 ) && f==osapi_protocol_ipv4 ? true : false )
38 #define osapi_is_ipv6_selection( s, f ) ( ( s==osapi_protocol_ip || s==osapi_protocol_ipv6 ) && f==osapi_protocol_ipv6 ? true : false )
39 
40 #define osapi_is_ipv4_family( f ) ( f==osapi_protocol_ipv4 ? true : false )
41 #define osapi_is_ipv6_family( f ) ( f==osapi_protocol_ipv6 ? true : false )
42 
43 // Macros for checking additional IP information
44 #define osapi_is_ip_address_broadcast( a ) ( (a & IFF_BROADCAST) ? true : false )
45 #define osapi_is_ip_address_loopback ( a ) ( (a & IFF_LOOPBACK) ? true : false )
46 #define osapi_is_ip_address_up( a ) ( (a & IFF_UP) ? true : false )
47 #define osapi_is_ip_address_running( a ) ( (a & IFF_RUNNING) ? true : false )
48 #define osapi_is_ip_address_multicast( a ) ( (a & IFF_MULTICAST) ? true : false )
49 #define osapi_is_ip_address_promisc( a ) ( (a & IFF_PROMISC) ? true : false )
50 #define osapi_is_ip_address_ptp( a ) ( (a & IFF_POINTOPOINT) ? true : false )
51 
52 #define OSAPI_IP_TARGET_NONE 0
53 #define OSAPI_IP_TARGET_BROADCAST 1
54 #define OSAPI_IP_TARGET_POINT2POINT 2
55 
56 // Size that it takes to create a string with an IP address
57 #define OSAPI_IPV4_ADDRESS_SIZE 4
58 #define OSAPI_IPV6_ADDRESS_SIZE 16
59 
60 // *****************************************************************************************
61 //
62 // Section: Type definitions
63 //
64 // *****************************************************************************************
65 
67 typedef int t_address_type;
68 
71 {
72  Byte host [ OSAPI_IPV4_ADDRESS_SIZE ];
73  Byte mask [ OSAPI_IPV4_ADDRESS_SIZE ];
74  Byte broadcast [ OSAPI_IPV4_ADDRESS_SIZE ];
75  Byte p2p [ OSAPI_IPV4_ADDRESS_SIZE ];
76 };
77 
80 {
82  Byte raw [ OSAPI_IPV6_ADDRESS_SIZE ];
83 };
84 
87 {
89  Byte ipv6 [ OSAPI_IPV6_ADDRESS_SIZE ];
90 };
91 
94 
97 {
98  char interface_name [ OSAPI_INTERFACE_MAX_NAME_SIZE ];
101  t_address_type type_target;
102  //t_mac_address mac;
103 };
104 
106 typedef struct osapi_common_ip_S t_ip;
107 
108 
109 
110 #endif /* OSAPI_COMMON_TYPES_IP_H_ */
t_protocol
int t_protocol
Definition of a protocol type.
Definition: general_types.h:64
Byte
uint8_t Byte
Definition of a Byte type.
Definition: general_types.h:58
osapi_common_ipv4_address_S::p2p
Byte p2p[OSAPI_IPV4_ADDRESS_SIZE]
Point to Point address type.
Definition: common_types_ip.h:75
osapi_common_ip_S::type_target
t_address_type type_target
BroadCast / PtP target address.
Definition: common_types_ip.h:101
osapi_common_ip_S::protocol
t_protocol protocol
V4/V6 IP protocol.
Definition: common_types_ip.h:99
osapi_common_ipv4_address_U
Structure to support either raw (bunch of bytes) or structured IPv4 addresses.
Definition: common_types_ip.h:79
osapi_common_ip_address_U
Union of IPv4/v6 addresses.
Definition: common_types_ip.h:86
osapi_common_ip_S::interface_name
char interface_name[OSAPI_INTERFACE_MAX_NAME_SIZE]
Interface name.
Definition: common_types_ip.h:98
osapi_common_ipv4_address_U::raw
Byte raw[OSAPI_IPV6_ADDRESS_SIZE]
Array of the same number of bytes as IPV6 address.
Definition: common_types_ip.h:82
osapi_common_ipv4_address_S
Structure for a structured IPv4 address.
Definition: common_types_ip.h:70
osapi_common_ipv4_address_S::mask
Byte mask[OSAPI_IPV4_ADDRESS_SIZE]
Network mask.
Definition: common_types_ip.h:73
osapi_common_ip_address_U::ipv6
Byte ipv6[OSAPI_IPV6_ADDRESS_SIZE]
An array of bytes to support an IPv6 address.
Definition: common_types_ip.h:89
osapi_common_ip_S::address
t_ip_address address
IP address.
Definition: common_types_ip.h:100
osapi_common_ipv4_address_S::broadcast
Byte broadcast[OSAPI_IPV4_ADDRESS_SIZE]
Broadcast address type or.
Definition: common_types_ip.h:74
osapi_common_ip_address_U::ipv4
union osapi_common_ipv4_address_U ipv4
An union of all possible IPv4 addresses.
Definition: common_types_ip.h:88
osapi_common_ipv4_address_S::host
Byte host[OSAPI_IPV4_ADDRESS_SIZE]
IP address.
Definition: common_types_ip.h:72
osapi_common_ipv4_address_U::field
struct osapi_common_ipv4_address_S field
Select individual fields.
Definition: common_types_ip.h:81
osapi_common_ip_S
Structure to support IP information.
Definition: common_types_ip.h:96