1 /****************************************************************************
2 **
3 ** Copyright (C) 2017 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtNetwork module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QNETWORKINTERFACE_UIKIT_P_H
41 #define QNETWORKINTERFACE_UIKIT_P_H
42 
43 //
44 //  W A R N I N G
45 //  -------------
46 //
47 // This file is not part of the Qt API. It exists purely as an
48 // implementation detail. This header file may change from version to
49 // version without notice, or even be removed.
50 //
51 // We mean it.
52 //
53 
54 // Platform SDK for iOS, tvOS and watchOS is missing those headers:
55 // net/if_media.h, netinet/in_var.h, netinet6/in6_var.h This header is
56 // a workaround, it provides missing macros and structs.
57 
58 // <net/if_media.h>:
59 
60 /*
61  * Ethernet
62  */
63 #define IFM_ETHER 0x00000020
64 /*
65  * FDDI
66  */
67 #define IFM_FDDI 0x00000060
68 /*
69  * IEEE 802.11 Wireless
70  */
71 #define IFM_IEEE80211 0x00000080
72 /*
73  * Masks
74  */
75 #define IFM_NMASK 0x000000e0 /* Network type */
76 /*
77  * Macros to extract various bits of information from the media word.
78  */
79 #define IFM_TYPE(x) ((x) & IFM_NMASK)
80 
81 // <netinet6/in6_var.h>:
82 
83 struct in6_addrlifetime {
84     time_t ia6t_expire;    /* valid lifetime expiration time */
85     time_t ia6t_preferred;    /* preferred lifetime expiration time */
86     u_int32_t ia6t_vltime;    /* valid lifetime */
87     u_int32_t ia6t_pltime;    /* prefix lifetime */
88 };
89 
90 /*
91  * IPv6 interface statistics, as defined in RFC2465 Ipv6IfStatsEntry (p12).
92  */
93 struct in6_ifstat {
94     u_quad_t ifs6_in_receive;    /* # of total input datagram */
95     u_quad_t ifs6_in_hdrerr;    /* # of datagrams with invalid hdr */
96     u_quad_t ifs6_in_toobig;    /* # of datagrams exceeded MTU */
97     u_quad_t ifs6_in_noroute;    /* # of datagrams with no route */
98     u_quad_t ifs6_in_addrerr;    /* # of datagrams with invalid dst */
99     u_quad_t ifs6_in_protounknown;    /* # of datagrams with unknown proto */
100                     /* NOTE: increment on final dst if */
101     u_quad_t ifs6_in_truncated;    /* # of truncated datagrams */
102     u_quad_t ifs6_in_discard;    /* # of discarded datagrams */
103                     /* NOTE: fragment timeout is not here */
104     u_quad_t ifs6_in_deliver;    /* # of datagrams delivered to ULP */
105                     /* NOTE: increment on final dst if */
106     u_quad_t ifs6_out_forward;    /* # of datagrams forwarded */
107                     /* NOTE: increment on outgoing if */
108     u_quad_t ifs6_out_request;    /* # of outgoing datagrams from ULP */
109                     /* NOTE: does not include forwrads */
110     u_quad_t ifs6_out_discard;    /* # of discarded datagrams */
111     u_quad_t ifs6_out_fragok;    /* # of datagrams fragmented */
112     u_quad_t ifs6_out_fragfail;    /* # of datagrams failed on fragment */
113     u_quad_t ifs6_out_fragcreat;    /* # of fragment datagrams */
114                     /* NOTE: this is # after fragment */
115     u_quad_t ifs6_reass_reqd;    /* # of incoming fragmented packets */
116                     /* NOTE: increment on final dst if */
117     u_quad_t ifs6_reass_ok;        /* # of reassembled packets */
118                     /* NOTE: this is # after reass */
119                     /* NOTE: increment on final dst if */
120     u_quad_t ifs6_atmfrag_rcvd;    /* # of atomic fragments received */
121     u_quad_t ifs6_reass_fail;    /* # of reass failures */
122                     /* NOTE: may not be packet count */
123                     /* NOTE: increment on final dst if */
124     u_quad_t ifs6_in_mcast;        /* # of inbound multicast datagrams */
125     u_quad_t ifs6_out_mcast;    /* # of outbound multicast datagrams */
126 
127     u_quad_t ifs6_cantfoward_icmp6;    /* # of ICMPv6 packets received for unreachable dest */
128     u_quad_t ifs6_addr_expiry_cnt;    /* # of address expiry events (excluding privacy addresses) */
129     u_quad_t ifs6_pfx_expiry_cnt;    /* # of prefix expiry events */
130     u_quad_t ifs6_defrtr_expiry_cnt;    /* # of default router expiry events */
131 };
132 
133 /*
134  * ICMPv6 interface statistics, as defined in RFC2466 Ipv6IfIcmpEntry.
135  * XXX: I'm not sure if this file is the right place for this structure...
136  */
137 struct icmp6_ifstat {
138     /*
139      * Input statistics
140      */
141     /* ipv6IfIcmpInMsgs, total # of input messages */
142     u_quad_t ifs6_in_msg;
143     /* ipv6IfIcmpInErrors, # of input error messages */
144     u_quad_t ifs6_in_error;
145     /* ipv6IfIcmpInDestUnreachs, # of input dest unreach errors */
146     u_quad_t ifs6_in_dstunreach;
147     /* ipv6IfIcmpInAdminProhibs, # of input admin. prohibited errs */
148     u_quad_t ifs6_in_adminprohib;
149     /* ipv6IfIcmpInTimeExcds, # of input time exceeded errors */
150     u_quad_t ifs6_in_timeexceed;
151     /* ipv6IfIcmpInParmProblems, # of input parameter problem errors */
152     u_quad_t ifs6_in_paramprob;
153     /* ipv6IfIcmpInPktTooBigs, # of input packet too big errors */
154     u_quad_t ifs6_in_pkttoobig;
155     /* ipv6IfIcmpInEchos, # of input echo requests */
156     u_quad_t ifs6_in_echo;
157     /* ipv6IfIcmpInEchoReplies, # of input echo replies */
158     u_quad_t ifs6_in_echoreply;
159     /* ipv6IfIcmpInRouterSolicits, # of input router solicitations */
160     u_quad_t ifs6_in_routersolicit;
161     /* ipv6IfIcmpInRouterAdvertisements, # of input router advertisements */
162     u_quad_t ifs6_in_routeradvert;
163     /* ipv6IfIcmpInNeighborSolicits, # of input neighbor solicitations */
164     u_quad_t ifs6_in_neighborsolicit;
165     /* ipv6IfIcmpInNeighborAdvertisements, # of input neighbor advs. */
166     u_quad_t ifs6_in_neighboradvert;
167     /* ipv6IfIcmpInRedirects, # of input redirects */
168     u_quad_t ifs6_in_redirect;
169     /* ipv6IfIcmpInGroupMembQueries, # of input MLD queries */
170     u_quad_t ifs6_in_mldquery;
171     /* ipv6IfIcmpInGroupMembResponses, # of input MLD reports */
172     u_quad_t ifs6_in_mldreport;
173     /* ipv6IfIcmpInGroupMembReductions, # of input MLD done */
174     u_quad_t ifs6_in_mlddone;
175 
176     /*
177      * Output statistics. We should solve unresolved routing problem...
178      */
179     /* ipv6IfIcmpOutMsgs, total # of output messages */
180     u_quad_t ifs6_out_msg;
181     /* ipv6IfIcmpOutErrors, # of output error messages */
182     u_quad_t ifs6_out_error;
183     /* ipv6IfIcmpOutDestUnreachs, # of output dest unreach errors */
184     u_quad_t ifs6_out_dstunreach;
185     /* ipv6IfIcmpOutAdminProhibs, # of output admin. prohibited errs */
186     u_quad_t ifs6_out_adminprohib;
187     /* ipv6IfIcmpOutTimeExcds, # of output time exceeded errors */
188     u_quad_t ifs6_out_timeexceed;
189     /* ipv6IfIcmpOutParmProblems, # of output parameter problem errors */
190     u_quad_t ifs6_out_paramprob;
191     /* ipv6IfIcmpOutPktTooBigs, # of output packet too big errors */
192     u_quad_t ifs6_out_pkttoobig;
193     /* ipv6IfIcmpOutEchos, # of output echo requests */
194     u_quad_t ifs6_out_echo;
195     /* ipv6IfIcmpOutEchoReplies, # of output echo replies */
196     u_quad_t ifs6_out_echoreply;
197     /* ipv6IfIcmpOutRouterSolicits, # of output router solicitations */
198     u_quad_t ifs6_out_routersolicit;
199     /* ipv6IfIcmpOutRouterAdvertisements, # of output router advs. */
200     u_quad_t ifs6_out_routeradvert;
201     /* ipv6IfIcmpOutNeighborSolicits, # of output neighbor solicitations */
202     u_quad_t ifs6_out_neighborsolicit;
203     /* ipv6IfIcmpOutNeighborAdvertisements, # of output neighbor advs. */
204     u_quad_t ifs6_out_neighboradvert;
205     /* ipv6IfIcmpOutRedirects, # of output redirects */
206     u_quad_t ifs6_out_redirect;
207     /* ipv6IfIcmpOutGroupMembQueries, # of output MLD queries */
208     u_quad_t ifs6_out_mldquery;
209     /* ipv6IfIcmpOutGroupMembResponses, # of output MLD reports */
210     u_quad_t ifs6_out_mldreport;
211     /* ipv6IfIcmpOutGroupMembReductions, # of output MLD done */
212     u_quad_t ifs6_out_mlddone;
213 };
214 
215 #define SCOPE6_ID_MAX 16
216 
217 struct in6_ifreq {
218     char    ifr_name[IFNAMSIZ];
219     union {
220         struct    sockaddr_in6 ifru_addr;
221         struct    sockaddr_in6 ifru_dstaddr;
222         int    ifru_flags;
223         int    ifru_flags6;
224         int    ifru_metric;
225         int    ifru_intval;
226         caddr_t    ifru_data;
227         struct in6_addrlifetime ifru_lifetime;
228         struct in6_ifstat ifru_stat;
229         struct icmp6_ifstat ifru_icmp6stat;
230         u_int32_t ifru_scope_id[SCOPE6_ID_MAX];
231     } ifr_ifru;
232 };
233 
234 #define IN6_IFF_TEMPORARY 0x0080 /* temporary (anonymous) address. */
235 #define IN6_IFF_DEPRECATED 0x0010 /* deprecated address */
236 
237 #define SIOCGIFAFLAG_IN6 _IOWR('i', 73, struct in6_ifreq)
238 #define SIOCGIFALIFETIME_IN6 _IOWR('i', 81, struct in6_ifreq)
239 
240 // The definition below is ONLY a temporary workaround to unblock
241 // integrations on CI. MUST be removed ASAP, as soon as SDK is
242 // updated. Currently, we have WatchOS SDK 3.2 and it's missing
243 // net/if_types.h (unlike SDK 4.0, which has it). Alas, we have to
244 // work this around. We only define constants that we use in code.
245 
246 #if !QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_NA, __IPHONE_NA, __TVOS_NA, __WATCHOS_4_0)
247 
248 #define QT_WATCHOS_OUTDATED_SDK_WORKAROUND
249 
250 #define IFT_PPP 0x17 /* RFC 1331 */
251 #define IFT_LOOP 0x18 /* loopback */
252 #define IFT_SLIP 0x1c /* IP over generic TTY */
253 
254 #define IFT_GIF 0x37 /*0xf0*/
255 #define IFT_STF 0x39 /*0xf3*/
256 
257 #define IFT_IEEE1394 0x90 /* IEEE1394 High Performance SerialBus*/
258 
259 #endif // WatchOS SDK below 4.0
260 
261 #endif // QNETWORKINTERFACE_UIKIT_P_H
262 
263