f66f2056bff514136b5fc187b8fefb5cd750cf73
[cascardo/ovs.git] / include / sparse / netinet / in.h
1 /*
2  * Copyright (c) 2011, 2013, 2014, 2015 Nicira, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __CHECKER__
18 #error "Use this header only with sparse.  It is not a correct implementation."
19 #endif
20
21 #ifndef __NETINET_IN_SPARSE
22 #define __NETINET_IN_SPARSE 1
23
24 #include "openvswitch/types.h"
25 #include <inttypes.h>
26 #include <sys/socket.h>
27
28 typedef ovs_be16 in_port_t;
29 typedef ovs_be32 in_addr_t;
30
31 struct in_addr {
32     in_addr_t s_addr;
33 };
34
35 struct sockaddr_in {
36     sa_family_t sin_family;
37     in_port_t sin_port;
38     struct in_addr sin_addr;
39 };
40
41 struct in6_addr {
42     union {
43         uint8_t u_s6_addr[16];
44     } u;
45 };
46
47 #define s6_addr u.u_s6_addr
48
49 extern const struct in6_addr in6addr_any;
50
51 /* Ditto, for IPv6.  */
52 struct sockaddr_in6 {
53     sa_family_t sin6_family;
54     in_port_t sin6_port;        /* Transport layer port # */
55     uint32_t sin6_flowinfo;     /* IPv6 flow information */
56     struct in6_addr sin6_addr;  /* IPv6 address */
57     uint32_t sin6_scope_id;     /* IPv6 scope-id */
58 };
59
60 #define IPPROTO_IP 0
61 #define IPPROTO_IPV6  41
62 #define IPPROTO_HOPOPTS 0
63 #define IPPROTO_ICMP 1
64 #define IPPROTO_IGMP 2
65 #define IPPROTO_TCP 6
66 #define IPPROTO_UDP 17
67 #define IPPROTO_ROUTING 43
68 #define IPPROTO_FRAGMENT 44
69 #define IPPROTO_GRE 47
70 #define IPPROTO_ESP 50
71 #define IPPROTO_AH 51
72 #define IPPROTO_ICMPV6 58
73 #define IPPROTO_NONE 59
74 #define IPPROTO_DSTOPTS 60
75 #define IPPROTO_SCTP 132
76
77 /* All the IP options documented in Linux ip(7). */
78 #define IP_ADD_MEMBERSHIP 0
79 #define IP_DROP_MEMBERSHIP 1
80 #define IP_HDRINCL 2
81 #define IP_MTU 3
82 #define IP_MTU_DISCOVER 4
83 #define IP_MULTICAST_IF 5
84 #define IP_MULTICAST_LOOP 6
85 #define IP_MULTICAST_TTL 7
86 #define IP_NODEFRAG 8
87 #define IP_OPTIONS 9
88 #define IP_PKTINFO 10
89 #define IP_RECVERR 11
90 #define IP_RECVOPTS 12
91 #define IP_RECVTOS 13
92 #define IP_RECVTTL 14
93 #define IP_RETOPTS 15
94 #define IP_ROUTER_ALERT 16
95 #define IP_TOS 17
96 #define IP_TTL 18
97
98 #define INADDR_ANY              0x00000000
99 #define INADDR_BROADCAST        0xffffffff
100 #define INADDR_LOOPBACK         0x7f000001
101 #define INADDR_NONE             0xffffffff
102
103 #define IN6_IS_ADDR_V4MAPPED(X)                 \
104     ((X)->s6_addr[0] == 0 &&                    \
105      (X)->s6_addr[1] == 0 &&                    \
106      (X)->s6_addr[2] == 0 &&                    \
107      (X)->s6_addr[3] == 0 &&                    \
108      (X)->s6_addr[4] == 0 &&                    \
109      (X)->s6_addr[5] == 0 &&                    \
110      (X)->s6_addr[6] == 0 &&                    \
111      (X)->s6_addr[7] == 0 &&                    \
112      (X)->s6_addr[8] == 0 &&                    \
113      (X)->s6_addr[9] == 0 &&                    \
114      (X)->s6_addr[10] == 0xff &&                \
115      (X)->s6_addr[11] == 0xff)
116
117 #define INET6_ADDRSTRLEN 46
118
119 #define IPV6_TCLASS   67
120
121 static inline ovs_be32 htonl(uint32_t x)
122 {
123     return (OVS_FORCE ovs_be32) x;
124 }
125
126 static inline ovs_be16 htons(uint16_t x)
127 {
128     return (OVS_FORCE ovs_be16) x;
129 }
130
131 static inline uint32_t ntohl(ovs_be32 x)
132 {
133     return (OVS_FORCE uint32_t) x;
134 }
135
136 static inline uint16_t ntohs(ovs_be16 x)
137 {
138     return (OVS_FORCE uint16_t) x;
139 }
140
141 in_addr_t inet_addr(const char *);
142 int inet_aton (const char *, struct in_addr *);
143 const char *inet_ntop(int, const void *, char *, socklen_t);
144 int inet_pton(int, const char *, void *);
145
146 #endif /* <netinet/in.h> sparse */