-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathhifr.h
142 lines (121 loc) · 5.27 KB
/
hifr.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* HIFR.H (c) Copyright Roger Bowler, 2013 */
/* (c) Copyright Ian Shorter, 2013 */
/* Hercules IPV6 struct hifr/ifreq/in6_ifreq support */
/* */
/* Released under "The Q Public License Version 1" */
/* (http://www.hercules-390.org/herclic.html) as modifications to */
/* Hercules. */
#ifndef __HIFR_H_
#define __HIFR_H_
//---------------------------------------------------------------------
// The 'ifreq' interface request structure
//---------------------------------------------------------------------
#if !defined(OPTION_W32_CTCI) && !defined(HAVE_LINUX_IF_TUN_H) && !defined(HAVE_NET_IF_H)
struct ifreq
{
union
{
char ifrn_name[IFNAMSIZ]; // (interface name)
}
ifr_ifrn;
union
{
struct sockaddr ifru_addr; // (IP address)
struct sockaddr ifru_netmask; // (network mask)
struct sockaddr ifru_hwaddr; // (MAC address)
short int ifru_flags; // (flags)
int ifru_mtu; // (maximum transmission unit)
}
ifr_ifru;
};
#define ifr_name ifr_ifrn.ifrn_name
#define ifr_hwaddr ifr_ifru.ifru_hwaddr
#define ifr_addr ifr_ifru.ifru_addr
#define ifr_netmask ifr_ifru.ifru_netmask
#define ifr_flags ifr_ifru.ifru_flags
#define ifr_mtu ifr_ifru.ifru_mtu
#endif // !defined(OPTION_W32_CTCI) && !defined(HAVE_LINUX_IF_TUN_H) && !defined(HAVE_NET_IF_H)
//---------------------------------------------------------------------
// The 'in6_ifreq' IPv6 interface request structure
//---------------------------------------------------------------------
#if defined(ENABLE_IPV6)
#if defined(HAVE_IN6_IFREQ_IFR6_ADDR)
#if defined(HAVE_LINUX_IPV6_H)
#include <linux/ipv6.h>
#elif defined(HAVE_NETINET6_IN6_VAR_H)
#include <netinet6/in6_var.h>
#else
#error HAVE_IN6_IFREQ_IFR6_ADDR is defined but which header to include is undefined!
#endif
#else /*!defined(HAVE_IN6_IFREQ_IFR6_ADDR)*/
struct in6_ifreq {
struct in6_addr ifr6_addr;
U32 ifr6_prefixlen;
int ifr6_ifindex;
};
#endif /*defined(HAVE_IN6_IFREQ_IFR6_ADDR)*/
#endif /* defined(ENABLE_IPV6) */
//---------------------------------------------------------------------
// The INTERNAL Hercules 'hifr' structure
//---------------------------------------------------------------------
/*
The Hercules ifr (hifr) structure. Why? Because an ifreq stucture is
not large enough to hold inet6 addresses, an in6_ifreq structure is
needed for them. The hifr structure contains both an ifreq stucture
and an in6_ifreq structure.
The ifreq structure is the parameter to most of the ioctl requests
issued by hercifc, with ifrn_name specifying the device to which the
ioctl request applies, and the ifr_ifru union containing the
appropriate value for the ioctl.
When an ioctl request is made to set an inet6 address, an ifreq
structure is not used; instead an in6_ifreq structure is the
parameter. The field ifr6_ifindex specifies the device to which the
ioctl request applies, and the ifr6_addr and ifr6_prefixlen fields
contain the appropriate values for the ioctl. The ifr6_ifindex value
is obtained using the ifrn_name value.
Although the ifrn_name is not used when an in6_ifreq structure is the
parameter to the ioctl request, it is needed for hercifc to use in
error messages, etc.
To distinguish when the in6_ifreq structure is the parameter to the
ioctl request the field hifr_afamily must contain the value AF_INET6,
otherwise it should contain the value AF_INET or zero.
ioctl requests with an ifreq structure as the parameter are made
using an inet socket, whereas ioctl requests with an in6_ifreq
structure as the parameter are made using an inet6 socket.
*/
struct hifr
{
struct ifreq ifreq;
#if defined(ENABLE_IPV6)
struct in6_ifreq in6_ifreq;
#endif /*defined(ENABLE_IPV6)*/
int hifr_afamily;
};
typedef struct hifr hifr;
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__SOLARIS__)
#define hifr_name ifreq.ifr_name
#else
#define hifr_name ifreq.ifr_ifrn.ifrn_name
#endif
#define hifr_addr ifreq.ifr_ifru.ifru_addr
#define hifr_netmask ifreq.ifr_ifru.ifru_netmask
#define hifr_broadaddr ifreq.ifr_ifru.ifru_broadaddr
#define hifr_hwaddr ifreq.ifr_ifru.ifru_hwaddr
#if defined(__FreeBSD__)
/* short ifru_flags[2]; */
#define hifr_flags ifreq.ifr_ifru.ifru_flags[0]
#else
#define hifr_flags ifreq.ifr_ifru.ifru_flags
#endif
#define hifr_mtu ifreq.ifr_ifru.ifru_mtu
#if defined(ENABLE_IPV6)
#define hifr6_addr in6_ifreq.ifr6_addr
#define hifr6_prefixlen in6_ifreq.ifr6_prefixlen
#define hifr6_ifindex in6_ifreq.ifr6_ifindex
#endif /* defined(ENABLE_IPV6) */
//---------------------------------------------------------------------
// Some handy default values
//---------------------------------------------------------------------
#define DEF_MTU 1500
#define DEF_MTU_STR "1500"
#endif // __HIFR_H_