inet.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #ifndef __netinet_in__
  10. #define __netinet_in__
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. /*
  15. * Copyright (c) 1982, 1986, 1990 Regents of the University of California.
  16. * All rights reserved.
  17. *
  18. * Redistribution is only permitted until one year after the first shipment
  19. * of 4.4BSD by the Regents. Otherwise, redistribution and use in source and
  20. * binary forms are permitted provided that: (1) source distributions retain
  21. * this entire copyright notice and comment, and (2) distributions including
  22. * binaries display the following acknowledgement: This product includes
  23. * software developed by the University of California, Berkeley and its
  24. * contributors'' in the documentation or other materials provided with the
  25. * distribution and in all advertising materials mentioning features or use
  26. * of this software. Neither the name of the University nor the names of
  27. * its contributors may be used to endorse or promote products derived from
  28. * this software without specific prior written permission.
  29. * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  30. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  31. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  32. *
  33. * @(#)in.h 7.10 (Berkeley) 6/28/90 plus MULTICAST 1.1
  34. */
  35. /*
  36. * Constants and structures defined by the internet system,
  37. * Per RFC 790, September 1981.
  38. */
  39. /*
  40. * Protocols
  41. */
  42. #define IPPROTO_IP 0 /* dummy for IP */
  43. #define IPPROTO_ICMP 1 /* control message protocol */
  44. #define IPPROTO_GGP 3 /* gateway^2 (deprecated) */
  45. #define IPPROTO_TCP 6 /* tcp */
  46. #define IPPROTO_EGP 8 /* exterior gateway protocol */
  47. #define IPPROTO_PUP 12 /* pup */
  48. #define IPPROTO_UDP 17 /* user datagram protocol */
  49. #define IPPROTO_IDP 22 /* xns idp */
  50. #define IPPROTO_TP 29 /* tp-4 w/ class negotiation */
  51. #define IPPROTO_EON 80 /* ISO cnlp */
  52. #define IPPROTO_RAW 255 /* raw IP packet */
  53. #define IPPROTO_MAX 256
  54. /*
  55. * Local port number conventions:
  56. * Ports < IPPORT_RESERVED are reserved for
  57. * privileged processes (e.g. root).
  58. * Ports > IPPORT_USERRESERVED are reserved
  59. * for servers, not necessarily privileged.
  60. */
  61. #define IPPORT_RESERVED 1024
  62. #define IPPORT_USERRESERVED 5000
  63. /*
  64. * Internet address (a structure for historical reasons)
  65. */
  66. struct in_addr {
  67. unsigned long s_addr;
  68. };
  69. /*
  70. * Definitions of bits in internet address integers.
  71. * On subnets, the decomposition of addresses to host and net parts
  72. * is done according to subnet mask, not the masks here.
  73. */
  74. #define IN_CLASSA(i) (((long)(i) & 0x80000000) == 0)
  75. #define IN_CLASSA_NET 0xff000000
  76. #define IN_CLASSA_NSHIFT 24
  77. #define IN_CLASSA_HOST 0x00ffffff
  78. #define IN_CLASSA_MAX 128
  79. #define IN_CLASSB(i) (((long)(i) & 0xc0000000) == 0x80000000)
  80. #define IN_CLASSB_NET 0xffff0000
  81. #define IN_CLASSB_NSHIFT 16
  82. #define IN_CLASSB_HOST 0x0000ffff
  83. #define IN_CLASSB_MAX 65536
  84. #define IN_CLASSC(i) (((long)(i) & 0xe0000000) == 0xc0000000)
  85. #define IN_CLASSC_NET 0xffffff00
  86. #define IN_CLASSC_NSHIFT 8
  87. #define IN_CLASSC_HOST 0x000000ff
  88. #define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000)
  89. #define IN_MULTICAST(i) IN_CLASSD(i)
  90. #define IN_EXPERIMENTAL(i) (((long)(i) & 0xe0000000) == 0xe0000000)
  91. #define IN_BADCLASS(i) (((long)(i) & 0xf0000000) == 0xf0000000)
  92. #define INADDR_ANY (unsigned long)0x00000000
  93. #define INADDR_BROADCAST (unsigned long)0xffffffff /* must be masked */
  94. #define IN_LOOPBACKNET 127 /* official! */
  95. /*
  96. * Socket address, internet style.
  97. */
  98. struct sockaddr_in {
  99. short sin_family;
  100. unsigned short sin_port;
  101. struct in_addr sin_addr;
  102. char sin_zero[8];
  103. };
  104. /*
  105. * Structure used to describe IP options.
  106. * Used to store options internally, to pass them to a process,
  107. * or to restore options retrieved earlier.
  108. * The ip_dst is used for the first-hop gateway when using a source route
  109. * (this gets put into the header proper).
  110. */
  111. struct ip_opts {
  112. struct in_addr ip_dst; /* first hop, 0 w/o src rt */
  113. char ip_opts[40]; /* actually variable in size */
  114. };
  115. /*
  116. * Options for use with [gs]etsockopt at the IP level.
  117. * First word of comment is data type; bool is stored in int.
  118. */
  119. #define IP_OPTIONS 1 /* buf/ip_opts; set/get IP per-packet options */
  120. #define IP_HDRINCL 7 /* int; header is included with data (raw) */
  121. #define IP_TOS 8 /* int; IP type of service and precedence */
  122. #define IP_TTL 9 /* int; IP time to live */
  123. extern unsigned long ntohl(unsigned long x);
  124. extern unsigned short ntohs(unsigned short x);
  125. extern unsigned long htonl(unsigned long x);
  126. extern unsigned short htons(unsigned short x);
  127. extern unsigned long inet_addr(char*);
  128. extern char* inet_ntoa(struct in_addr);
  129. extern unsigned long nptohl(void*);
  130. #ifdef __cplusplus
  131. }
  132. #endif
  133. #endif /* __netinet_in__ */