1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * INET An implementation of the TCP/IP protocol suite for the LINUX
4 * operating system. INET is implemented using the BSD Socket
5 * interface as the means of communication with the user level.
7 * Definitions of the Internet Protocol.
9 * Version: @(#)in.h 1.0.1 04/21/93
11 * Authors: Original taken from the GNU Project <netinet/in.h> file.
12 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
18 #include <linux/errno.h>
19 #include <uapi/linux/in.h>
21 static inline int proto_ports_offset(int proto)
27 case IPPROTO_ESP: /* SPI */
31 case IPPROTO_AH: /* SPI */
38 static inline bool ipv4_is_loopback(__be32 addr)
40 return (addr & htonl(0xff000000)) == htonl(0x7f000000);
43 static inline bool ipv4_is_multicast(__be32 addr)
45 return (addr & htonl(0xf0000000)) == htonl(0xe0000000);
48 static inline bool ipv4_is_local_multicast(__be32 addr)
50 return (addr & htonl(0xffffff00)) == htonl(0xe0000000);
53 static inline bool ipv4_is_lbcast(__be32 addr)
55 /* limited broadcast */
56 return addr == htonl(INADDR_BROADCAST);
59 static inline bool ipv4_is_all_snoopers(__be32 addr)
61 return addr == htonl(INADDR_ALLSNOOPERS_GROUP);
64 static inline bool ipv4_is_zeronet(__be32 addr)
69 /* Special-Use IPv4 Addresses (RFC3330) */
71 static inline bool ipv4_is_private_10(__be32 addr)
73 return (addr & htonl(0xff000000)) == htonl(0x0a000000);
76 static inline bool ipv4_is_private_172(__be32 addr)
78 return (addr & htonl(0xfff00000)) == htonl(0xac100000);
81 static inline bool ipv4_is_private_192(__be32 addr)
83 return (addr & htonl(0xffff0000)) == htonl(0xc0a80000);
86 static inline bool ipv4_is_linklocal_169(__be32 addr)
88 return (addr & htonl(0xffff0000)) == htonl(0xa9fe0000);
91 static inline bool ipv4_is_anycast_6to4(__be32 addr)
93 return (addr & htonl(0xffffff00)) == htonl(0xc0586300);
96 static inline bool ipv4_is_test_192(__be32 addr)
98 return (addr & htonl(0xffffff00)) == htonl(0xc0000200);
101 static inline bool ipv4_is_test_198(__be32 addr)
103 return (addr & htonl(0xfffe0000)) == htonl(0xc6120000);
105 #endif /* _LINUX_IN_H */