knet.h 47 KB

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