socket.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (c) 2004, 2008
  3. * The President and Fellows of Harvard College.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the University nor the names of its contributors
  14. * may be used to endorse or promote products derived from this software
  15. * without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. */
  29. #ifndef _KERN_SOCKET_H_
  30. #define _KERN_SOCKET_H_
  31. /*
  32. * Socket-related definitions, for <sys/socket.h>.
  33. */
  34. /*
  35. * Important
  36. */
  37. /* Socket types that we (might) support. */
  38. #define SOCK_STREAM 1 /* stream */
  39. #define SOCK_DGRAM 2 /* packet */
  40. #define SOCK_RAW 3 /* raw packet */
  41. /* Address families that we (might) support. */
  42. #define AF_UNSPEC 0
  43. #define AF_UNIX 1
  44. #define AF_INET 2
  45. #define AF_INET6 3
  46. /* Protocol families. Pointless layer of indirection in the standard API. */
  47. #define PF_UNSPEC AF_UNSPEC
  48. #define PF_UNIX AF_UNIX
  49. #define PF_INET AF_INET
  50. #define PF_INET6 AF_INET6
  51. /*
  52. * Socket address structures. Socket addresses are polymorphic, and
  53. * the polymorphism is handled by casting pointers. It's fairly gross,
  54. * but way too deeply standardized to ever change.
  55. *
  56. * Each address family defines a sockaddr type (sockaddr_un,
  57. * sockaddr_in, etc.) struct sockaddr is the common prefix of all
  58. * these, and struct sockaddr_storage is defined to be large enough to
  59. * hold any of them.
  60. *
  61. * The complex padding in sockaddr_storage forces it to be aligned,
  62. * which wouldn't happen if it were just a char array.
  63. */
  64. struct sockaddr {
  65. __u8 sa_len;
  66. __u8 sa_family;
  67. };
  68. #define _SS_SIZE 128
  69. struct sockaddr_storage {
  70. __u8 ss_len;
  71. __u8 ss_family;
  72. __u8 __ss_pad1;
  73. __u8 __ss_pad2;
  74. __u32 __ss_pad3;
  75. __u64 __ss_pad4;
  76. char __ss_pad5[_SS_SIZE - sizeof(__u64) - sizeof(__u32) - 4*sizeof(__u8)];
  77. };
  78. /*
  79. * Not very important.
  80. */
  81. /*
  82. * msghdr structures for sendmsg() and recvmsg().
  83. */
  84. struct msghdr {
  85. void *msg_name; /* really sockaddr; address, or null */
  86. socklen_t msg_namelen; /* size of msg_name object, or 0 */
  87. struct iovec *msg_iov; /* I/O buffers */
  88. int msg_iovlen; /* number of iovecs */
  89. void *msg_control; /* auxiliary data area, or null */
  90. socklen_t msg_controllen; /* size of msg_control area */
  91. int msg_flags; /* flags */
  92. };
  93. struct cmsghdr {
  94. socklen_t cmsg_len; /* length of control data, including header */
  95. int cmsg_level; /* protocol layer item originates from */
  96. int cmsg_type; /* protocol-specific message type */
  97. /* char cmsg_data[];*/ /* data follows the header */
  98. };
  99. #endif /* _KERN_SOCKET_H_ */