in.h 4.7 KB

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