| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * INET		An implementation of the TCP/IP protocol suite for the LINUX | 
 | 3 |  *		operating system.  INET is implemented using the  BSD Socket | 
 | 4 |  *		interface as the means of communication with the user level. | 
 | 5 |  * | 
 | 6 |  *		Definitions of the Internet Protocol. | 
 | 7 |  * | 
 | 8 |  * Version:	@(#)in.h	1.0.1	04/21/93 | 
 | 9 |  * | 
 | 10 |  * Authors:	Original taken from the GNU Project <netinet/in.h> file. | 
 | 11 |  *		Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> | 
 | 12 |  * | 
 | 13 |  *		This program is free software; you can redistribute it and/or | 
 | 14 |  *		modify it under the terms of the GNU General Public License | 
 | 15 |  *		as published by the Free Software Foundation; either version | 
 | 16 |  *		2 of the License, or (at your option) any later version. | 
 | 17 |  */ | 
 | 18 | #ifndef _LINUX_IN_H | 
 | 19 | #define _LINUX_IN_H | 
 | 20 |  | 
| Joe Perches | 2658fa8 | 2007-12-16 13:42:49 -0800 | [diff] [blame] | 21 |  | 
| Changli Gao | e760702 | 2010-08-17 19:03:44 +0000 | [diff] [blame] | 22 | #include <linux/errno.h> | 
| David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 23 | #include <uapi/linux/in.h> | 
| Changli Gao | e760702 | 2010-08-17 19:03:44 +0000 | [diff] [blame] | 24 |  | 
 | 25 | static inline int proto_ports_offset(int proto) | 
 | 26 | { | 
 | 27 | 	switch (proto) { | 
 | 28 | 	case IPPROTO_TCP: | 
 | 29 | 	case IPPROTO_UDP: | 
 | 30 | 	case IPPROTO_DCCP: | 
 | 31 | 	case IPPROTO_ESP:	/* SPI */ | 
 | 32 | 	case IPPROTO_SCTP: | 
 | 33 | 	case IPPROTO_UDPLITE: | 
 | 34 | 		return 0; | 
 | 35 | 	case IPPROTO_AH:	/* SPI */ | 
 | 36 | 		return 4; | 
 | 37 | 	default: | 
 | 38 | 		return -EINVAL; | 
 | 39 | 	} | 
 | 40 | } | 
 | 41 |  | 
| Joe Perches | 2658fa8 | 2007-12-16 13:42:49 -0800 | [diff] [blame] | 42 | static inline bool ipv4_is_loopback(__be32 addr) | 
 | 43 | { | 
 | 44 | 	return (addr & htonl(0xff000000)) == htonl(0x7f000000); | 
 | 45 | } | 
 | 46 |  | 
 | 47 | static inline bool ipv4_is_multicast(__be32 addr) | 
 | 48 | { | 
 | 49 | 	return (addr & htonl(0xf0000000)) == htonl(0xe0000000); | 
 | 50 | } | 
 | 51 |  | 
 | 52 | static inline bool ipv4_is_local_multicast(__be32 addr) | 
 | 53 | { | 
 | 54 | 	return (addr & htonl(0xffffff00)) == htonl(0xe0000000); | 
 | 55 | } | 
 | 56 |  | 
| Jan Engelhardt | 1e637c7 | 2008-01-21 03:18:08 -0800 | [diff] [blame] | 57 | static inline bool ipv4_is_lbcast(__be32 addr) | 
| Joe Perches | 2658fa8 | 2007-12-16 13:42:49 -0800 | [diff] [blame] | 58 | { | 
| Jan Engelhardt | 1e637c7 | 2008-01-21 03:18:08 -0800 | [diff] [blame] | 59 | 	/* limited broadcast */ | 
| Al Viro | 0ff9663 | 2008-03-17 22:48:46 -0700 | [diff] [blame] | 60 | 	return addr == htonl(INADDR_BROADCAST); | 
| Joe Perches | 2658fa8 | 2007-12-16 13:42:49 -0800 | [diff] [blame] | 61 | } | 
 | 62 |  | 
 | 63 | static inline bool ipv4_is_zeronet(__be32 addr) | 
 | 64 | { | 
 | 65 | 	return (addr & htonl(0xff000000)) == htonl(0x00000000); | 
 | 66 | } | 
 | 67 |  | 
| Fred L. Templin | c7dc89c | 2007-11-29 22:11:40 +1100 | [diff] [blame] | 68 | /* Special-Use IPv4 Addresses (RFC3330) */ | 
| Joe Perches | 2658fa8 | 2007-12-16 13:42:49 -0800 | [diff] [blame] | 69 |  | 
 | 70 | static inline bool ipv4_is_private_10(__be32 addr) | 
 | 71 | { | 
 | 72 | 	return (addr & htonl(0xff000000)) == htonl(0x0a000000); | 
 | 73 | } | 
 | 74 |  | 
 | 75 | static inline bool ipv4_is_private_172(__be32 addr) | 
 | 76 | { | 
 | 77 | 	return (addr & htonl(0xfff00000)) == htonl(0xac100000); | 
 | 78 | } | 
 | 79 |  | 
 | 80 | static inline bool ipv4_is_private_192(__be32 addr) | 
 | 81 | { | 
 | 82 | 	return (addr & htonl(0xffff0000)) == htonl(0xc0a80000); | 
 | 83 | } | 
 | 84 |  | 
 | 85 | static inline bool ipv4_is_linklocal_169(__be32 addr) | 
 | 86 | { | 
 | 87 | 	return (addr & htonl(0xffff0000)) == htonl(0xa9fe0000); | 
 | 88 | } | 
 | 89 |  | 
 | 90 | static inline bool ipv4_is_anycast_6to4(__be32 addr) | 
 | 91 | { | 
 | 92 | 	return (addr & htonl(0xffffff00)) == htonl(0xc0586300); | 
 | 93 | } | 
 | 94 |  | 
 | 95 | static inline bool ipv4_is_test_192(__be32 addr) | 
 | 96 | { | 
 | 97 | 	return (addr & htonl(0xffffff00)) == htonl(0xc0000200); | 
 | 98 | } | 
 | 99 |  | 
 | 100 | static inline bool ipv4_is_test_198(__be32 addr) | 
 | 101 | { | 
 | 102 | 	return (addr & htonl(0xfffe0000)) == htonl(0xc6120000); | 
 | 103 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | #endif	/* _LINUX_IN_H */ |