knet.h 46 KB

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