in.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #include <linux/errno.h>
  21. #include <uapi/linux/in.h>
  22. static inline int proto_ports_offset(int proto)
  23. {
  24. switch (proto) {
  25. case IPPROTO_TCP:
  26. case IPPROTO_UDP:
  27. case IPPROTO_DCCP:
  28. case IPPROTO_ESP: /* SPI */
  29. case IPPROTO_SCTP:
  30. case IPPROTO_UDPLITE:
  31. return 0;
  32. case IPPROTO_AH: /* SPI */
  33. return 4;
  34. default:
  35. return -EINVAL;
  36. }
  37. }
  38. static inline bool ipv4_is_loopback(__be32 addr)
  39. {
  40. return (addr & htonl(0xff000000)) == htonl(0x7f000000);
  41. }
  42. static inline bool ipv4_is_multicast(__be32 addr)
  43. {
  44. return (addr & htonl(0xf0000000)) == htonl(0xe0000000);
  45. }
  46. static inline bool ipv4_is_local_multicast(__be32 addr)
  47. {
  48. return (addr & htonl(0xffffff00)) == htonl(0xe0000000);
  49. }
  50. static inline bool ipv4_is_lbcast(__be32 addr)
  51. {
  52. /* limited broadcast */
  53. return addr == htonl(INADDR_BROADCAST);
  54. }
  55. static inline bool ipv4_is_zeronet(__be32 addr)
  56. {
  57. return (addr & htonl(0xff000000)) == htonl(0x00000000);
  58. }
  59. /* Special-Use IPv4 Addresses (RFC3330) */
  60. static inline bool ipv4_is_private_10(__be32 addr)
  61. {
  62. return (addr & htonl(0xff000000)) == htonl(0x0a000000);
  63. }
  64. static inline bool ipv4_is_private_172(__be32 addr)
  65. {
  66. return (addr & htonl(0xfff00000)) == htonl(0xac100000);
  67. }
  68. static inline bool ipv4_is_private_192(__be32 addr)
  69. {
  70. return (addr & htonl(0xffff0000)) == htonl(0xc0a80000);
  71. }
  72. static inline bool ipv4_is_linklocal_169(__be32 addr)
  73. {
  74. return (addr & htonl(0xffff0000)) == htonl(0xa9fe0000);
  75. }
  76. static inline bool ipv4_is_anycast_6to4(__be32 addr)
  77. {
  78. return (addr & htonl(0xffffff00)) == htonl(0xc0586300);
  79. }
  80. static inline bool ipv4_is_test_192(__be32 addr)
  81. {
  82. return (addr & htonl(0xffffff00)) == htonl(0xc0000200);
  83. }
  84. static inline bool ipv4_is_test_198(__be32 addr)
  85. {
  86. return (addr & htonl(0xfffe0000)) == htonl(0xc6120000);
  87. }
  88. #endif /* _LINUX_IN_H */