PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/winsup/cygwin/include/cygwin/socket.h

https://gitlab.com/buildchain/newlib-cygwin
C Header | 326 lines | 246 code | 37 blank | 43 comment | 0 complexity | a0e217616546ffb17a5936f6cdbfb5fb MD5 | raw file
  1. /* cygwin/socket.h
  2. Copyright 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2009, 2010, 2012,
  3. 2013, 2014, 2015 Red Hat, Inc.
  4. This file is part of Cygwin.
  5. This software is a copyrighted work licensed under the terms of the
  6. Cygwin license. Please consult the file "CYGWIN_LICENSE" for
  7. details. */
  8. #ifndef _CYGWIN_SOCKET_H
  9. #define _CYGWIN_SOCKET_H
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif /* __cplusplus */
  13. #include <stdint.h>
  14. /* Not unsigned for backward compatibility. Keep #define for backward
  15. compatibility. */
  16. #ifndef socklen_t
  17. typedef int socklen_t;
  18. #define socklen_t socklen_t
  19. #endif
  20. typedef uint16_t sa_family_t;
  21. #ifndef __INSIDE_CYGWIN_NET__
  22. struct sockaddr {
  23. sa_family_t sa_family; /* address family, AF_xxx */
  24. char sa_data[14]; /* 14 bytes of protocol address */
  25. };
  26. /* Definition of sockaddr_storage according to SUSv3. */
  27. #define _SS_MAXSIZE 128 /* Maximum size. */
  28. #define _SS_ALIGNSIZE (sizeof (int64_t))/* Desired alignment. */
  29. #define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof (sa_family_t))
  30. #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (sa_family_t) \
  31. + _SS_PAD1SIZE + _SS_ALIGNSIZE))
  32. struct sockaddr_storage {
  33. sa_family_t ss_family;
  34. char _ss_pad1[_SS_PAD1SIZE];
  35. int64_t __ss_align;
  36. char _ss_pad2[_SS_PAD2SIZE];
  37. };
  38. #endif
  39. #include <asm/socket.h> /* arch-dependent defines */
  40. #include <cygwin/sockios.h> /* the SIOCxxx I/O controls */
  41. #include <sys/uio.h> /* iovec support */
  42. #include <sys/types.h>
  43. struct ucred {
  44. pid_t pid;
  45. uid_t uid;
  46. gid_t gid;
  47. };
  48. struct linger {
  49. unsigned short l_onoff; /* Linger active */
  50. unsigned short l_linger; /* How long to linger for */
  51. };
  52. struct msghdr
  53. {
  54. void * msg_name; /* Socket name */
  55. socklen_t msg_namelen; /* Length of name */
  56. struct iovec * msg_iov; /* Data blocks */
  57. int msg_iovlen; /* Number of blocks */
  58. void * msg_control; /* Ancillary data */
  59. socklen_t msg_controllen; /* Ancillary data buffer length */
  60. int msg_flags; /* Received flags on recvmsg */
  61. };
  62. struct cmsghdr
  63. {
  64. /* Amazing but true: The type of cmsg_len should be socklen_t but, just
  65. as on Linux, the definition of the kernel is incompatible with this,
  66. so the Windows socket headers define cmsg_len as SIZE_T. */
  67. size_t cmsg_len; /* Length of cmsghdr + data */
  68. int cmsg_level; /* Protocol */
  69. int cmsg_type; /* Protocol type */
  70. };
  71. #define CMSG_ALIGN(len) \
  72. (((len) + __alignof__ (struct cmsghdr) - 1) \
  73. & ~(__alignof__ (struct cmsghdr) - 1))
  74. #define CMSG_LEN(len) \
  75. (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len))
  76. #define CMSG_SPACE(len) \
  77. (CMSG_ALIGN (sizeof (struct cmsghdr)) + CMSG_ALIGN(len))
  78. #define CMSG_FIRSTHDR(mhdr) \
  79. ({ \
  80. struct msghdr *_m = (struct msghdr *) mhdr; \
  81. (unsigned) (_m)->msg_controllen >= sizeof (struct cmsghdr) \
  82. ? (struct cmsghdr *) (_m)->msg_control \
  83. : (struct cmsghdr *) NULL; \
  84. })
  85. #define CMSG_NXTHDR(mhdr,cmsg) \
  86. ({ \
  87. struct msghdr *_m = (struct msghdr *) mhdr; \
  88. struct cmsghdr *_c = (struct cmsghdr *) cmsg; \
  89. ((char *) _c + CMSG_SPACE (_c->cmsg_len) \
  90. > (char *) _m->msg_control + _m->msg_controllen) \
  91. ? (struct cmsghdr *) NULL \
  92. : (struct cmsghdr *) ((char *) _c + CMSG_ALIGN (_c->cmsg_len)); \
  93. })
  94. #define CMSG_DATA(cmsg) \
  95. ((unsigned char *) ((struct cmsghdr *)(cmsg) + 1))
  96. /* "Socket"-level control message types: */
  97. #define SCM_RIGHTS 0x01 /* access rights (array of int) */
  98. #ifdef __INSIDE_CYGWIN__
  99. /* Definition of struct msghdr up to release 1.5.18 */
  100. struct OLD_msghdr
  101. {
  102. void * msg_name; /* Socket name */
  103. int msg_namelen; /* Length of name */
  104. struct iovec * msg_iov; /* Data blocks */
  105. int msg_iovlen; /* Number of blocks */
  106. void * msg_accrights; /* Per protocol magic */
  107. /* (eg BSD descriptor passing) */
  108. int msg_accrightslen; /* Length of rights list */
  109. };
  110. #endif
  111. /* Socket types. */
  112. #define SOCK_STREAM 1 /* stream (connection) socket */
  113. #define SOCK_DGRAM 2 /* datagram (conn.less) socket */
  114. #define SOCK_RAW 3 /* raw socket */
  115. #define SOCK_RDM 4 /* reliably-delivered message */
  116. #define SOCK_SEQPACKET 5 /* sequential packet socket */
  117. /* GNU extension flags. Or them to the type parameter in calls to
  118. socket(2) to mark socket as nonblocking and/or close-on-exec. */
  119. #define SOCK_NONBLOCK 0x01000000
  120. #define SOCK_CLOEXEC 0x02000000
  121. #ifdef __INSIDE_CYGWIN__
  122. #define _SOCK_FLAG_MASK 0xff000000 /* Bits left for more extensions */
  123. #endif
  124. /* Supported address families. */
  125. /*
  126. * Address families.
  127. */
  128. #define AF_UNSPEC 0 /* unspecified */
  129. #define AF_UNIX 1 /* local to host (pipes, portals) */
  130. #define AF_LOCAL 1 /* POSIX name for AF_UNIX */
  131. #define AF_INET 2 /* internetwork: UDP, TCP, etc. */
  132. #define AF_IMPLINK 3 /* arpanet imp addresses */
  133. #define AF_PUP 4 /* pup protocols: e.g. BSP */
  134. #define AF_CHAOS 5 /* mit CHAOS protocols */
  135. #define AF_NS 6 /* XEROX NS protocols */
  136. #define AF_ISO 7 /* ISO protocols */
  137. #define AF_OSI AF_ISO /* OSI is ISO */
  138. #define AF_ECMA 8 /* european computer manufacturers */
  139. #define AF_DATAKIT 9 /* datakit protocols */
  140. #define AF_CCITT 10 /* CCITT protocols, X.25 etc */
  141. #define AF_SNA 11 /* IBM SNA */
  142. #define AF_DECnet 12 /* DECnet */
  143. #define AF_DLI 13 /* Direct data link interface */
  144. #define AF_LAT 14 /* LAT */
  145. #define AF_HYLINK 15 /* NSC Hyperchannel */
  146. #define AF_APPLETALK 16 /* AppleTalk */
  147. #define AF_NETBIOS 17 /* NetBios-style addresses */
  148. #define AF_INET6 23 /* IP version 6 */
  149. #define AF_MAX 32
  150. /*
  151. * Protocol families, same as address families for now.
  152. */
  153. #define PF_UNSPEC AF_UNSPEC
  154. #define PF_UNIX AF_UNIX
  155. #define PF_LOCAL AF_LOCAL
  156. #define PF_INET AF_INET
  157. #define PF_IMPLINK AF_IMPLINK
  158. #define PF_PUP AF_PUP
  159. #define PF_CHAOS AF_CHAOS
  160. #define PF_NS AF_NS
  161. #define PF_ISO AF_ISO
  162. #define PF_OSI AF_OSI
  163. #define PF_ECMA AF_ECMA
  164. #define PF_DATAKIT AF_DATAKIT
  165. #define PF_CCITT AF_CCITT
  166. #define PF_SNA AF_SNA
  167. #define PF_DECnet AF_DECnet
  168. #define PF_DLI AF_DLI
  169. #define PF_LAT AF_LAT
  170. #define PF_HYLINK AF_HYLINK
  171. #define PF_APPLETALK AF_APPLETALK
  172. #define PF_NETBIOS AF_NETBIOS
  173. #define PF_INET6 AF_INET6
  174. #define PF_MAX AF_MAX
  175. /* Maximum queue length specificable by listen. */
  176. #define SOMAXCONN 0x7fffffff
  177. /* Flags we can use with send/ and recv. */
  178. #define MSG_OOB 0x1 /* process out-of-band data */
  179. #define MSG_PEEK 0x2 /* peek at incoming message */
  180. #define MSG_DONTROUTE 0x4 /* send without using routing tables */
  181. #define MSG_WAITALL 0x8 /* wait for all requested bytes */
  182. #define MSG_DONTWAIT 0x10 /* selective non-blocking operation */
  183. #define MSG_NOSIGNAL 0x20 /* Don't raise SIGPIPE */
  184. #define MSG_TRUNC 0x0100 /* Normal data truncated */
  185. #define MSG_CTRUNC 0x0200 /* Control data truncated */
  186. /* Windows-specific flag values returned by recvmsg. */
  187. #define MSG_BCAST 0x0400 /* Broadcast datagram */
  188. #define MSG_MCAST 0x0800 /* Multicast datagram */
  189. /* Setsockoptions(2) level. Thanks to BSD these must match IPPROTO_xxx */
  190. #define SOL_IP 0
  191. #define SOL_IPV6 41
  192. #define SOL_IPX 256
  193. #define SOL_AX25 257
  194. #define SOL_ATALK 258
  195. #define SOL_NETROM 259
  196. #define SOL_TCP 6
  197. #define SOL_UDP 17
  198. /* IP options */
  199. #ifndef IPTOS_LOWDELAY
  200. #define IPTOS_LOWDELAY 0x10
  201. #define IPTOS_THROUGHPUT 0x08
  202. #define IPTOS_RELIABILITY 0x04
  203. #endif
  204. /* These need to appear somewhere around here */
  205. #define IP_DEFAULT_MULTICAST_TTL 1
  206. #define IP_DEFAULT_MULTICAST_LOOP 1
  207. #define IP_MAX_MEMBERSHIPS 20
  208. /* IP options for use with getsockopt/setsockopt */
  209. #define IP_OPTIONS 1
  210. #define IP_HDRINCL 2
  211. #define IP_TOS 3
  212. #define IP_TTL 4
  213. #define IP_MULTICAST_IF 9
  214. #define IP_MULTICAST_TTL 10
  215. #define IP_MULTICAST_LOOP 11
  216. #define IP_ADD_MEMBERSHIP 12
  217. #define IP_DROP_MEMBERSHIP 13
  218. #define IP_DONTFRAGMENT 14
  219. #define IP_ADD_SOURCE_MEMBERSHIP 15
  220. #define IP_DROP_SOURCE_MEMBERSHIP 16
  221. #define IP_BLOCK_SOURCE 17
  222. #define IP_UNBLOCK_SOURCE 18
  223. #define IP_PKTINFO 19
  224. #define IP_UNICAST_IF 31
  225. /* IPv6 options for use with getsockopt/setsockopt */
  226. #define IPV6_HOPOPTS 1
  227. #define IPV6_UNICAST_HOPS 4
  228. #define IPV6_MULTICAST_IF 9
  229. #define IPV6_MULTICAST_HOPS 10
  230. #define IPV6_MULTICAST_LOOP 11
  231. #define IPV6_ADD_MEMBERSHIP 12
  232. #define IPV6_DROP_MEMBERSHIP 13
  233. #define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP
  234. #define IPV6_LEAVE_GROUP IPV6_DROP_MEMBERSHIP
  235. #define IPV6_DONTFRAG 14
  236. #define IPV6_PKTINFO 19
  237. #define IPV6_HOPLIMIT 21
  238. #define IPV6_CHECKSUM 26
  239. #define IPV6_V6ONLY 27
  240. #define IPV6_UNICAST_IF 31
  241. #define IPV6_RTHDR 32
  242. #define IPV6_RECVRTHDR 38
  243. #define IPV6_TCLASS 39
  244. #define IPV6_RECVTCLASS 40
  245. /* IP agnostic options for use with getsockopt/setsockopt */
  246. #define MCAST_JOIN_GROUP 41
  247. #define MCAST_LEAVE_GROUP 42
  248. #define MCAST_BLOCK_SOURCE 43
  249. #define MCAST_UNBLOCK_SOURCE 44
  250. #define MCAST_JOIN_SOURCE_GROUP 45
  251. #define MCAST_LEAVE_SOURCE_GROUP 46
  252. #ifndef __INSIDE_CYGWIN_NET__
  253. #define MCAST_INCLUDE 0
  254. #define MCAST_EXCLUDE 1
  255. #endif
  256. /* Old WinSock1 values, needed internally */
  257. #ifdef __INSIDE_CYGWIN__
  258. #define _WS1_IP_OPTIONS 1
  259. #define _WS1_IP_MULTICAST_IF 2
  260. #define _WS1_IP_MULTICAST_TTL 3
  261. #define _WS1_IP_MULTICAST_LOOP 4
  262. #define _WS1_IP_ADD_MEMBERSHIP 5
  263. #define _WS1_IP_DROP_MEMBERSHIP 6
  264. #define _WS1_IP_TTL 7
  265. #define _WS1_IP_TOS 8
  266. #define _WS1_IP_DONTFRAGMENT 9
  267. #endif
  268. /* IPX options */
  269. #define IPX_TYPE 1
  270. /* TCP options - this way around because someone left a set in the c library includes */
  271. #ifndef TCP_NODELAY
  272. #define TCP_NODELAY 0x0001
  273. #define TCP_MAXSEG 2
  274. #endif
  275. /* SUS symbolic values for the second parm to shutdown(2) */
  276. #define SHUT_RD 0 /* == Win32 SD_RECEIVE */
  277. #define SHUT_WR 1 /* == Win32 SD_SEND */
  278. #define SHUT_RDWR 2 /* == Win32 SD_BOTH */
  279. /* The various priorities. */
  280. #define SOPRI_INTERACTIVE 0
  281. #define SOPRI_NORMAL 1
  282. #define SOPRI_BACKGROUND 2
  283. #ifdef __cplusplus
  284. };
  285. #endif /* __cplusplus */
  286. #endif /* _CYGWIN_SOCKET_H */