PageRenderTime 54ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/include/minoca/kernel/knet.h

https://gitlab.com/vascocosta/os
C Header | 1792 lines | 407 code | 147 blank | 1238 comment | 6 complexity | 027d3413696d85126b5ba6aff30e1090 MD5 | raw file
  1. /*++
  2. Copyright (c) 2013 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. knet.h
  9. Abstract:
  10. This header contains the interface between the kernel and the networking
  11. core library.
  12. Author:
  13. Evan Green 4-Apr-2013
  14. --*/
  15. //
  16. // ------------------------------------------------------------------- Includes
  17. //
  18. //
  19. // --------------------------------------------------------------------- Macros
  20. //
  21. //
  22. // Define macros for manipulating a sequence of socket control messages.
  23. //
  24. //
  25. // This macro evaluates to a pointer to the ancillary data following a cmsghdr
  26. // structure.
  27. //
  28. #define SOCKET_CONTROL_DATA(_Control) \
  29. ((PVOID)((PSOCKET_CONTROL_MESSAGE)(_Control) + 1))
  30. //
  31. // This macro advances a cmsghdr pointer to the next cmsghdr, or assigns it to
  32. // NULL if it is the last one. The first parameter is a pointer to the original
  33. // msghdr.
  34. //
  35. #define SOCKET_CONTROL_NEXT(_ControlBuffer, _ControlBufferSize, _Control) \
  36. if ((_Control)->Length < sizeof(SOCKET_CONTROL_MESSAGE)) { \
  37. (_Control) = NULL; \
  38. \
  39. } else { \
  40. (_Control) = (PSOCKET_CONTROL_MESSAGE)((PVOID)(_Control) + \
  41. SOCKET_CONTROL_ALIGN((_Control)->Length)); \
  42. \
  43. if (((PVOID)((_Control) + 1) > \
  44. (PVOID)(_ControlBuffer) + (_ControlBufferSize)) || \
  45. ((PVOID)(_Control) + SOCKET_CONTROL_ALIGN((_Control)->Length) > \
  46. ((PVOID)(_ControlBuffer) + (_ControlBufferSize)))) { \
  47. \
  48. (_Control) = NULL; \
  49. } \
  50. }
  51. //
  52. // This macro evaluates to the first cmsghdr given a msghdr structure, or
  53. // NULL if there is no data.
  54. //
  55. #define SOCKET_CONTROL_FIRST(_ControlBuffer, _ControlBufferSize) \
  56. (((_ControlBufferSize) >= sizeof(SOCKET_CONTROL_MESSAGE)) ? \
  57. (PSOCKET_CONTROL_MESSAGE)(_ControlBuffer) : \
  58. NULL)
  59. //
  60. // This macro returns the required alignment for a given length. This is a
  61. // constant expression.
  62. //
  63. #define SOCKET_CONTROL_ALIGN(_Length) ALIGN_RANGE_UP(_Length, sizeof(UINTN))
  64. //
  65. // This macro returns the number of bytes an ancillary element with the given
  66. // payload size takes up. This is a constant expression.
  67. //
  68. #define SOCKET_CONTROL_SPACE(_Length) \
  69. (SOCKET_CONTROL_ALIGN(_Length) + \
  70. SOCKET_CONTROL_ALIGN(sizeof(SOCKET_CONTROL_MESSAGE)))
  71. //
  72. // This macro returns the value to store in the cmsghdr length member, taking
  73. // into account any necessary alignment. It takes the data length as an
  74. // argument. This is a constant expression.
  75. //
  76. #define SOCKET_CONTROL_LENGTH(_Length) \
  77. (SOCKET_CONTROL_ALIGN(sizeof(SOCKET_CONTROL_MESSAGE)) + (_Length))
  78. //
  79. // This macro returns TRUE if the network domain is a physical network or FALSE
  80. // otherwise.
  81. //
  82. #define NET_IS_PHYSICAL_DOMAIN(_Domain) \
  83. (((_Domain) >= NET_DOMAIN_PHYSICAL_BASE) && \
  84. ((_Domain) < NET_DOMAIN_PHYSICAL_LIMIT))
  85. //
  86. // This macro returns TRUE if the network domain is a socket network or FALSE
  87. // otherwise.
  88. //
  89. #define NET_IS_SOCKET_NETWORK_DOMAIN(_Domain) \
  90. (((_Domain) >= NET_DOMAIN_SOCKET_NETWORK_BASE) && \
  91. ((_Domain) < NET_DOMAIN_SOCKET_NETWORK_LIMIT))
  92. //
  93. // ---------------------------------------------------------------- Definitions
  94. //
  95. //
  96. // Define the maximum number of bytes in a network address.
  97. //
  98. #define MAX_NETWORK_ADDRESS_SIZE 16
  99. //
  100. // Define socket shutdown types. These can be ORed together.
  101. //
  102. #define SOCKET_SHUTDOWN_READ 0x00000001
  103. #define SOCKET_SHUTDOWN_WRITE 0x00000002
  104. //
  105. // Define socket I/O flags. These should match up to the C library MSG_* flags.
  106. //
  107. //
  108. // Peeks at an incoming message without officially receiving it. The data is
  109. // treated as unread and the next recv or similar function call still returns
  110. // the same data.
  111. //
  112. #define SOCKET_IO_PEEK 0x00000001
  113. //
  114. // Requests out-of-band data. The significants and semantics of out-of-band
  115. // data are protocol-specific.
  116. //
  117. #define SOCKET_IO_OUT_OF_BAND 0x00000002
  118. //
  119. // On SOCK_STREAM sockets this requests that the function block until the full
  120. // amount of data can be returned. The function may return the smaller amount
  121. // of data if the socket is a message-based socket, if a signal is caught, if
  122. // the connection is terminated, is MSG_PEEK was specified, or if an error is
  123. // pending for the socket.
  124. //
  125. #define SOCKET_IO_WAIT_ALL 0x00000004
  126. //
  127. // This flag indicates a complete message, used by sequential packet sockets.
  128. // This flag can be set by user-mode on transmit and kernel-mode on receive.
  129. //
  130. #define SOCKET_IO_END_OF_RECORD 0x00000008
  131. //
  132. // This flag is returned by the kernel when the trailing portion of the
  133. // datagram was discarded because the datagram was larger than the buffer
  134. // supplied.
  135. //
  136. #define SOCKET_IO_DATA_TRUNCATED 0x00000010
  137. //
  138. // This flag is returned by the kernel when some control/ancillary data is
  139. // discarded due to lack of space in the provided ancillary buffer.
  140. //
  141. #define SOCKET_IO_CONTROL_TRUNCATED 0x00000020
  142. //
  143. // This flag requests not to send a broken pipe signal on stream oriented
  144. // sockets when the other end breaks the connection. The broken pipe status
  145. // is still returned.
  146. //
  147. #define SOCKET_IO_NO_SIGNAL 0x00000040
  148. //
  149. // This flag requests that the operation not block.
  150. //
  151. #define SOCKET_IO_NON_BLOCKING 0x00000080
  152. //
  153. // This flag requests that routing tables not be used when sending a packet.
  154. // This limits the system to sending the packet across networks that are
  155. // directly connected.
  156. //
  157. #define SOCKET_IO_DONT_ROUTE 0x00000100
  158. //
  159. // Define common internet protocol numbers, as defined by the IANA.
  160. //
  161. #define SOCKET_INTERNET_PROTOCOL_ICMP 1
  162. #define SOCKET_INTERNET_PROTOCOL_IPV4 4
  163. #define SOCKET_INTERNET_PROTOCOL_TCP 6
  164. #define SOCKET_INTERNET_PROTOCOL_UDP 17
  165. #define SOCKET_INTERNET_PROTOCOL_IPV6 41
  166. //
  167. // Define non-IANA protocol numbers starting with the raw protocol at 255, the
  168. // highest reserved IANA value.
  169. //
  170. #define SOCKET_INTERNET_PROTOCOL_RAW 255
  171. #define SOCKET_INTERNET_PROTOCOL_NETLINK 256
  172. #define SOCKET_INTERNET_PROTOCOL_NETLINK_GENERIC 257
  173. //
  174. // Define the socket level of control messages.
  175. //
  176. #define SOCKET_LEVEL_SOCKET 0xFFFF
  177. //
  178. // Define socket level control message types, currently only used by local
  179. // sockets. These must match up with the C library SCM_* definitions.
  180. //
  181. //
  182. // This control message type allows the passing of file descriptors.
  183. //
  184. #define SOCKET_CONTROL_RIGHTS 1
  185. //
  186. // This control message type allows the passing of credentials.
  187. //
  188. #define SOCKET_CONTROL_CREDENTIALS 2
  189. //
  190. // As the C library socket options are passed straight through to the kernel,
  191. // this causes conversions from int options to ULONG options. Guard against
  192. // negative values by defining a new maximum ULONG value.
  193. //
  194. #define SOCKET_OPTION_MAX_ULONG ((ULONG)0x7FFFFFFF)
  195. //
  196. // Define the ranges for the different regions of the net domain type namespace.
  197. //
  198. #define NET_DOMAIN_SOCKET_NETWORK_BASE 0x0000
  199. #define NET_DOMAIN_SOCKET_NETWORK_LIMIT 0x4000
  200. #define NET_DOMAIN_LOW_LEVEL_NETWORK_BASE 0x4000
  201. #define NET_DOMAIN_LOW_LEVEL_NETWORK_LIMIT 0x8000
  202. #define NET_DOMAIN_PHYSICAL_BASE 0x8000
  203. #define NET_DOMAIN_PHYSICAL_LIMIT 0xC000
  204. //
  205. // Define the kernel socket flags.
  206. //
  207. #define SOCKET_FLAG_SEND_TIMEOUT_SET 0x00000001
  208. #define SOCKET_FLAG_RECEIVE_TIMEOUT_SET 0x00000002
  209. //
  210. // ------------------------------------------------------ Data Type Definitions
  211. //
  212. typedef enum _NET_DOMAIN_TYPE {
  213. NetDomainInvalid = NET_DOMAIN_SOCKET_NETWORK_BASE,
  214. NetDomainLocal,
  215. NetDomainIp4,
  216. NetDomainIp6,
  217. NetDomainNetlink,
  218. NetDomainArp = NET_DOMAIN_LOW_LEVEL_NETWORK_BASE,
  219. NetDomainEapol,
  220. NetDomainEthernet = NET_DOMAIN_PHYSICAL_BASE,
  221. NetDomain80211
  222. } NET_DOMAIN_TYPE, *PNET_DOMAIN_TYPE;
  223. typedef enum _NET_SOCKET_TYPE {
  224. NetSocketInvalid,
  225. NetSocketDatagram,
  226. NetSocketRaw,
  227. NetSocketSequencedPacket,
  228. NetSocketStream
  229. } NET_SOCKET_TYPE, *PNET_SOCKET_TYPE;
  230. /*++
  231. Structure Description:
  232. This structure defines a generic network address.
  233. Members:
  234. Domain - Stores the network domain of this address.
  235. Port - Stores the port number, which may or may not be relevant depending
  236. on the protocol and network layers. This number is in host order.
  237. Address - Stores the network-specific addressing information. The address
  238. is in network order.
  239. --*/
  240. typedef struct _NETWORK_ADDRESS {
  241. NET_DOMAIN_TYPE Domain;
  242. ULONG Port;
  243. UINTN Address[MAX_NETWORK_ADDRESS_SIZE / sizeof(UINTN)];
  244. } NETWORK_ADDRESS, *PNETWORK_ADDRESS;
  245. typedef enum _SOCKET_INFORMATION_TYPE {
  246. SocketInformationBasic = 0xFFFF,
  247. SocketInformationIp4 = SOCKET_INTERNET_PROTOCOL_IPV4,
  248. SocketInformationIp6 = SOCKET_INTERNET_PROTOCOL_IPV6,
  249. SocketInformationTcp = SOCKET_INTERNET_PROTOCOL_TCP,
  250. SocketInformationUdp = SOCKET_INTERNET_PROTOCOL_UDP,
  251. SocketInformationRaw = SOCKET_INTERNET_PROTOCOL_RAW,
  252. SocketInformationNetlink = SOCKET_INTERNET_PROTOCOL_NETLINK,
  253. SocketInformationNetlinkGeneric = SOCKET_INTERNET_PROTOCOL_NETLINK_GENERIC
  254. } SOCKET_INFORMATION_TYPE, *PSOCKET_INFORMATION_TYPE;
  255. /*++
  256. Enumeration Description:
  257. This enumeration describes the various socket options for the basic socket
  258. information class.
  259. Values:
  260. SocketBasicOptionInvalid - Indicates an invalid basic socket option.
  261. SocketBasicOptionAcceptConnections - Indicates that the listening state of
  262. the socket should be retrieved. This option is read only and takes a
  263. ULONG boolean.
  264. SocketBasicOptionBroadcastEnabled - Indicates that the sending of broadcast
  265. packets should be enabled or disabled, or that the current state of the
  266. ability to send broadcast packets should be retrieved. This option
  267. takes a ULONG boolean.
  268. SocketBasicOptionDebug - Indicates that debugging should be enabled or
  269. disabled for the socket, or that the current debug state should be
  270. retrieved. This option takes a ULONG boolean.
  271. SocketBasicOptionRoutingDisabled - Indicates that the default routing
  272. process for packets should be enabled or disabled, or retrieves whether
  273. or not default routing is disabled. This option takes a ULONG boolean.
  274. SocketBasicOptionErrorStatus - Indicates that the socket's error status
  275. should be retrieved and cleared. This option is read only and takes a
  276. KSTATUS.
  277. SocketBasicOptionKeepAlive - Indicates that the performance of periodic
  278. connection checks should be enabled or disabled, or that the state of
  279. the use of such checks should be retrieved. This option takes a ULONG
  280. boolean.
  281. SocketBasicOptionLinger - Indicates that the socket's linger state should
  282. be modified or retrieved. This option takes a SOCKET_LINGER structure.
  283. If disabled, a connected socket will return immediately from a close
  284. operation and attempt to gracefully shut down the connection. If
  285. enabled without a timeout, a connected socket will abort the connection
  286. on a close option. If enabled with a timeout, the close operation will
  287. not return until all data has been sent and a graceful shutdown is
  288. complete or until the timer has expired, at which point the connection
  289. will be aborted.
  290. SocketBasicOptionInlineOutOfBand - Indicates that the inclusion of urgent
  291. data in the mainline packet processing should be enabled or disabled,
  292. or retrieves the current state of urgent packet processing. This option
  293. takes a ULONG boolean.
  294. SocketBasicOptionReceiveBufferSize - Indicates the size of the socket's
  295. receive bufffer to set, in bytes, or retrieves the current size of the
  296. socket's receive buffer. This option takes a ULONG.
  297. SocketBasicOptionReceiveMinimum - Indicates the minimum amount of data, in
  298. bytes, that needs to be received before the system will alert any
  299. readers that may be waiting on poll or receive operations. This option
  300. takes a ULONG.
  301. SocketBasicOptionReceiveTimeout - Indicates the maximum amount of time, in
  302. milliseconds, that a receive operation should wait for more data before
  303. completing. This option takes a SOCKET_TIME structure.
  304. SocketBasicOptionSendBufferSize - Indicates the size of the socket's send
  305. buffer to set, in bytes, or retrieves the current size of the socket's
  306. send buffer, in bytes. This option takes a ULONG.
  307. SocketBasicOptionSendMinimum - Indicates the minimum amount of data, in
  308. bytes, that needs to be sent before the socket will actually transmit
  309. packets. This option takes a ULONG.
  310. SocketBasicOptionSendTimeout - Indicates the maximum amount of time, in
  311. milliseconds, that a send operation should wait to send data if it is
  312. blocked by flow control. This option takes a SOCKET_TIME structure.
  313. SocketBasicOptionType - Indicates that the socket's protocol should be
  314. retrieved. This option is read only and takes a ULONG.
  315. SocketBasicOptionReuseAnyAddress - Indicates that the socket may be bound
  316. to the same local port as an existing socket as long as one of them is
  317. bound to the any address and the other is bound to a different local
  318. address (i.e. not the any address). Both sockets must have this option
  319. set for it to take effect. This option takes a ULONG Boolean. As a
  320. hold-over from the BSD sockets implementation, this will also set the
  321. SocketBasicOptionReuseTimeWait option.
  322. SocketBasicOptionReuseExactAddress - Indicates that the sockets may bind to
  323. the exact same address and port as an existing socket. Both sockets
  324. must have this option enabled. This option takes a ULONG boolean.
  325. SocketBasicOptionPassCredentials - Indicates that credentials should be
  326. sent and received automatically with messages on the socket. This is
  327. only applicable for local sockets. This option takes a ULONG boolean.
  328. SocketBasicOptionPeerCredentials - Indicates the credentials of the
  329. foreign socket at the time of connect. This is only applicable for
  330. local sockets.
  331. SocketBasicOptionDomain - Indicates that the socket's domain should be
  332. retrieved. This option is read only and takes a NET_DOMAIN_TYPE
  333. structure.
  334. SocketBasicOptionLocalAddress - Indicates that the socket's local address
  335. should be retrieved. This option is read only and takes a
  336. NETWORK_ADDRESS structure.
  337. SocketBasicOptionRemoteAddress - Indicates that the socket's remote address
  338. should be retrieved. This option is read only and takes a
  339. NETWORK_ADDRESS structure.
  340. SocketBasicOptionReuseTimeWait - Indicates that the socket may be bound to
  341. the exact same local address and port as an existing socket as long as
  342. the existing socket is in the time-wait state. Both sockets must have
  343. this option set for it to take effect. This option takes a ULONG
  344. boolean.
  345. --*/
  346. typedef enum _SOCKET_BASIC_OPTION {
  347. SocketBasicOptionInvalid,
  348. SocketBasicOptionAcceptConnections,
  349. SocketBasicOptionBroadcastEnabled,
  350. SocketBasicOptionDebug,
  351. SocketBasicOptionRoutingDisabled,
  352. SocketBasicOptionErrorStatus,
  353. SocketBasicOptionKeepAlive,
  354. SocketBasicOptionLinger,
  355. SocketBasicOptionInlineOutOfBand,
  356. SocketBasicOptionReceiveBufferSize,
  357. SocketBasicOptionReceiveMinimum,
  358. SocketBasicOptionReceiveTimeout,
  359. SocketBasicOptionSendBufferSize,
  360. SocketBasicOptionSendMinimum,
  361. SocketBasicOptionSendTimeout,
  362. SocketBasicOptionType,
  363. SocketBasicOptionReuseAnyAddress,
  364. SocketBasicOptionReuseExactAddress,
  365. SocketBasicOptionPassCredentials,
  366. SocketBasicOptionPeerCredentials,
  367. SocketBasicOptionDomain,
  368. SocketBasicOptionLocalAddress,
  369. SocketBasicOptionRemoteAddress,
  370. SocketBasicOptionReuseTimeWait,
  371. } SOCKET_BASIC_OPTION, *PSOCKET_BASIC_OPTION;
  372. /*++
  373. Structure Description:
  374. This structure defines the set of socket linger information. This structure
  375. lines up exactly with the C library linger structure.
  376. Members:
  377. LingerEnabled - Stores a 32-bit boolean indicating whether or not lingering
  378. is enabled on the socket.
  379. LingerTimeout - Stores the amount of time, in seconds, the socket will wait
  380. for data to be sent before forcefully closing.
  381. --*/
  382. typedef struct _SOCKET_LINGER {
  383. ULONG LingerEnabled;
  384. ULONG LingerTimeout;
  385. } SOCKET_LINGER, *PSOCKET_LINGER;
  386. /*++
  387. Structure Description:
  388. This structure defines socket option time information. This structure lines
  389. up exactly with the C library timeval structure.
  390. Members:
  391. Seconds - Stores the number of seconds.
  392. Microseconds - Stores the microseconds.
  393. --*/
  394. typedef struct _SOCKET_TIME {
  395. LONGLONG Seconds;
  396. LONG Microseconds;
  397. } SOCKET_TIME, *PSOCKET_TIME;
  398. /*++
  399. Enumeration Description:
  400. This enumeration describes the various IPv4 options for the IPv4 socket
  401. information class.
  402. Values:
  403. SocketIp4OptionInvalid - Indicates an invalid IPv4 socket option.
  404. SocketIp4OptionHeaderIncluded - Indicates that packets supplied to the send
  405. call for this socket include an IPv4 header. This options takes a
  406. boolean.
  407. SocketIp4OptionJoinMulticastGroup - Indicates a request to join a multicast
  408. group. This option takes a SOCKET_IP4_MULTICAST_REQUEST structure.
  409. SocketIp4OptionLeaveMulticastGroup - Indicates a request to leave a
  410. multicast group. This option takes a SOCKET_MULTICAST_REQUEST structure.
  411. SocketIp4OptionMulticastInterface - Indicates the network interface to use
  412. for multicast messages. This option takes a ULONG.
  413. SocketIp4OptionMulticastTimeToLive - Indicates the time-to-live value for
  414. multicast packets. This option takes a ULONG.
  415. SocketIp4OptionMulticastLoopback - Indicates whether or not multicast
  416. packets should be sent back to sockets on local interfaces. This option
  417. takes a ULONG boolean.
  418. SocketIp4OptionTimeToLive - Indicates the time-to-live value for all
  419. unicast packets sent from the socket. This option takes a ULONG.
  420. --*/
  421. typedef enum _SOCKET_IP4_OPTION {
  422. SocketIp4OptionInvalid,
  423. SocketIp4OptionHeaderIncluded,
  424. SocketIp4OptionJoinMulticastGroup,
  425. SocketIp4OptionLeaveMulticastGroup,
  426. SocketIp4OptionMulticastInterface,
  427. SocketIp4OptionMulticastTimeToLive,
  428. SocketIp4OptionMulticastLoopback,
  429. SocketIp4OptionTimeToLive
  430. } SOCKET_IP4_OPTION, *PSOCKET_IP4_OPTION;
  431. /*++
  432. Structure Description:
  433. This structure defines a socket option IPv4 multicast request to join or
  434. leave a group. This structure lines up exactly with the C library ip_mreq
  435. structure.
  436. Members:
  437. Address - Stores the address of the multicast group to join or leave.
  438. Interface - Stores the index of the network interfaces that is to join or
  439. leave the multicast group.
  440. --*/
  441. typedef struct _SOCKET_IP4_MULTICAST_REQUEST {
  442. ULONG Address;
  443. ULONG Interface;
  444. } SOCKET_IP4_MULTICAST_REQUEST, *PSOCKET_IP4_MULTICAST_REQUEST;
  445. /*++
  446. Enumeration Description:
  447. This enumeration describes the various IPv6 options for the IPv6 socket
  448. information class.
  449. Values:
  450. SocketIp6OptionInvalid - Indicates an invalid IPv6 socket option.
  451. SocketIp6OptionJoinMulticastGroup - Indicates a request to join a multicast
  452. group. This option takes a SOCKET_IP6_MULTICAST_REQUEST structure.
  453. SocketIp6OptionLeaveMulticastGroup - Indicates a request to leave a
  454. multicast group. This option takes a SOCKET_MULTICAST_REQUEST structure.
  455. SocketIp6OptionMulticastHops - Indicates the multicast hop limit for the
  456. socket. This option takes a ULONG.
  457. SocketIp6OptionMulticastInterface - Indicates the network interface to use
  458. for multicast messages. This option takes a ULONG.
  459. SocketIp6OptionMulticastLoopback - Indicates whether or not multicast
  460. packets should be sent back to sockets oo local interfaces. This option
  461. takes a ULONG boolean.
  462. SocketIp6OptionUnicastHops - Indicates the unicast hop limit. This option
  463. takes a ULONG.
  464. SocketIp6OptionIpv6Only - Indicates that the socket can only communicate
  465. via IPv6 packets.
  466. --*/
  467. typedef enum _SOCKET_IP6_OPTION {
  468. SocketIp6OptionInvalid,
  469. SocketIp6OptionJoinMulticastGroup,
  470. SocketIp6OptionLeaveMulticastGroup,
  471. SocketIp6OptionMulticastHops,
  472. SocketIp6OptionMulticastInterface,
  473. SocketIp6OptionMulticastLoopback,
  474. SocketIp6OptionUnicastHops,
  475. SocketIp6OptionIpv6Only
  476. } SOCKET_IP6_OPTION, *PSOCKET_IP6_OPTION;
  477. /*++
  478. Structure Description:
  479. This structure defines a socket option IPv6 multicast request to join or
  480. leave a group. This structure lines up exactly with the C library ip_mreq
  481. structure.
  482. Members:
  483. Address - Stores the address of the multicast group to join or leave.
  484. Interface - Stores the index of the network interfaces that is to join or
  485. leave the multicast group.
  486. --*/
  487. typedef struct _SOCKET_IP6_MULTICAST_REQUEST {
  488. UINTN Address[16 / sizeof(UINTN)];
  489. ULONG Interface;
  490. } SOCKET_IP6_MULTICAST_REQUEST, *PSOCKET_IP6_MULTICAST_REQUEST;
  491. /*++
  492. Enumeration Description:
  493. This enumeration describes the various TCP options for the TCP socket
  494. information class.
  495. Values:
  496. SocketTcpOptionInvalid - Indicates an invalid TCP socket option.
  497. SocketTcpOptionNoDelay - Indicates whether outgoing data is sent
  498. immediately or batched together (the default).
  499. SocketTcpOptionKeepAliveTimeout - Indicates the time, in seconds, until the
  500. first keep alive probe is sent after the TCP connection goes idle. This
  501. option takes an ULONG.
  502. SocketTcpOptionKeepAlivePeriod - Indicates the the time, in seconds,
  503. between keep alive probes. This option takes a ULONG.
  504. SocketTcpOptionKeepAliveProbeLimit - Indicates the number of TCP keep alive
  505. probes to be sent, without response, before the connection is aborted.
  506. This option takes a ULONG.
  507. SocketTcpOptionCount - Indicates the number of TCP socket options.
  508. --*/
  509. typedef enum _SOCKET_TCP_OPTION {
  510. SocketTcpOptionInvalid,
  511. SocketTcpOptionNoDelay,
  512. SocketTcpOptionKeepAliveTimeout,
  513. SocketTcpOptionKeepAlivePeriod,
  514. SocketTcpOptionKeepAliveProbeLimit
  515. } SOCKET_TCP_OPTION, *PSOCKET_TCP_OPTION;
  516. /*++
  517. Structure Description:
  518. This structure defines the common portion of a socket that must be at the
  519. beginning of every socket structure. depending on the type of socket, there
  520. may be more fields in this structure (ie this structure is only the first
  521. member in a larger socket structure).
  522. Members:
  523. Domain - Stores the network domain of this socket.
  524. Type - Stores the socket type.
  525. Protocol - Stores the raw protocol value of this socket that is used
  526. on the network.
  527. ReferenceCount - Stores the reference count on the socket.
  528. IoState - Stores a pointer to the I/O object state for this socket. If the
  529. networking driver allocates this on socket creation, the kernel will
  530. take ownership of the structure upon return from create. The driver
  531. should never destroy it.
  532. IoHandle - Stores a pointer to the I/O handle that goes along with this
  533. socket.
  534. Flags - Stores a bitmaks of socket flags. See SOCKET_FLAG_* for definitions.
  535. --*/
  536. typedef struct _SOCKET {
  537. NET_DOMAIN_TYPE Domain;
  538. NET_SOCKET_TYPE Type;
  539. ULONG Protocol;
  540. UINTN ReferenceCount;
  541. PIO_OBJECT_STATE IoState;
  542. PIO_HANDLE IoHandle;
  543. ULONG Flags;
  544. } SOCKET, *PSOCKET;
  545. /*++
  546. Structure Description:
  547. This structure defines parameters associated with a socket I/O request.
  548. Members:
  549. Size - Stores the size in bytes of the I/O request.
  550. BytesCompleted - Stores the number of bytes of I/O that were actually
  551. completed.
  552. IoFlags - Stores the standard I/O flags. See IO_FLAG_* definitions for
  553. kernel mode or SYS_IO_FLAG_* definitions for user mode.
  554. SocketIoFlags - Stores a set of socket-specific I/O flags. See SOCKET_IO_*
  555. definitions. On return, these may be updated.
  556. TimeoutInMilliseconds - Stores the timeout in milliseconds before the
  557. operation returns with what it has.
  558. NetworkAddress - Stores an optional pointer to a remote network address.
  559. RemotePath - Stores an optional pointer to a socket file path for local
  560. sockets.
  561. RemotePathSize - Stores the size of the remote path buffer in bytes. On
  562. return, will contain the actual size of the remote path, including
  563. the null terminator.
  564. ControlData - Stores an optional pointer to the ancillary data associated
  565. with this request.
  566. ControlDataSize - Stores the size of the control data buffer in bytes. On
  567. return, returns the actual size of the control data.
  568. --*/
  569. typedef struct _SOCKET_IO_PARAMETERS {
  570. UINTN Size;
  571. UINTN BytesCompleted;
  572. ULONG IoFlags;
  573. ULONG SocketIoFlags;
  574. ULONG TimeoutInMilliseconds;
  575. PNETWORK_ADDRESS NetworkAddress;
  576. PSTR RemotePath;
  577. UINTN RemotePathSize;
  578. PVOID ControlData;
  579. UINTN ControlDataSize;
  580. } SOCKET_IO_PARAMETERS, *PSOCKET_IO_PARAMETERS;
  581. /*++
  582. Structure Description:
  583. This structure defines a socket control message, the header for the socket
  584. ancillary data. This structure lines up exactly with the C library cmsghdr
  585. structure.
  586. Members:
  587. Length - Stores the length of the data for this message, including this
  588. structure.
  589. Protocol- Stores the originating protocol of the control message.
  590. Type - Stores the control message type.
  591. --*/
  592. typedef struct SOCKET_CONTROL_MESSAGE {
  593. UINTN Length;
  594. ULONG Protocol;
  595. ULONG Type;
  596. } SOCKET_CONTROL_MESSAGE, *PSOCKET_CONTROL_MESSAGE;
  597. typedef
  598. KSTATUS
  599. (*PNET_CREATE_SOCKET) (
  600. NET_DOMAIN_TYPE Domain,
  601. NET_SOCKET_TYPE Type,
  602. ULONG Protocol,
  603. PSOCKET *NewSocket
  604. );
  605. /*++
  606. Routine Description:
  607. This routine allocates resources associated with a new socket. The core
  608. networking driver is responsible for allocating the structure (with
  609. additional length for any of its context). The kernel will fill in the
  610. common header when this routine returns.
  611. Arguments:
  612. Domain - Supplies the network domain to use on the socket.
  613. Type - Supplies the socket connection type.
  614. Protocol - Supplies the raw protocol value for this socket used on the
  615. network. This value is network specific.
  616. NewSocket - Supplies a pointer where a pointer to a newly allocated
  617. socket structure will be returned. The caller is responsible for
  618. allocating the socket (and potentially a larger structure for its own
  619. context). The kernel will fill in the standard socket structure after
  620. this routine returns.
  621. Return Value:
  622. Status code.
  623. --*/
  624. typedef
  625. VOID
  626. (*PNET_DESTROY_SOCKET) (
  627. PSOCKET Socket
  628. );
  629. /*++
  630. Routine Description:
  631. This routine destroys resources associated with an open socket, officially
  632. marking the end of the kernel's knowledge of this structure.
  633. Arguments:
  634. Socket - Supplies a pointer to the socket to destroy. The kernel will have
  635. already destroyed any resources inside the common header, the core
  636. networking library should not reach through any pointers inside the
  637. socket header.
  638. Return Value:
  639. None. This routine is responsible for freeing the memory associated with
  640. the socket structure itself.
  641. --*/
  642. typedef
  643. KSTATUS
  644. (*PNET_BIND_TO_ADDRESS) (
  645. PSOCKET Socket,
  646. PVOID Link,
  647. PNETWORK_ADDRESS Address
  648. );
  649. /*++
  650. Routine Description:
  651. This routine binds the given socket to the specified network address.
  652. Arguments:
  653. Socket - Supplies a pointer to the socket to bind.
  654. Link - Supplies an optional pointer to a link to bind to.
  655. Address - Supplies a pointer to the address to bind the socket to.
  656. Return Value:
  657. Status code.
  658. --*/
  659. typedef
  660. KSTATUS
  661. (*PNET_LISTEN) (
  662. PSOCKET Socket,
  663. ULONG BacklogCount
  664. );
  665. /*++
  666. Routine Description:
  667. This routine adds a bound socket to the list of listening sockets,
  668. officially allowing sockets to attempt to connect to it.
  669. Arguments:
  670. Socket - Supplies a pointer to the socket to mark as listening.
  671. BacklogCount - Supplies the number of attempted connections that can be
  672. queued before additional connections are refused.
  673. Return Value:
  674. Status code.
  675. --*/
  676. typedef
  677. KSTATUS
  678. (*PNET_ACCEPT) (
  679. PSOCKET Socket,
  680. PIO_HANDLE *NewConnectionSocket,
  681. PNETWORK_ADDRESS RemoteAddress
  682. );
  683. /*++
  684. Routine Description:
  685. This routine accepts an incoming connection on a listening connection-based
  686. socket.
  687. Arguments:
  688. Socket - Supplies a pointer to the socket to accept a connection from.
  689. NewConnectionSocket - Supplies a pointer where a new socket will be
  690. returned that represents the accepted connection with the remote
  691. host.
  692. RemoteAddress - Supplies a pointer where the address of the connected
  693. remote host will be returned.
  694. Return Value:
  695. Status code.
  696. --*/
  697. typedef
  698. KSTATUS
  699. (*PNET_CONNECT) (
  700. PSOCKET Socket,
  701. PNETWORK_ADDRESS Address
  702. );
  703. /*++
  704. Routine Description:
  705. This routine attempts to make an outgoing connection to a server.
  706. Arguments:
  707. Socket - Supplies a pointer to the socket to use for the connection.
  708. Address - Supplies a pointer to the address to connect to.
  709. Return Value:
  710. Status code.
  711. --*/
  712. typedef
  713. KSTATUS
  714. (*PNET_CLOSE_SOCKET) (
  715. PSOCKET Socket
  716. );
  717. /*++
  718. Routine Description:
  719. This routine closes a socket connection.
  720. Arguments:
  721. Socket - Supplies a pointer to the socket to shut down.
  722. Return Value:
  723. Status code.
  724. --*/
  725. typedef
  726. KSTATUS
  727. (*PNET_SEND_DATA) (
  728. BOOL FromKernelMode,
  729. PSOCKET Socket,
  730. PSOCKET_IO_PARAMETERS Parameters,
  731. PIO_BUFFER IoBuffer
  732. );
  733. /*++
  734. Routine Description:
  735. This routine sends the given data buffer through the network.
  736. Arguments:
  737. FromKernelMode - Supplies a boolean indicating whether the request is
  738. coming from kernel mode (TRUE) or user mode (FALSE).
  739. Socket - Supplies a pointer to the socket to send the data to.
  740. Parameters - Supplies a pointer to the socket I/O parameters. This will
  741. always be a kernel mode pointer.
  742. IoBuffer - Supplies a pointer to the I/O buffer containing the data to
  743. send.
  744. Return Value:
  745. Status code.
  746. --*/
  747. typedef
  748. KSTATUS
  749. (*PNET_RECEIVE_DATA) (
  750. BOOL FromKernelMode,
  751. PSOCKET Socket,
  752. PSOCKET_IO_PARAMETERS Parameters,
  753. PIO_BUFFER IoBuffer
  754. );
  755. /*++
  756. Routine Description:
  757. This routine is called by the user to receive data from the socket.
  758. Arguments:
  759. FromKernelMode - Supplies a boolean indicating whether the request is
  760. coming from kernel mode (TRUE) or user mode (FALSE).
  761. Socket - Supplies a pointer to the socket to receive data from.
  762. Parameters - Supplies a pointer to the socket I/O parameters.
  763. IoBuffer - Supplies a pointer to the I/O buffer where the received data
  764. will be returned.
  765. Return Value:
  766. STATUS_SUCCESS if any bytes were read.
  767. STATUS_TIMEOUT if the request timed out.
  768. STATUS_BUFFER_TOO_SMALL if the incoming datagram was too large for the
  769. buffer. The remainder of the datagram is discarded in this case.
  770. Other error codes on other failures.
  771. --*/
  772. typedef
  773. KSTATUS
  774. (*PNET_GET_SET_SOCKET_INFORMATION) (
  775. PSOCKET Socket,
  776. SOCKET_INFORMATION_TYPE InformationType,
  777. UINTN Option,
  778. PVOID Data,
  779. PUINTN DataSize,
  780. BOOL Set
  781. );
  782. /*++
  783. Routine Description:
  784. This routine gets or sets properties of the given socket.
  785. Arguments:
  786. Socket - Supplies a pointer to the socket to get or set information for.
  787. InformationType - Supplies the socket information type category to which
  788. specified option belongs.
  789. Option - Supplies the option to get or set, which is specific to the
  790. information type. The type of this value is generally
  791. SOCKET_<information_type>_OPTION.
  792. Data - Supplies a pointer to the data buffer where the data is either
  793. returned for a get operation or given for a set operation.
  794. DataSize - Supplies a pointer that on input constains the size of the data
  795. buffer. On output, this contains the required size of the data buffer.
  796. Set - Supplies a boolean indicating if this is a get operation (FALSE) or
  797. a set operation (TRUE).
  798. Return Value:
  799. STATUS_SUCCESS on success.
  800. STATUS_INVALID_PARAMETER if the information type is incorrect.
  801. STATUS_BUFFER_TOO_SMALL if the data buffer is too small to receive the
  802. requested option.
  803. STATUS_NOT_SUPPORTED_BY_PROTOCOL if the socket option is not supported by
  804. the socket.
  805. --*/
  806. typedef
  807. KSTATUS
  808. (*PNET_SHUTDOWN) (
  809. PSOCKET Socket,
  810. ULONG ShutdownType
  811. );
  812. /*++
  813. Routine Description:
  814. This routine shuts down communication with a given socket.
  815. Arguments:
  816. Socket - Supplies a pointer to the socket.
  817. ShutdownType - Supplies the shutdown type to perform. See the
  818. SOCKET_SHUTDOWN_* definitions.
  819. Return Value:
  820. Status code.
  821. --*/
  822. typedef
  823. KSTATUS
  824. (*PNET_USER_CONTROL) (
  825. PSOCKET Socket,
  826. ULONG CodeNumber,
  827. BOOL FromKernelMode,
  828. PVOID ContextBuffer,
  829. UINTN ContextBufferSize
  830. );
  831. /*++
  832. Routine Description:
  833. This routine handles user control requests destined for a socket.
  834. Arguments:
  835. Socket - Supplies a pointer to the socket.
  836. CodeNumber - Supplies the minor code of the request.
  837. FromKernelMode - Supplies a boolean indicating whether or not this request
  838. (and the buffer associated with it) originates from user mode (FALSE)
  839. or kernel mode (TRUE).
  840. ContextBuffer - Supplies a pointer to the context buffer allocated by the
  841. caller for the request.
  842. ContextBufferSize - Supplies the size of the supplied context buffer.
  843. Return Value:
  844. Status code.
  845. --*/
  846. /*++
  847. Structure Description:
  848. This structure defines interface between the kernel and the core networking
  849. library. More specifically, it defines the set of functions that the
  850. kernel will call when it needs networking support.
  851. Members:
  852. CreateSocket - Stores a pointer to a function that creates a new socket.
  853. DestroySocket - Stores a pointer to a function that destroys all resources
  854. associated with a socket.
  855. BindToAddress - Stores a pointer to a function that binds a network
  856. address to the socket.
  857. Listen - Stores a pointer to a function that starts a bound socket listening
  858. for incoming connections.
  859. Accept - Stores a pointer to a function that accepts an incoming connection
  860. request from a remote host.
  861. Connect - Stores a pointer to a function that attempts to create an
  862. outgoing connection.
  863. CloseSocket - Stores a pointer to a function that closes a socket and
  864. destroys all resources associated with it.
  865. Send - Stores a pointer to a function used to send data into a socket.
  866. Receive - Stores a pointer to a function used to receive data from a socket.
  867. GetSetInformation - Stores a pointer to a function used to get or set
  868. socket information.
  869. Shutdown - Stores a pointer to a function used to shut down communication
  870. with a socket.
  871. UserControl - Stores a pointer to a function used to support ioctls to
  872. sockets.
  873. --*/
  874. typedef struct _NET_INTERFACE {
  875. PNET_CREATE_SOCKET CreateSocket;
  876. PNET_DESTROY_SOCKET DestroySocket;
  877. PNET_BIND_TO_ADDRESS BindToAddress;
  878. PNET_LISTEN Listen;
  879. PNET_ACCEPT Accept;
  880. PNET_CONNECT Connect;
  881. PNET_CLOSE_SOCKET CloseSocket;
  882. PNET_SEND_DATA Send;
  883. PNET_RECEIVE_DATA Receive;
  884. PNET_GET_SET_SOCKET_INFORMATION GetSetSocketInformation;
  885. PNET_SHUTDOWN Shutdown;
  886. PNET_USER_CONTROL UserControl;
  887. } NET_INTERFACE, *PNET_INTERFACE;
  888. //
  889. // -------------------------------------------------------------------- Globals
  890. //
  891. //
  892. // -------------------------------------------------------- Function Prototypes
  893. //
  894. KERNEL_API
  895. VOID
  896. IoInitializeCoreNetworking (
  897. PNET_INTERFACE Interface
  898. );
  899. /*++
  900. Routine Description:
  901. This routine initializes the interface between the kernel and the core
  902. networking library. This routine should not be called by random drivers.
  903. Arguments:
  904. Interface - Supplies a pointer to the core networking library interface.
  905. Return Value:
  906. None.
  907. --*/
  908. KERNEL_API
  909. ULONG
  910. IoSocketAddReference (
  911. PSOCKET Socket
  912. );
  913. /*++
  914. Routine Description:
  915. This routine increases the reference count on a socket.
  916. Arguments:
  917. Socket - Supplies a pointer to the socket whose reference count should be
  918. incremented.
  919. Return Value:
  920. Returns the old reference count.
  921. --*/
  922. KERNEL_API
  923. ULONG
  924. IoSocketReleaseReference (
  925. PSOCKET Socket
  926. );
  927. /*++
  928. Routine Description:
  929. This routine decreases the reference count of a socket, and destroys the
  930. socket if in this call the reference count drops to zero.
  931. Arguments:
  932. Socket - Supplies a pointer to the socket whose reference count should be
  933. decremented.
  934. Return Value:
  935. Returns the old reference count.
  936. --*/
  937. KERNEL_API
  938. KSTATUS
  939. IoSocketCreatePair (
  940. NET_DOMAIN_TYPE Domain,
  941. NET_SOCKET_TYPE Type,
  942. ULONG Protocol,
  943. ULONG OpenFlags,
  944. PIO_HANDLE IoHandles[2]
  945. );
  946. /*++
  947. Routine Description:
  948. This routine creates a pair of sockets that are connected to each other.
  949. Arguments:
  950. Domain - Supplies the network domain to use on the socket.
  951. Type - Supplies the socket connection type.
  952. Protocol - Supplies the raw protocol value used on the network.
  953. OpenFlags - Supplies a bitfield of open flags governing the new handles.
  954. See OPEN_FLAG_* definitions.
  955. IoHandles - Supplies an array where the two I/O handles to the connected
  956. sockets will be returned on success.
  957. Return Value:
  958. Status code.
  959. --*/
  960. KERNEL_API
  961. KSTATUS
  962. IoSocketCreate (
  963. NET_DOMAIN_TYPE Domain,
  964. NET_SOCKET_TYPE Type,
  965. ULONG Protocol,
  966. ULONG OpenFlags,
  967. PIO_HANDLE *IoHandle
  968. );
  969. /*++
  970. Routine Description:
  971. This routine allocates resources associated with a new socket.
  972. Arguments:
  973. Domain - Supplies the network domain to use on the socket.
  974. Type - Supplies the socket connection type.
  975. Protocol - Supplies the raw protocol value used on the network.
  976. OpenFlags - Supplies the open flags for the socket. See OPEN_FLAG_*
  977. definitions.
  978. IoHandle - Supplies a pointer where a pointer to the new socket's I/O
  979. handle will be returned.
  980. Return Value:
  981. Status code.
  982. --*/
  983. KERNEL_API
  984. KSTATUS
  985. IoSocketBindToAddress (
  986. BOOL FromKernelMode,
  987. PIO_HANDLE Handle,
  988. PVOID Link,
  989. PNETWORK_ADDRESS Address,
  990. PSTR Path,
  991. UINTN PathSize
  992. );
  993. /*++
  994. Routine Description:
  995. This routine binds the socket to the given address and starts listening for
  996. client requests.
  997. Arguments:
  998. FromKernelMode - Supplies a boolean indicating if the request is coming
  999. from kernel mode or user mode. This value affects the root path node
  1000. to traverse for local domain sockets.
  1001. Handle - Supplies a pointer to the socket handle to bind.
  1002. Link - Supplies an optional pointer to a link to bind to.
  1003. Address - Supplies a pointer to the address to bind the socket to.
  1004. Path - Supplies an optional pointer to a path, required if the network
  1005. address is a local socket.
  1006. PathSize - Supplies the size of the path in bytes including the null
  1007. terminator.
  1008. Return Value:
  1009. Status code.
  1010. --*/
  1011. KERNEL_API
  1012. KSTATUS
  1013. IoSocketListen (
  1014. PIO_HANDLE Handle,
  1015. ULONG BacklogCount
  1016. );
  1017. /*++
  1018. Routine Description:
  1019. This routine adds a bound socket to the list of listening sockets,
  1020. officially allowing sockets to attempt to connect to it.
  1021. Arguments:
  1022. Handle - Supplies a pointer to the socket to mark as listening.
  1023. BacklogCount - Supplies the number of attempted connections that can be
  1024. queued before additional connections are refused.
  1025. Return Value:
  1026. Status code.
  1027. --*/
  1028. KERNEL_API
  1029. KSTATUS
  1030. IoSocketAccept (
  1031. PIO_HANDLE Handle,
  1032. PIO_HANDLE *NewConnectionSocket,
  1033. PNETWORK_ADDRESS RemoteAddress,
  1034. PSTR *RemotePath,
  1035. PUINTN RemotePathSize
  1036. );
  1037. /*++
  1038. Routine Description:
  1039. This routine accepts an incoming connection on a listening connection-based
  1040. socket.
  1041. Arguments:
  1042. Handle - Supplies a pointer to the socket to accept a connection from.
  1043. NewConnectionSocket - Supplies a pointer where a new socket will be
  1044. returned that represents the accepted connection with the remote
  1045. host.
  1046. RemoteAddress - Supplies a pointer where the address of the connected
  1047. remote host will be returned.
  1048. RemotePath - Supplies a pointer where a string containing the remote path
  1049. will be returned on success. The caller does not own this string, it is
  1050. connected with the new socket coming out. This only applies to local
  1051. sockets.
  1052. RemotePathSize - Supplies a pointer where the size of the remote path in
  1053. bytes will be returned on success.
  1054. Return Value:
  1055. Status code.
  1056. --*/
  1057. KERNEL_API
  1058. KSTATUS
  1059. IoSocketConnect (
  1060. BOOL FromKernelMode,
  1061. PIO_HANDLE Handle,
  1062. PNETWORK_ADDRESS Address,
  1063. PSTR RemotePath,
  1064. UINTN RemotePathSize
  1065. );
  1066. /*++
  1067. Routine Description:
  1068. This routine attempts to make an outgoing connection to a server.
  1069. Arguments:
  1070. FromKernelMode - Supplies a boolean indicating if the request is coming
  1071. from kernel mode or user mode.
  1072. Handle - Supplies a pointer to the socket to use for the connection.
  1073. Address - Supplies a pointer to the address to connect to.
  1074. RemotePath - Supplies a pointer to the path to connect to, if this is a
  1075. local socket.
  1076. RemotePathSize - Supplies the size of the remote path buffer in bytes,
  1077. including the null terminator.
  1078. Return Value:
  1079. Status code.
  1080. --*/
  1081. KERNEL_API
  1082. KSTATUS
  1083. IoSocketSendData (
  1084. BOOL FromKernelMode,
  1085. PIO_HANDLE Handle,
  1086. PSOCKET_IO_PARAMETERS Parameters,
  1087. PIO_BUFFER IoBuffer
  1088. );
  1089. /*++
  1090. Routine Description:
  1091. This routine sends the given data buffer through the network.
  1092. Arguments:
  1093. FromKernelMode - Supplies a boolean indicating if the request is coming
  1094. from kernel mode or user mode. This value affects the root path node
  1095. to traverse for local domain sockets.
  1096. Handle - Supplies a pointer to the socket to send the data to.
  1097. Parameters - Supplies a pointer to the socket I/O parameters.
  1098. IoBuffer - Supplies a pointer to the I/O buffer containing the data to
  1099. send.
  1100. Return Value:
  1101. Status code.
  1102. --*/
  1103. KERNEL_API
  1104. KSTATUS
  1105. IoSocketReceiveData (
  1106. BOOL FromKernelMode,
  1107. PIO_HANDLE Handle,
  1108. PSOCKET_IO_PARAMETERS Parameters,
  1109. PIO_BUFFER IoBuffer
  1110. );
  1111. /*++
  1112. Routine Description:
  1113. This routine is called by the user to receive data from the socket.
  1114. Arguments:
  1115. FromKernelMode - Supplies a boolean indicating if the request is coming
  1116. from kernel mode or user mode. This value affects the root path node
  1117. to traverse for local domain sockets.
  1118. Handle - Supplies a pointer to the socket to receive data from.
  1119. Parameters - Supplies a pointer to the socket I/O parameters.
  1120. IoBuffer - Supplies a pointer to the I/O buffer where the received data
  1121. will be returned.
  1122. Return Value:
  1123. STATUS_SUCCESS if any bytes were read.
  1124. STATUS_TIMEOUT if the request timed out.
  1125. STATUS_BUFFER_TOO_SMALL if the incoming datagram was too large for the
  1126. buffer. The remainder of the datagram is discarded in this case.
  1127. Other error codes on other failures.
  1128. --*/
  1129. KERNEL_API
  1130. KSTATUS
  1131. IoSocketGetSetInformation (
  1132. PIO_HANDLE IoHandle,
  1133. SOCKET_INFORMATION_TYPE InformationType,
  1134. UINTN SocketOption,
  1135. PVOID Data,
  1136. PUINTN DataSize,
  1137. BOOL Set
  1138. );
  1139. /*++
  1140. Routine Description:
  1141. This routine gets or sets information about the given socket.
  1142. Arguments:
  1143. IoHandle - Supplies a pointer to the I/O handle of the socket.
  1144. InformationType - Supplies the socket information type category to which
  1145. specified option belongs.
  1146. SocketOption - Supplies the option to get or set, which is specific to the
  1147. information type. The type of this value is generally
  1148. SOCKET_<information_type>_OPTION.
  1149. Data - Supplies a pointer to the data buffer where the data is either
  1150. returned for a get operation or given for a set operation.
  1151. DataSize - Supplies a pointer that on input constains the size of the data
  1152. buffer. On output, this contains the required size of the data buffer.
  1153. Set - Supplies a boolean indicating if this is a get operation (FALSE) or
  1154. a set operation (TRUE).
  1155. Return Value:
  1156. STATUS_SUCCESS on success.
  1157. STATUS_INVALID_PARAMETER if the data is not appropriate for the socket
  1158. option.
  1159. STATUS_BUFFER_TOO_SMALL if the socket option information does not fit in
  1160. the supplied buffer.
  1161. STATUS_NOT_SUPPORTED_BY_PROTOCOL if the socket option or information type
  1162. is not supported by the socket.
  1163. STATUS_NOT_A_SOCKET if the given handle wasn't a socket.
  1164. --*/
  1165. KERNEL_API
  1166. KSTATUS
  1167. IoSocketShutdown (
  1168. PIO_HANDLE IoHandle,
  1169. ULONG ShutdownType
  1170. );
  1171. /*++
  1172. Routine Description:
  1173. This routine shuts down communication with a given socket.
  1174. Arguments:
  1175. IoHandle - Supplies a pointer to the I/O handle of the socket.
  1176. ShutdownType - Supplies the shutdown type to perform. See the
  1177. SOCKET_SHUTDOWN_* definitions.
  1178. Return Value:
  1179. STATUS_SUCCESS on success.
  1180. STATUS_NOT_A_SOCKET if the given handle wasn't a socket.
  1181. Other error codes on failure.
  1182. --*/
  1183. KERNEL_API
  1184. KSTATUS
  1185. IoSocketUserControl (
  1186. PIO_HANDLE Handle,
  1187. ULONG CodeNumber,
  1188. BOOL FromKernelMode,
  1189. PVOID ContextBuffer,
  1190. UINTN ContextBufferSize
  1191. );
  1192. /*++
  1193. Routine Description:
  1194. This routine handles user control requests destined for a socket.
  1195. Arguments:
  1196. Handle - Supplies the open file handle.
  1197. CodeNumber - Supplies the minor code of the request.
  1198. FromKernelMode - Supplies a boolean indicating whether or not this request
  1199. (and the buffer associated with it) originates from user mode (FALSE)
  1200. or kernel mode (TRUE).
  1201. ContextBuffer - Supplies a pointer to the context buffer allocated by the
  1202. caller for the request.
  1203. ContextBufferSize - Supplies the size of the supplied context buffer.
  1204. Return Value:
  1205. Status code.
  1206. --*/
  1207. KERNEL_API
  1208. KSTATUS
  1209. IoGetSocketFromHandle (
  1210. PIO_HANDLE IoHandle,
  1211. PSOCKET *Socket
  1212. );
  1213. /*++
  1214. Routine Description:
  1215. This routine returns the socket structure from inside an I/O handle. This
  1216. routine is usually only used by networking protocol to get their own
  1217. structures for the socket they create in the "accept" function.
  1218. Arguments:
  1219. IoHandle - Supplies a pointer to the I/O handle whose corresponding socket
  1220. is desired.
  1221. Socket - Supplies a pointer where a pointer to the socket corresponding to
  1222. the given handle will be returned on success.
  1223. Return Value:
  1224. STATUS_SUCCESS on success.
  1225. STATUS_INVALID_HANDLE if the given handle wasn't a socket.
  1226. --*/