1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
11 #include "mozilla/LinkedList.h"
13 #if !defined(XP_WIN) && !defined(XP_OS2)
14 #include <arpa/inet.h>
21 #define IPv6ADDR_IS_LOOPBACK(a) \
22 (((a)->u32[0] == 0) && \
23 ((a)->u32[1] == 0) && \
24 ((a)->u32[2] == 0) && \
25 ((a)->u8[12] == 0) && \
26 ((a)->u8[13] == 0) && \
27 ((a)->u8[14] == 0) && \
28 ((a)->u8[15] == 0x1U))
30 #define IPv6ADDR_IS_V4MAPPED(a) \
31 (((a)->u32[0] == 0) && \
32 ((a)->u32[1] == 0) && \
33 ((a)->u8[8] == 0) && \
34 ((a)->u8[9] == 0) && \
35 ((a)->u8[10] == 0xff) && \
36 ((a)->u8[11] == 0xff))
38 #define IPv6ADDR_V4MAPPED_TO_IPADDR(a) ((a)->u32[3])
40 #define IPv6ADDR_IS_UNSPECIFIED(a) \
41 (((a)->u32[0] == 0) && \
42 ((a)->u32[1] == 0) && \
43 ((a)->u32[2] == 0) && \
49 // Required buffer size for text form of an IP address.
50 // Includes space for null termination. We make our own contants
51 // because we don't want higher-level code depending on things
52 // like INET6_ADDRSTRLEN and having to include the associated
53 // platform-specific headers.
55 // Windows requires longer buffers for some reason.
56 const int kIPv4CStrBufSize
= 22;
57 const int kIPv6CStrBufSize
= 65;
59 const int kIPv4CStrBufSize
= 16;
60 const int kIPv6CStrBufSize
= 46;
63 // This was all created at a time in which we were using NSPR for host
64 // resolution and we were propagating NSPR types like "PRAddrInfo" and
65 // "PRNetAddr" all over Gecko. This made it hard to use another host
66 // resolver -- we were locked into NSPR. The goal here is to get away
67 // from that. We'll translate what we get from NSPR or any other host
68 // resolution library into the types below and use them in Gecko.
77 // This struct is similar to operating system structs like "sockaddr", used for
78 // things like "connect" and "getsockname". When tempted to cast or do dumb
79 // copies of this struct to another struct, bear compiler-computed padding
80 // in mind. The size of this struct, and the layout of the data in it, may
81 // not be what you expect.
84 uint16_t family
; /* address family (0x00ff maskable) */
85 char data
[14]; /* raw address data */
88 uint16_t family
; /* address family (AF_INET) */
89 uint16_t port
; /* port number */
90 uint32_t ip
; /* The actual 32 bits of address */
93 uint16_t family
; /* address family (AF_INET6) */
94 uint16_t port
; /* port number */
95 uint32_t flowinfo
; /* routing information */
96 IPv6Addr ip
; /* the actual 128 bits of address */
97 uint32_t scope_id
; /* set of interfaces for a scope */
99 #if defined(XP_UNIX) || defined(XP_OS2)
100 struct { /* Unix domain socket address */
101 uint16_t family
; /* address family (AF_UNIX) */
103 char path
[108]; /* null-terminated pathname */
105 char path
[104]; /* null-terminated pathname */
111 // This class wraps a NetAddr union to provide C++ linked list
112 // capabilities and other methods. It is created from a PRNetAddr,
113 // which is converted to a mozilla::dns::NetAddr.
114 class NetAddrElement
: public LinkedListElement
<NetAddrElement
> {
116 NetAddrElement(const PRNetAddr
*prNetAddr
);
124 AddrInfo(const char *host
, const PRAddrInfo
*prAddrInfo
, bool disableIPv4
);
128 LinkedList
<NetAddrElement
> mAddresses
;
131 // Copies the contents of a PRNetAddr to a NetAddr.
132 // Does not do a ptr safety check!
133 void PRNetAddrToNetAddr(const PRNetAddr
*prAddr
, NetAddr
*addr
);
135 // Copies the contents of a NetAddr to a PRNetAddr.
136 // Does not do a ptr safety check!
137 void NetAddrToPRNetAddr(const NetAddr
*addr
, PRNetAddr
*prAddr
);
139 bool NetAddrToString(const NetAddr
*addr
, char *buf
, uint32_t bufSize
);
141 bool IsLoopBackAddress(const NetAddr
*addr
);
143 bool IsIPAddrAny(const NetAddr
*addr
);
145 bool IsIPAddrV4Mapped(const NetAddr
*addr
);
148 } // namespace mozilla