PageRenderTime 25ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/apps/libc/include/sys/socket.h

https://gitlab.com/vascocosta/os
C Header | 1330 lines | 252 code | 171 blank | 907 comment | 0 complexity | f3c974d659cbb80f562100f75fbfe48b MD5 | raw file
  1. /*++
  2. Copyright (c) 2013 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. socket.h
  9. Abstract:
  10. This header contains definitions for socket-based communication endpoints.
  11. Author:
  12. Evan Green 3-May-2013
  13. --*/
  14. #ifndef _SOCKET_H
  15. #define _SOCKET_H
  16. //
  17. // ------------------------------------------------------------------- Includes
  18. //
  19. #include <sys/uio.h>
  20. //
  21. // --------------------------------------------------------------------- Macros
  22. //
  23. //
  24. // This macro evaluates to a pointer to the ancillary data following a cmsghdr
  25. // structure.
  26. //
  27. #define CMSG_DATA(_Control) \
  28. ((unsigned char *)((struct cmsghdr *)(_Control) + 1))
  29. //
  30. // This macro advances a cmsghdr pointer to the next cmsghdr, or assigns it to
  31. // NULL if it is the last one. The first parameter is a pointer to the original
  32. // msghdr.
  33. //
  34. #define CMSG_NXTHDR(_Message, _Control) __cmsg_nxthdr((_Message), (_Control))
  35. //
  36. // This macro evaluates to the first cmsghdr given a msghdr structure, or
  37. // NULL if there is no data.
  38. //
  39. #define CMSG_FIRSTHDR(_Message) \
  40. (((_Message)->msg_controllen >= sizeof(struct cmsghdr)) ? \
  41. (struct cmsghdr *)(_Message)->msg_control : \
  42. NULL)
  43. //
  44. // This macro returns the required alignment for a given length. This is a
  45. // constant expression.
  46. //
  47. #define CMSG_ALIGN(_Length) \
  48. (((_Length) + sizeof(size_t) - 1) & (size_t)~(sizeof(size_t) - 1))
  49. //
  50. // This macro returns the number of bytes an ancillary element with the given
  51. // payload size takes up. This is a constant expression.
  52. //
  53. #define CMSG_SPACE(_Length) \
  54. (CMSG_ALIGN(_Length) + CMSG_ALIGN(sizeof(struct cmsghdr)))
  55. //
  56. // This macro returns the value to store in the cmsghdr length member, taking
  57. // into account any necessary alignment. It takes the data length as an
  58. // argument. This is a constant expression.
  59. //
  60. #define CMSG_LEN(_Length) \
  61. (CMSG_ALIGN(sizeof(struct cmsghdr)) + (_Length))
  62. //
  63. // ---------------------------------------------------------------- Definitions
  64. //
  65. #ifdef __cplusplus
  66. extern "C" {
  67. #endif
  68. //
  69. // Define the valid address families.
  70. //
  71. #define AF_UNSPEC 0
  72. #define AF_UNIX 1
  73. #define AF_LOCAL AF_UNIX
  74. #define AF_INET 2
  75. #define AF_INET6 3
  76. //
  77. // Define valid protocol families as the same as the address families.
  78. //
  79. #define PF_UNSPEC AF_UNSPEC
  80. #define PF_UNIX AF_UNIX
  81. #define PF_LOCAL AF_LOCAL
  82. #define PF_INET AF_INET
  83. #define PF_INET6 AF_INET6
  84. //
  85. // Define the socket types.
  86. //
  87. //
  88. // Datagram sockets provide connectionless unreliable packets of a fixed
  89. // maximum length.
  90. //
  91. #define SOCK_DGRAM 1
  92. //
  93. // Raw sockets snoop all traffic.
  94. //
  95. #define SOCK_RAW 2
  96. //
  97. // Sequenced packet sockets provide reliable bidirectional connection-based
  98. // tranmission paths for records.
  99. //
  100. #define SOCK_SEQPACKET 3
  101. //
  102. // Streams provide reliable bidirectional connection-mode byte streams, and may
  103. // provide a transmission mechanism for out of band data.
  104. //
  105. #define SOCK_STREAM 4
  106. //
  107. // Define flags to the accept4 function.
  108. //
  109. //
  110. // Set this flag to request that the new descriptor be created with the
  111. // non-blocking flag set.
  112. //
  113. #define SOCK_NONBLOCK 0x00001000
  114. //
  115. // Set this flag to request that the new descriptor be created with the
  116. // close-on-execute flag set.
  117. //
  118. #define SOCK_CLOEXEC 0x00004000
  119. //
  120. // Define flags that can be passed to the send and recv functions.
  121. //
  122. //
  123. // Peeks at an incoming message without officially receiving it. The data is
  124. // treated as unread and the next recv or similar function call still returns
  125. // the same data.
  126. //
  127. #define MSG_PEEK 0x00000001
  128. //
  129. // Requests out-of-band data. The significance and semantics of out-of-band
  130. // data are protocol-specific. This flag is also returned by the kernel when
  131. // out-of-band data is received.
  132. //
  133. #define MSG_OOB 0x00000002
  134. //
  135. // On SOCK_STREAM sockets this requests that the function block until the full
  136. // amount of data can be returned. The function may return the smaller amount
  137. // of data if the socket is a message-based socket, if a signal is caught, if
  138. // the connection is terminated, is MSG_PEEK was specified, or if an error is
  139. // pending for the socket.
  140. //
  141. #define MSG_WAITALL 0x00000004
  142. //
  143. // This flag indicates a complete message, used by sequential packet sockets.
  144. // This flag can be set by user-mode on transmit and kernel-mode on receive.
  145. //
  146. #define MSG_EOR 0x00000008
  147. //
  148. // This flag is returned by the kernel when the trailing portion of the
  149. // datagram was discarded because the datagram was larger than the buffer
  150. // supplied.
  151. //
  152. #define MSG_TRUNC 0x00000010
  153. //
  154. // This flag is returned by the kernel when some control/ancillary data is
  155. // discarded due to lack of space in the provided ancillary buffer.
  156. //
  157. #define MSG_CTRUNC 0x00000020
  158. //
  159. // This flag requests not to send a broken pipe signal on stream oriented
  160. // sockets when the other end breaks the connection. The broken pipe status
  161. // is still returned.
  162. //
  163. #define MSG_NOSIGNAL 0x00000040
  164. //
  165. // This flag requests that the operation not block.
  166. //
  167. #define MSG_DONTWAIT 0x00000080
  168. //
  169. // This flag requests that routing tables not be used when sending a packet.
  170. // This limits the system to sending the packet across networks that are
  171. // directly connected.
  172. //
  173. #define MSG_DONTROUTE 0x00000100
  174. //
  175. // Define the shutdown types. Read closes the socket for further reading, write
  176. // closes the socket for further writing, and rdwr closes the socket for both
  177. // reading and writing.
  178. //
  179. #define SHUT_RD 0
  180. #define SHUT_WR 1
  181. #define SHUT_RDWR 2
  182. //
  183. // Define socket level control message types, currently only used by local
  184. // sockets.
  185. //
  186. //
  187. // This control message type allows the passing of file descriptors.
  188. //
  189. #define SCM_RIGHTS 1
  190. //
  191. // This control message type allows the passing of credentials.
  192. //
  193. #define SCM_CREDENTIALS 2
  194. //
  195. // Define socket options.
  196. //
  197. //
  198. // This options reports whether or not socket listening is enabled. The option
  199. // value is an int boolean and is read only.
  200. //
  201. #define SO_ACCEPTCONN 1
  202. //
  203. // This option permits the sending of broadcast messages, if supported by the
  204. // protocol. The option value is an int boolean.
  205. //
  206. #define SO_BROADCAST 2
  207. //
  208. // This option turns on recording of debugging information in the protocol. The
  209. // option value is an int boolean.
  210. //
  211. #define SO_DEBUG 3
  212. //
  213. // This option requests that outgoing messages bypass the standard routing
  214. // facilities. The destination shall assumed to be directly connected, and
  215. // messages are directed to the appropriate network interface based on the
  216. // destination address. The affect, if any, depends on what protocl is in use.
  217. // This option takes an int boolean value.
  218. //
  219. #define SO_DONTROUTE 4
  220. //
  221. // This option reports information about the error status and clears it. The
  222. // option value is an int.
  223. //
  224. #define SO_ERROR 5
  225. //
  226. // This option keeps connections active by enabling the periodic transmission
  227. // of messages, if supported by the protocol. This option takes an int boolean.
  228. // If the connected socket fails to respond to these messages, the connection
  229. // is broken and threads writing to the socket are notified with a SIGPIPE
  230. // signal.
  231. //
  232. #define SO_KEEPALIVE 6
  233. //
  234. // This option lingers on a close function if data is present. This option
  235. // controls the action taken when unsent messages queue on a socket and close
  236. // is performed. If this option is set, the system blocks the calling thread
  237. // during close until it can transmit the data or until the time expires. If
  238. // this option is not set and close is called, the system handles the call in
  239. // a way that allows the calling thread to continue as quickly as possible. The
  240. // option takes a linger structure to specify the state of the option and
  241. // linger interval.
  242. //
  243. #define SO_LINGER 7
  244. //
  245. // This option leaves out-of-band data (data marked urgent) inline. The option
  246. // value is an integer boolean.
  247. //
  248. #define SO_OOBINLINE 8
  249. //
  250. // This option sets the receive buffer size. It taks an int value.
  251. //
  252. #define SO_RCVBUF 9
  253. //
  254. // This option sets the minimum number of bytes to process for socket input
  255. // operations. The default value is 1 byte. If this is set to a larger value,
  256. // blocking receive calls normally wait until they have received the smaller of
  257. // the low water mark or the requested amount. They may return less than the
  258. // low water mark if an error or signal occurs. This option takes an int value.
  259. //
  260. #define SO_RCVLOWAT 10
  261. //
  262. // This option sets the maximum amount of time an input function waits until it
  263. // completes. The value is a timeval structure specifying how long to wait
  264. // before returning with whatever data was collected, if any. The default value
  265. // is zero, meaning the receive operation does not time out.
  266. //
  267. #define SO_RCVTIMEO 11
  268. //
  269. // This option sets the send buffer size. It takes an int value.
  270. //
  271. #define SO_SNDBUF 12
  272. //
  273. // This option sets the minimum number of bytes to process for socket output
  274. // operations. Non-blocking output operations shall process no data if flow
  275. // control does not allow the smaller of the send low water mark value or the
  276. // entire request to be processed. This option takes an int value.
  277. //
  278. #define SO_SNDLOWAT 13
  279. //
  280. // This option sets maximum amount of time an output function would block
  281. // because flow control is preventing data from being sent. If a send operation
  282. // has blocked for this time, it shall return with a partial count or 0 if no
  283. // data was sent. The default value is 0, indicating that send operations do
  284. // not time out. This option takes a timeval structure.
  285. //
  286. #define SO_SNDTIMEO 14
  287. //
  288. // This option reports the socket type. The value is an int.
  289. //
  290. #define SO_TYPE 15
  291. //
  292. // Despite its name, when enabled, this option allows the socket to bind to
  293. // the same local port as an existing socket as long as one of them is bound to
  294. // the any address and the other is bound to a different local address (i.e.
  295. // they cannot both be bound to the any address). Additionally, this option
  296. // allows the socket to bind to the exact same local address and port as an
  297. // existing socket if the existing socket is in the time-wait state. Both
  298. // sockets must have this option set for it to take effect. This option takes
  299. // an int boolean.
  300. //
  301. #define SO_REUSEADDR 16
  302. //
  303. // This option allows a socket to bind to the exact same local address and
  304. // port as an existing socket. Both sockets must have the option set for it to
  305. // take effect. This option takes an int boolean.
  306. //
  307. #define SO_REUSEPORT 17
  308. //
  309. // This option determines whether or not to send and receive credentials
  310. // automatically in the control data. This only applies to local sockets.
  311. //
  312. #define SO_PASSCRED 18
  313. //
  314. // This option returns the credentials of the foreign socket at the time of
  315. // connect. This only applies to local sockets. The argument is a pointer to
  316. // a ucred structure.
  317. //
  318. #define SO_PEERCRED 19
  319. //
  320. // Define the level number for the get/setsockopts function to apply to the
  321. // socket itself.
  322. //
  323. #define SOL_SOCKET 0xFFFF
  324. //
  325. // Define socket ioctl numbers.
  326. //
  327. //
  328. // This ioctl returns a non-zero integer if the inbound data stream is at the
  329. // urgent mark. If the SO_OOBINLINE option is not and SIOCATMARK returns true,
  330. // then the next read from the socket will return the bytes following the
  331. // urgent data. Note that a read never reads across the urgent mark.
  332. //
  333. #define SIOCATMARK 0x7300
  334. //
  335. // Define the maximum length of the connection backlog queue for listen calls
  336. // before the system stats refusing connection requests.
  337. //
  338. #define SOMAXCONN 512
  339. //
  340. // ------------------------------------------------------ Data Type Definitions
  341. //
  342. //
  343. // Define the unsigned integer type used for the sockaddr family type.
  344. //
  345. typedef unsigned int sa_family_t;
  346. //
  347. // Define the type used for passing the length of a socket.
  348. //
  349. typedef unsigned long socklen_t;
  350. /*++
  351. Structure Description:
  352. This structure defines a socket address.
  353. Members:
  354. sa_family - Stores the socket address family. See AF_* definitions.
  355. sa_data - Stores the address data information, which may or may not use
  356. all of the bytes available in this member.
  357. --*/
  358. struct sockaddr {
  359. sa_family_t sa_family;
  360. char sa_data[28];
  361. };
  362. /*++
  363. Structure Description:
  364. This structure defines a socket address storage structure, which is
  365. guaranteed to be as big as the biggest type of sockaddr.
  366. Members:
  367. sa_family - Stores the socket address family. See AF_* definitions.
  368. sa_data - Stores the address data information, which may or may not use
  369. all of the bytes available in this member.
  370. --*/
  371. struct sockaddr_storage {
  372. sa_family_t ss_family;
  373. char ss_data[28];
  374. };
  375. /*++
  376. Structure Description:
  377. This structure defines the linger state for a socket.
  378. Members:
  379. l_onoff - Stores a boolean value indicating whether or not lingering is
  380. enabled on socket close.
  381. l_linger - Stores the time, in seconds, that the socket is set to linger
  382. on close.
  383. --*/
  384. struct linger {
  385. int l_onoff;
  386. int l_linger;
  387. };
  388. /*++
  389. Structure Description:
  390. This structure defines a socket message.
  391. Members:
  392. msg_name - Stores a pointer to the socket address to send to or receive
  393. from.
  394. msg_namelen - Stores the size of the name buffer in bytes.
  395. msg_iov - Stores a pointer to an array of I/O vectors to do the I/O to or
  396. from.
  397. msg_iovlen - Stores the number of elements in the I/O vector.
  398. msg_control - Stores an optional pointer to the ancillary data.
  399. msg_controllen - Stores the length of the ancillary data in bytes on input.
  400. On output, this value is adjusted to indicate the actual amount of
  401. data.
  402. msg_flags - Stores a bitmask of message flags. See MSG_* for definitions.
  403. --*/
  404. struct msghdr {
  405. void *msg_name;
  406. socklen_t msg_namelen;
  407. struct iovec *msg_iov;
  408. size_t msg_iovlen;
  409. void *msg_control;
  410. socklen_t msg_controllen;
  411. int msg_flags;
  412. };
  413. /*++
  414. Structure Description:
  415. This structure defines a socket control message, the header for the socket
  416. ancillary data.
  417. Members:
  418. cmsg_len - Stores the length of the data for this message, including this
  419. structure.
  420. cmsg_level - Stores the originating protocol of the control message.
  421. cmsg_type - Stores the control message type.
  422. --*/
  423. struct cmsghdr {
  424. socklen_t cmsg_len;
  425. int cmsg_level;
  426. int cmsg_type;
  427. };
  428. /*++
  429. Structure Description:
  430. This structure defines the user credential structure used when passing a
  431. SCM_CREDENTIALS ancillary message. These credentials are checked and
  432. validated by the kernel on the sending side unless the sender has the
  433. system administrator permission.
  434. Members:
  435. pid - Stores the ID of the process that sent the message.
  436. uid - Stores the user ID of the process that sent the message.
  437. gid - Stores the group ID of the process that sent the message.
  438. --*/
  439. struct ucred {
  440. pid_t pid;
  441. uid_t uid;
  442. gid_t gid;
  443. };
  444. //
  445. // -------------------------------------------------------------------- Globals
  446. //
  447. //
  448. // -------------------------------------------------------- Function Prototypes
  449. //
  450. LIBC_API
  451. int
  452. socketpair (
  453. int Domain,
  454. int Type,
  455. int Protocol,
  456. int Sockets[2]
  457. );
  458. /*++
  459. Routine Description:
  460. This routine creates an unbound pair of connected sockets. The two sockets
  461. are identical.
  462. Arguments:
  463. Domain - Supplies the communicaion domain in which a sockets are to be
  464. created. Currently only AF_UNIX is supported for socket pairs.
  465. Type - Supplies the type of socket to be created. See the SOCK_*
  466. definitions. Common values include SOCK_STREAM and SOCK_DGRAM.
  467. Protocol - Supplies the particular protocol to use for the given domain
  468. and type. Supply 0 to use a default protocol appropriate for the
  469. specified type.
  470. Sockets - Supplies an array where the two connected sockets will be
  471. returned on success.
  472. Return Value:
  473. 0 on success.
  474. -1 on error, and the errno variable will be set to contain more information.
  475. --*/
  476. LIBC_API
  477. int
  478. socket (
  479. int Domain,
  480. int Type,
  481. int Protocol
  482. );
  483. /*++
  484. Routine Description:
  485. This routine creates a new socket for communication.
  486. Arguments:
  487. Domain - Supplies the communicaion domain in which a socket is to be
  488. created. See the AF_* or PF_* definitions. The most common values are
  489. AF_INET, AF_INET6, and AF_UNIX.
  490. Type - Supplies the type of socket to be created. See the SOCK_*
  491. definitions. Common values include SOCK_STREAM and SOCK_DGRAM.
  492. Protocol - Supplies the particular protocol to use for the given domain
  493. and type. Supply 0 to use a default protocol appropriate for the
  494. specified type.
  495. Return Value:
  496. Returns a non-negative integer representing the descriptor for the new
  497. socket.
  498. -1 on error, and the errno variable will be set to contain more information.
  499. --*/
  500. LIBC_API
  501. int
  502. bind (
  503. int Socket,
  504. const struct sockaddr *Address,
  505. socklen_t AddressLength
  506. );
  507. /*++
  508. Routine Description:
  509. This routine assigns a local socket address to a socket that currently has
  510. no local address assigned.
  511. Arguments:
  512. Socket - Supplies the file descriptor of the socket to be bound.
  513. Address - Supplies a pointer to the address to bind the socket to. The
  514. length and format depend on the address family of the socket.
  515. AddressLength - Supplies the length of the address structure in bytes.
  516. Return Value:
  517. 0 on success.
  518. -1 on error, and the errno variable will be set to contain more information.
  519. --*/
  520. LIBC_API
  521. int
  522. listen (
  523. int Socket,
  524. int Backlog
  525. );
  526. /*++
  527. Routine Description:
  528. This routine marks a connection-mode socket as ready to accept new
  529. incoming connections.
  530. Arguments:
  531. Socket - Supplies the file descriptor of the socket to be marked as
  532. listening.
  533. Backlog - Supplies a suggestion to the system as to the number of
  534. un-accepted connections to queue up before refusing additional
  535. incoming connection requests.
  536. Return Value:
  537. 0 on success.
  538. -1 on error, and the errno variable will be set to contain more information.
  539. --*/
  540. LIBC_API
  541. int
  542. accept (
  543. int Socket,
  544. struct sockaddr *Address,
  545. socklen_t *AddressLength
  546. );
  547. /*++
  548. Routine Description:
  549. This routine extracts the first pending incoming connection from the
  550. given listening socket, creates a new socket representing that connection,
  551. and allocates a file descriptor for that new socket. These newly created
  552. file descriptors are then ready for reading and writing.
  553. Arguments:
  554. Socket - Supplies the file descriptor of the listening socket to accept
  555. a connection on.
  556. Address - Supplies an optional pointer where the address of the connecting
  557. socket will be returned.
  558. AddressLength - Supplies a pointer that on input contains the length of the
  559. specified Address structure, and on output returns the length of the
  560. returned address.
  561. Return Value:
  562. Returns a non-negative file descriptor representing the new connection on
  563. success.
  564. -1 on error, and the errno variable will be set to contain more information.
  565. --*/
  566. LIBC_API
  567. int
  568. accept4 (
  569. int Socket,
  570. struct sockaddr *Address,
  571. socklen_t *AddressLength,
  572. int Flags
  573. );
  574. /*++
  575. Routine Description:
  576. This routine extracts the first pending incoming connection from the
  577. given listening socket, creates a new socket representing that connection,
  578. and allocates a file descriptor for that new socket. These newly created
  579. file descriptors are then ready for reading and writing.
  580. Arguments:
  581. Socket - Supplies the file descriptor of the listening socket to accept
  582. a connection on.
  583. Address - Supplies an optional pointer where the address of the connecting
  584. socket will be returned.
  585. AddressLength - Supplies a pointer that on input contains the length of the
  586. specified Address structure, and on output returns the length of the
  587. returned address.
  588. Flags - Supplies an optional bitfield of flags governing the newly created
  589. file descriptor. Set SOCK_CLOEXEC to set the O_CLOEXEC flag on the new
  590. descriptor, and SOCK_NONBLOCK to set the O_NONBLOCK flag on the new
  591. descriptor.
  592. Return Value:
  593. Returns a non-negative file descriptor representing the new connection on
  594. success.
  595. -1 on error, and the errno variable will be set to contain more information.
  596. --*/
  597. LIBC_API
  598. int
  599. connect (
  600. int Socket,
  601. const struct sockaddr *Address,
  602. socklen_t AddressLength
  603. );
  604. /*++
  605. Routine Description:
  606. This routine attempts to reach out and establish a connection with another
  607. socket.
  608. Arguments:
  609. Socket - Supplies the file descriptor of the socket to use for the
  610. connection.
  611. Address - Supplies a pointer to the address to connect to. The length and
  612. format depend on the address family of the socket.
  613. AddressLength - Supplies the length of the address structure in bytes.
  614. Return Value:
  615. 0 on success.
  616. -1 on error, and the errno variable will be set to contain more information.
  617. --*/
  618. LIBC_API
  619. ssize_t
  620. send (
  621. int Socket,
  622. const void *Data,
  623. size_t Length,
  624. int Flags
  625. );
  626. /*++
  627. Routine Description:
  628. This routine sends data out of a connected socket.
  629. Arguments:
  630. Socket - Supplies the file descriptor of the socket to send data out of.
  631. Data - Supplies the buffer of data to send.
  632. Length - Supplies the length of the data buffer, in bytes.
  633. Flags - Supplies a bitfield of flags governing the transmission of the data.
  634. See MSG_* definitions.
  635. Return Value:
  636. Returns the number of bytes sent on success.
  637. -1 on error, and the errno variable will be set to contain more information.
  638. --*/
  639. LIBC_API
  640. ssize_t
  641. sendto (
  642. int Socket,
  643. const void *Data,
  644. size_t Length,
  645. int Flags,
  646. const struct sockaddr *DestinationAddress,
  647. socklen_t DestinationAddressLength
  648. );
  649. /*++
  650. Routine Description:
  651. This routine sends data out of a socket, potentially to a specific
  652. destination address for connection-less sockets.
  653. Arguments:
  654. Socket - Supplies the file descriptor of the socket to send data out of.
  655. Data - Supplies the buffer of data to send.
  656. Length - Supplies the length of the data buffer, in bytes.
  657. Flags - Supplies a bitfield of flags governing the transmission of the data.
  658. See MSG_* definitions.
  659. DestinationAddress - Supplies an optional pointer to the destination
  660. address to send the data to.
  661. DestinationAddressLength - Supplies the length of the destination address
  662. structure.
  663. Return Value:
  664. Returns the number of bytes sent on success.
  665. -1 on error, and the errno variable will be set to contain more information.
  666. --*/
  667. LIBC_API
  668. ssize_t
  669. sendmsg (
  670. int Socket,
  671. const struct msghdr *Message,
  672. int Flags
  673. );
  674. /*++
  675. Routine Description:
  676. This routine sends a message out of a socket, potentially to a specific
  677. destination address for connection-less sockets. This version of the send
  678. function allows for vectored I/O and sending of ancillary data.
  679. Arguments:
  680. Socket - Supplies the file descriptor of the socket to send data out of.
  681. Message - Supplies a pointer to the message details to send.
  682. Flags - Supplies a bitfield of flags governing the transmission of the data.
  683. See MSG_* definitions.
  684. Return Value:
  685. Returns the number of bytes sent on success.
  686. -1 on error, and the errno variable will be set to contain more information.
  687. --*/
  688. LIBC_API
  689. ssize_t
  690. recv (
  691. int Socket,
  692. void *Buffer,
  693. size_t Length,
  694. int Flags
  695. );
  696. /*++
  697. Routine Description:
  698. This routine receives data from a connected socket.
  699. Arguments:
  700. Socket - Supplies the file descriptor of the socket to receive data from.
  701. Buffer - Supplies a pointer to a buffer where the received data will be
  702. returned.
  703. Length - Supplies the length of the data buffer, in bytes.
  704. Flags - Supplies a bitfield of flags governing the reception of the data.
  705. See MSG_* definitions.
  706. Return Value:
  707. Returns the number of bytes received on success.
  708. -1 on error, and the errno variable will be set to contain more information.
  709. --*/
  710. LIBC_API
  711. ssize_t
  712. recvfrom (
  713. int Socket,
  714. void *Buffer,
  715. size_t Length,
  716. int Flags,
  717. struct sockaddr *SourceAddress,
  718. socklen_t *SourceAddressLength
  719. );
  720. /*++
  721. Routine Description:
  722. This routine receives data from a socket, potentially receiving the
  723. source address for connection-less sockets.
  724. Arguments:
  725. Socket - Supplies the file descriptor of the socket to receive data from.
  726. Buffer - Supplies a pointer to a buffer where the received data will be
  727. returned.
  728. Length - Supplies the length of the data buffer, in bytes.
  729. Flags - Supplies a bitfield of flags governing the reception of the data.
  730. See MSG_* definitions.
  731. SourceAddress - Supplies an optional pointer where the source of the packet
  732. will be returned for connection-less sockets.
  733. SourceAddressLength - Supplies the length of the source address structure.
  734. Return Value:
  735. Returns the number of bytes received on success.
  736. -1 on error, and the errno variable will be set to contain more information.
  737. --*/
  738. LIBC_API
  739. ssize_t
  740. recvmsg (
  741. int Socket,
  742. struct msghdr *Message,
  743. int Flags
  744. );
  745. /*++
  746. Routine Description:
  747. This routine receives data from a socket, potentially receiving the
  748. source address for connection-less sockets. This variation of the recv
  749. function has the ability to receive vectored I/O, as well as ancillary
  750. data.
  751. Arguments:
  752. Socket - Supplies the file descriptor of the socket to receive data from.
  753. Message - Supplies a pointer to an initialized structure where the message
  754. information will be returned. The caller must initialize the
  755. appropriate members to valid buffers if the remote network address or
  756. ancillary data is desired.
  757. Flags - Supplies a bitfield of flags governing the reception of the data.
  758. See MSG_* definitions.
  759. Return Value:
  760. Returns the number of bytes received on success.
  761. -1 on error, and the errno variable will be set to contain more information.
  762. --*/
  763. LIBC_API
  764. int
  765. shutdown (
  766. int Socket,
  767. int How
  768. );
  769. /*++
  770. Routine Description:
  771. This routine shuts down all or part of a full-duplex socket connection.
  772. Arguments:
  773. Socket - Supplies the socket to shut down.
  774. How - Supplies the type of shutdown. Valid values are SHUT_RD to disable
  775. further receive operations, SHUT_WR to disable further send operations,
  776. or SHUT_RDWR to disable further send and receive operations.
  777. Return Value:
  778. 0 on success.
  779. -1 on failure, and errno will be set to contain more information.
  780. --*/
  781. LIBC_API
  782. int
  783. setsockopt (
  784. int Socket,
  785. int Level,
  786. int OptionName,
  787. const void *OptionValue,
  788. socklen_t OptionLength
  789. );
  790. /*++
  791. Routine Description:
  792. This routine sets a socket option for the given socket.
  793. Arguments:
  794. Socket - Supplies the file descriptor of the socket to set options for.
  795. Level - Supplies the protocol level at which the option resides. To set
  796. options at the socket level, supply SOL_SOCKET. To set options at other
  797. levels, specify the identifier for the protocol controlling the option.
  798. For example, to indicate that an option is interpreted by the TCP
  799. protocol, set this parameter to IPPROTO_TCP.
  800. OptionName - Supplies the option name that is passed to the protocol module
  801. for interpretation. See SO_* definitions.
  802. OptionValue - Supplies a pointer to a buffer that is passed uninterpreted
  803. to the protocol module. The contents of the buffer are option-specific.
  804. OptionLength - Supplies the length of the option buffer in bytes.
  805. Return Value:
  806. 0 on success.
  807. -1 on failure, and errno will be set to contain more information.
  808. --*/
  809. LIBC_API
  810. int
  811. getsockopt (
  812. int Socket,
  813. int Level,
  814. int OptionName,
  815. void *OptionValue,
  816. socklen_t *OptionLength
  817. );
  818. /*++
  819. Routine Description:
  820. This routine retrieves the current value of a given socket option.
  821. Arguments:
  822. Socket - Supplies the file descriptor of the socket.
  823. Level - Supplies the protocol level at which the option resides. To get
  824. options at the socket level, supply SOL_SOCKET. To get options at other
  825. levels, specify the identifier for the protocol controlling the option.
  826. For example, to indicate that an option is interpreted by the TCP
  827. protocol, set this parameter to IPPROTO_TCP.
  828. OptionName - Supplies the option name that is passed to the protocol module
  829. for interpretation. See SO_* definitions.
  830. OptionValue - Supplies a pointer to a buffer where the option value is
  831. returned on success.
  832. OptionLength - Supplies a pointer that on input contains the size of the
  833. option value buffer in bytes. If the supplied length is less than the
  834. actual size of the option value, then the option value will be silently
  835. truncated. On output, if the supplied length is greater than the actual
  836. size of the value, this will contain the actual size of the value.
  837. Return Value:
  838. 0 on success.
  839. -1 on failure, and errno will be set to contain more information.
  840. --*/
  841. LIBC_API
  842. int
  843. getsockname (
  844. int Socket,
  845. struct sockaddr *SocketAddress,
  846. socklen_t *AddressLength
  847. );
  848. /*++
  849. Routine Description:
  850. This routine returns the current address to which the given socket is bound.
  851. Arguments:
  852. Socket - Supplies the file descriptor of the socket.
  853. SocketAddress - Supplies a pointer where the socket address will be
  854. returned.
  855. AddressLength - Supplies a pointer that on input supplies the size of the
  856. socket address buffer. On output, this will contain the actual size of
  857. the buffer. The buffer will have been truncated if the number returned
  858. here is greater than the number supplied.
  859. Return Value:
  860. 0 on success.
  861. -1 on failure, and errno will be set to contain more information.
  862. --*/
  863. LIBC_API
  864. int
  865. getpeername (
  866. int Socket,
  867. struct sockaddr *SocketAddress,
  868. socklen_t *AddressLength
  869. );
  870. /*++
  871. Routine Description:
  872. This routine returns the peer address of the specified socket.
  873. Arguments:
  874. Socket - Supplies the file descriptor of the socket.
  875. SocketAddress - Supplies a pointer where the socket's peer address will be
  876. returned.
  877. AddressLength - Supplies a pointer that on input supplies the size of the
  878. socket address buffer. On output, this will contain the actual size of
  879. the buffer. The buffer will have been truncated if the number returned
  880. here is greater than the number supplied.
  881. Return Value:
  882. 0 on success.
  883. -1 on failure, and errno will be set to contain more information.
  884. --*/
  885. LIBC_API
  886. struct cmsghdr *
  887. __cmsg_nxthdr (
  888. struct msghdr *Message,
  889. struct cmsghdr *ControlMessage
  890. );
  891. /*++
  892. Routine Description:
  893. This routine gets the next control message in the buffer of ancillary data.
  894. Arguments:
  895. Message - Supplies a pointer to the beginning of the ancillary data.
  896. ControlMessage - Supplies the previous control message. This routine
  897. returns the next control message after this one.
  898. Return Value:
  899. Returns a pointer to the control message after the given control message.
  900. NULL if there are no more messages or the buffer does not contain enough
  901. space.
  902. --*/
  903. #ifdef __cplusplus
  904. }
  905. #endif
  906. #endif