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

/include/lely/io/sock.h

https://gitlab.com/lely_industries/io
C Header | 697 lines | 93 code | 59 blank | 545 comment | 0 complexity | a8762a43d50cf9bcd2653bbd1b984d71 MD5 | raw file
  1. /*!\file
  2. * This header file is part of the I/O library; it contains the network socket
  3. * declarations.
  4. *
  5. * \copyright 2017 Lely Industries N.V.
  6. *
  7. * \author J. S. Seldenthuis <jseldenthuis@lely.com>
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License");
  10. * you may not use this file except in compliance with the License.
  11. * You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing, software
  16. * distributed under the License is distributed on an "AS IS" BASIS,
  17. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. */
  21. #ifndef LELY_IO_SOCK_H
  22. #define LELY_IO_SOCK_H
  23. #include <lely/io/io.h>
  24. enum {
  25. //! A Bluetooth socket.
  26. IO_SOCK_BTH = 1,
  27. //! An IPv4 socket.
  28. IO_SOCK_IPV4,
  29. //! An IPv6 socket.
  30. IO_SOCK_IPV6,
  31. //! A UNIX domain socket (only supported on POSIX platforms).
  32. IO_SOCK_UNIX
  33. };
  34. enum {
  35. /*!
  36. * A stream-oriented connection-mode socket type. This corresponds to
  37. * TCP for IPv4 or IPv6 sockets and RFCOMM for Bluetooth.
  38. */
  39. IO_SOCK_STREAM = 1,
  40. /*!
  41. * A datagram-oriented, typically connectionless-mode, socket type. This
  42. * corresponds to UDP for IPv4 or IPv6 sockets.
  43. */
  44. IO_SOCK_DGRAM
  45. };
  46. enum {
  47. //! Peeks at incoming data.
  48. IO_MSG_PEEK = 1 << 0,
  49. //! Requests out-of-band data.
  50. IO_MSG_OOB = 1 << 1,
  51. /*!
  52. * On stream-oriented sockets, block until the full amount of data can
  53. * be returned.
  54. */
  55. IO_MSG_WAITALL = 1 << 2
  56. };
  57. enum {
  58. //! Disables further receive operations.
  59. IO_SHUT_RD,
  60. //! Disables further send operations.
  61. IO_SHUT_WR,
  62. //! Disables further send and receive operations.
  63. IO_SHUT_RDWR
  64. };
  65. #ifdef __cplusplus
  66. extern "C" {
  67. #endif
  68. /*!
  69. * Opens a network socket.
  70. *
  71. * \param domain the domain of the socket (one of #IO_SOCK_BTH, #IO_SOCK_IPV4,
  72. * #IO_SOCK_IPV6 or #IO_SOCK_UNIX).
  73. * \param type the type of the socket (either #IO_SOCK_STREAM or
  74. * #IO_SOCK_DGRAM).
  75. *
  76. * \returns a new I/O device handle, or #IO_HANDLE_ERROR on error. In the latter
  77. * case, the error number can be obtained with `get_errnum()`.
  78. */
  79. LELY_IO_EXTERN io_handle_t io_open_socket(int domain, int type);
  80. /*!
  81. * Opens a pair of connected sockets.
  82. *
  83. * \param domain the domain of the sockets (one of #IO_SOCK_IPV4,
  84. * #IO_SOCK_IPV6 or #IO_SOCK_UNIX).
  85. * \param type the type of the sockets (either #IO_SOCK_STREAM or
  86. * #IO_SOCK_DGRAM).
  87. * \param handle_vector a 2-value array which, on success, contains the device
  88. * handles of the socket pair.
  89. *
  90. * \returns 0 on success, or -1 on error. In the latter case, the error number
  91. * can be obtained with `get_errnum()`.
  92. */
  93. LELY_IO_EXTERN int io_open_socketpair(int domain, int type,
  94. io_handle_t handle_vector[2]);
  95. /*!
  96. * Performs a receive operation on a network socket.
  97. *
  98. * \param handle a valid socket device handle.
  99. * \param buf a pointer to the destination buffer.
  100. * \param nbytes the number of bytes to receive.
  101. * \param addr an optional pointer to a value which, on success, contains the
  102. * source address.
  103. * \param flags the type of message reception (any combination of #IO_MSG_PEEK,
  104. * #IO_MSG_OOB and #IO_MSG_WAITALL).
  105. *
  106. * \returns the number of bytes received on success, or -1 on error. In the
  107. * latter case, the error number can be obtained with `get_errnum()`.
  108. */
  109. LELY_IO_EXTERN ssize_t io_recv(io_handle_t handle, void *buf, size_t nbytes,
  110. io_addr_t *addr, int flags);
  111. /*!
  112. * Performs a send operation on a network socket.
  113. *
  114. * \param handle a valid socket device handle.
  115. * \param buf a pointer to the source buffer.
  116. * \param nbytes the number of bytes to send.
  117. * \param addr an optional pointer to the destination address (ignored for
  118. * connection-mode sockets).
  119. * \param flags type type of message transmission (0 or #IO_MSG_OOB).
  120. *
  121. * \returns the number of bytes sent on success, or -1 on error. In the latter
  122. * case, the error number can be obtained with `get_errnum()`.
  123. */
  124. LELY_IO_EXTERN ssize_t io_send(io_handle_t handle, const void *buf,
  125. size_t nbytes, const io_addr_t *addr, int flags);
  126. /*!
  127. * Accepts an incoming connection on a listening socket.
  128. *
  129. * \param handle a valid socket device handle.
  130. * \param addr an optional pointer to a value which, on success, contains the
  131. * incoming network address.
  132. *
  133. * \returns a new I/O device handle, or #IO_HANDLE_ERROR on error. In the latter
  134. * case, the error number can be obtained with `get_errnum()`.
  135. *
  136. * \see io_sock_listen()
  137. */
  138. LELY_IO_EXTERN io_handle_t io_accept(io_handle_t handle, io_addr_t *addr);
  139. /*!
  140. * Connects a socket to a network address.
  141. *
  142. * \param handle a valid socket device handle.
  143. * \param addr a pointer to the network address to which to connect.
  144. *
  145. * \returns 0 on success, or -1 on error. In the latter case, the error number
  146. * can be obtained with `get_errnum()`.
  147. */
  148. LELY_IO_EXTERN int io_connect(io_handle_t handle, const io_addr_t *addr);
  149. /*!
  150. * Obtains the domain of a socket (the first parameter in a call to
  151. * io_open_socket() or io_open_socketpair()).
  152. *
  153. * \returns #IO_SOCK_BTH, #IO_SOCK_IPV4, #IO_SOCK_IPV6 or #IO_SOCK_UNIX, or -1
  154. * on error. In the latter case, the error number can be obtained with
  155. * `get_errnum()`.
  156. *
  157. * \see io_sock_get_type(), io_addr_get_domain()
  158. */
  159. LELY_IO_EXTERN int io_sock_get_domain(io_handle_t handle);
  160. /*!
  161. * Obtains the type of a network socket (the second parameter in a call to
  162. * io_open_socket() or io_open_socketpair()).
  163. *
  164. * \returns #IO_SOCK_STREAM or #IO_SOCK_DGRAM, or -1 on error. In the latter
  165. * case, the error number can be obtained with `get_errnum()`.
  166. *
  167. * \see io_sock_get_domain()
  168. */
  169. LELY_IO_EXTERN int io_sock_get_type(io_handle_t handle);
  170. /*!
  171. * Binds a local network address to a socket.
  172. *
  173. * \returns 0 on success, or -1 on error. In the latter case, the error number
  174. * can be obtained with `get_errnum()`.
  175. */
  176. LELY_IO_EXTERN int io_sock_bind(io_handle_t handle, const io_addr_t *addr);
  177. /*!
  178. * Marks a connection-mode socket (#IO_SOCK_STREAM) as accepting connections.
  179. *
  180. * \param handle a valid socket device handle.
  181. * \param backlog the number of pending connections in the socket's listen
  182. * queue. The maximum value can be obtained with
  183. * io_sock_get_maxconn(). If \a backlog is 0, an
  184. * implementation-defined minimum value is used.
  185. *
  186. * \returns 0 on success, or -1 on error. In the latter case, the error number
  187. * can be obtained with `get_errnum()`.
  188. *
  189. * \see io_accept()
  190. */
  191. LELY_IO_EXTERN int io_sock_listen(io_handle_t handle, int backlog);
  192. /*!
  193. * Causes all or part of a full-duplex connection on a socket to be shut down.
  194. *
  195. * \param handle a valid socket device handle.
  196. * \param how the type of shutdown (one of #IO_SHUT_RD, #IO_SHUT_WR or
  197. * #IO_SHUT_RDWR).
  198. *
  199. * \returns 0 on success, or -1 on error. In the latter case, the error number
  200. * can be obtained with `get_errnum()`.
  201. */
  202. LELY_IO_EXTERN int io_sock_shutdown(io_handle_t handle, int how);
  203. /*!
  204. * Obtains the locally-bound name of a socket and stores the resulting address
  205. * in *\a addr. The socket name is set by io_sock_bind() and io_connect().
  206. *
  207. * \returns 0 on success, or -1 on error. In the latter case, the error number
  208. * can be obtained with `get_errnum()`.
  209. */
  210. LELY_IO_EXTERN int io_sock_get_sockname(io_handle_t handle, io_addr_t *addr);
  211. /*!
  212. * Obtains the peer address of a socket and stores the result in *\a addr. The
  213. * peer name is set by io_accept() and io_connect().
  214. *
  215. * \returns 0 on success, or -1 on error. In the latter case, the error number
  216. * can be obtained with `get_errnum()`.
  217. */
  218. LELY_IO_EXTERN int io_sock_get_peername(io_handle_t handle, io_addr_t *addr);
  219. /*!
  220. * Returns the maximum queue length for pending connections. This value can be
  221. * used as the \a backlog parameter in a call to `io_sock_listen()`.
  222. *
  223. * \returns the value of \a SOMAXCONN, or -1 on error.
  224. */
  225. LELY_IO_EXTERN int io_sock_get_maxconn(void);
  226. /*!
  227. * Checks if a socket is currently listening for incoming connections. This
  228. * function implements the SOL_SOCKET/SO_ACCEPTCONN option.
  229. *
  230. * \returns 1 if the socket is accepting connections and 0 if not, or -1 on
  231. * error. In the latter case, the error number can be obtained with
  232. * `get_errnum()`.
  233. *
  234. * \see io_sock_listen()
  235. */
  236. LELY_IO_EXTERN int io_sock_get_acceptconn(io_handle_t handle);
  237. /*!
  238. * Checks if a socket is allowed to send broadcast messages. This function
  239. * implements the SOL_SOCKET/SO_BROADCAST option.
  240. *
  241. * \returns 1 if address reuse is enabled and 0 if not, or -1 on error. In the
  242. * latter case, the error number can be obtained with `get_errnum()`.
  243. *
  244. * \see io_sock_set_broadcast()
  245. */
  246. LELY_IO_EXTERN int io_sock_get_broadcast(io_handle_t handle);
  247. /*!
  248. * Enables a socket to send broadcast messages if \a broadcast is non-zero, and
  249. * disables this option otherwise (disabled by default). This function
  250. * implements the SOL_SOCKET/SO_BROADCAST option.
  251. *
  252. * \returns 0 on success, or -1 on error. In the latter case, the error number
  253. * can be obtained with `get_errnum()`.
  254. *
  255. * \see io_sock_get_broadcast()
  256. */
  257. LELY_IO_EXTERN int io_sock_set_broadcast(io_handle_t handle, int broadcast);
  258. /*!
  259. * Checks if debugging is enabled for a socket. This function implements the
  260. * SOL_SOCKET/SO_DEBUG option.
  261. *
  262. * \returns 1 if debugging is enabled and 0 if not, or -1 on error. In the
  263. * latter case, the error number can be obtained with `get_errnum()`.
  264. *
  265. * \see io_sock_set_debug()
  266. */
  267. LELY_IO_EXTERN int io_sock_get_debug(io_handle_t handle);
  268. /*!
  269. * Enables (platform dependent) debugging output for a socket if \a debug is
  270. * non-zero, and disables this option otherwise (disabled by default). This
  271. * function implements the SOL_SOCKET/SO_DEBUG option.
  272. *
  273. * \returns 0 on success, or -1 on error. In the latter case, the error number
  274. * can be obtained with `get_errnum()`.
  275. *
  276. * \see io_sock_get_debug()
  277. */
  278. LELY_IO_EXTERN int io_sock_set_debug(io_handle_t handle, int debug);
  279. /*!
  280. * Checks if routing is disabled for a socket. This function implements the
  281. * SOL_SOCKET/SO_DONTROUTE option.
  282. *
  283. * \returns 1 if routing is disabled and 0 if not, or -1 on error. In the latter
  284. * case, the error number can be obtained with `get_errnum()`.
  285. *
  286. * \see io_sock_set_dontroute()
  287. */
  288. LELY_IO_EXTERN int io_sock_get_dontroute(io_handle_t handle);
  289. /*!
  290. * Bypasses normal routing for a socket if \a dontroute is non-zero, and
  291. * disables this option otherwise (disabled by default). This function
  292. * implements the SOL_SOCKET/SO_DONTROUTE option.
  293. *
  294. * \returns 0 on success, or -1 on error. In the latter case, the error number
  295. * can be obtained with `get_errnum()`.
  296. *
  297. * \see io_sock_get_dontroute()
  298. */
  299. LELY_IO_EXTERN int io_sock_set_dontroute(io_handle_t handle, int dontroute);
  300. /*!
  301. * Obtains and clears the current error number of a socket, and stores the value
  302. * in *\a perror. This function implements the SOL_SOCKET/SO_ERROR option.
  303. *
  304. * \returns 0 on success, or -1 on error. In the latter case, the error number
  305. * can be obtained with `get_errnum()`.
  306. */
  307. LELY_IO_EXTERN int io_sock_get_error(io_handle_t handle, int *perror);
  308. /*!
  309. * Checks if the TCP keep-alive option is enabled for a socket. This function
  310. * implements the SOL_SOCKET/KEEPALIVE option.
  311. *
  312. * \returns 1 if TCP keep-alive is enabled and 0 if not, or -1 on error. In the
  313. * latter case, the error number can be obtained with `get_errnum()`.
  314. *
  315. * \see io_sock_set_keepalive()
  316. */
  317. LELY_IO_EXTERN int io_sock_get_keepalive(io_handle_t handle);
  318. /*!
  319. * Enables or disables the TCP keep-alive option for a socket (disabled by
  320. * default). Note that the \a time and \a interval options are supported only on
  321. * Windows and Linux. This function implements the SOL_SOCKET/SO_KEEPALIVE
  322. * option.
  323. *
  324. * \param handle a valid socket device handle.
  325. * \param keepalive a boolean option specifying whether TCP keep-alive should be
  326. * enabled (non-zero) or disabled (zero).
  327. * \param time the timeout (in seconds) after which the first keep-alive
  328. * packet is sent. This parameter is unused if \a keepalive is
  329. * zero.
  330. * \param interval the interval (in seconds) between successive keep-alive
  331. * packets if no acknowledgment is received. This parameter is
  332. * unused if \a keepalive is zero.
  333. *
  334. * \returns 0 on success, or -1 on error. In the latter case, the error number
  335. * can be obtained with `get_errnum()`.
  336. *
  337. * \see io_sock_get_keepalive()
  338. */
  339. LELY_IO_EXTERN int io_sock_set_keepalive(io_handle_t handle, int keepalive,
  340. int time, int interval);
  341. /*!
  342. * Obtains the linger time (in seconds) of a socket. This function implements
  343. * the SOL_SOCKET/SO_LINGER option.
  344. *
  345. * \returns the linger time, or -1 on error. In the latter case, the error
  346. * number can be obtained with `get_errnum()`.
  347. *
  348. * \see io_sock_set_linger()
  349. */
  350. LELY_IO_EXTERN int io_sock_get_linger(io_handle_t handle);
  351. /*!
  352. * Sets the time (in seconds) io_close() will wait for unsent messages to be
  353. * sent. If \a time is 0, lingering is disabled. This function implements the
  354. * SOL_SOCKET/SO_LINGER option.
  355. *
  356. * \returns 0 on success, or -1 on error. In the latter case, the error number
  357. * can be obtained with `get_errnum()`.
  358. *
  359. * \see io_sock_getlinger()
  360. */
  361. LELY_IO_EXTERN int io_sock_set_linger(io_handle_t handle, int time);
  362. /*!
  363. * Checks if out-of-band data is received in the normal data stream of a socket.
  364. * This function implements the SOL_SOCKET/SO_OOBINLINE option.
  365. *
  366. * \returns 1 if out-of-band data is received in the normal data stream and 0 if
  367. * not, or -1 on error. In the latter case, the error number can be obtained
  368. * with `get_errnum()`.
  369. *
  370. * \see io_sock_set_oobinline()
  371. */
  372. LELY_IO_EXTERN int io_sock_get_oobinline(io_handle_t handle);
  373. /*!
  374. * Requests that out-of-band data is placed into the normal data stream of
  375. * socket if \a oobinline is non-zero, and disables this option otherwise
  376. * (disabled by default). This function implements the SOL_SOCKET/SO_OOBINLINE
  377. * option.
  378. *
  379. * \returns 0 on success, or -1 on error. In the latter case, the error number
  380. * can be obtained with `get_errnum()`.
  381. *
  382. * \see io_sock_get_oobinline()
  383. */
  384. LELY_IO_EXTERN int io_sock_set_oobinline(io_handle_t handle, int oobinline);
  385. /*!
  386. * Obtains the size (in bytes) of the receive buffer of a socket. This function
  387. * implements the SOL_SOCKET/SO_RCVBUF option.
  388. *
  389. * \returns the size of the receive buffer, or -1 on error. In the latter case,
  390. * the error number can be obtained with `get_errnum()`.
  391. *
  392. * \see io_sock_set_rcvbuf()
  393. */
  394. LELY_IO_EXTERN int io_sock_get_rcvbuf(io_handle_t handle);
  395. /*!
  396. * Sets the size (in bytes) of the receive buffer of a socket. This function
  397. * implements the SOL_SOCKET/SO_RCVBUF option.
  398. *
  399. * \returns 0 on success, or -1 on error. In the latter case, the error number
  400. * can be obtained with `get_errnum()`.
  401. *
  402. * \see io_sock_get_rcvbuf()
  403. */
  404. LELY_IO_EXTERN int io_sock_set_rcvbuf(io_handle_t handle, int size);
  405. /*!
  406. * Sets the timeout (in milliseconds) of a receive operation on a socket. This
  407. * function implements the SOL_SOCKET/SO_RCVTIMEO option.
  408. *
  409. * \returns 0 on success, or -1 on error. In the latter case, the error number
  410. * can be obtained with `get_errnum()`.
  411. */
  412. LELY_IO_EXTERN int io_sock_set_rcvtimeo(io_handle_t handle, int timeout);
  413. /*!
  414. * Checks if a socket is allowed to be bound to an address that is already in
  415. * use. This function implements the SOL_SOCKET/SO_REUSEADDR option.
  416. *
  417. * \returns 1 if address reuse is enabled and 0 if not, or -1 on error. In the
  418. * latter case, the error number can be obtained with `get_errnum()`.
  419. *
  420. * \see io_sock_set_reuseaddr()
  421. */
  422. LELY_IO_EXTERN int io_sock_get_reuseaddr(io_handle_t handle);
  423. /*!
  424. * Enables a socket to be bound to an address that is already in use if
  425. * \a reuseaddr is non-zero, and disables this option otherwise (disabled by
  426. * default). This function implements the SOL_SOCKET/SO_REUSEADDR option.
  427. *
  428. * \returns 0 on success, or -1 on error. In the latter case, the error number
  429. * can be obtained with `get_errnum()`.
  430. *
  431. * \see io_sock_get_reuseaddr()
  432. */
  433. LELY_IO_EXTERN int io_sock_set_reuseaddr(io_handle_t handle, int reuseaddr);
  434. /*!
  435. * Obtains the size (in bytes) of the send buffer of a socket. This function
  436. * implements the SOL_SOCKET/SO_SNDBUF option.
  437. *
  438. * \returns the size of the send buffer, or -1 on error. In the latter case, the
  439. * error number can be obtained with `get_errnum()`.
  440. *
  441. * \see io_sock_set_sndbuf()
  442. */
  443. LELY_IO_EXTERN int io_sock_get_sndbuf(io_handle_t handle);
  444. /*!
  445. * Sets the size (in bytes) of the send buffer of a socket. This function
  446. * implements the SOL_SOCKET/SO_SNDBUF option.
  447. *
  448. * \returns 0 on success, or -1 on error. In the latter case, the error number
  449. * can be obtained with `get_errnum()`.
  450. *
  451. * \see io_sock_get_sndbuf()
  452. */
  453. LELY_IO_EXTERN int io_sock_set_sndbuf(io_handle_t handle, int size);
  454. /*!
  455. * Sets the timeout (in milliseconds) of a send operation on a socket. This
  456. * function implements the SOL_SOCKET/SO_SNDTIMEO option.
  457. *
  458. * \returns 0 on success, or -1 on error. In the latter case, the error number
  459. * can be obtained with `get_errnum()`.
  460. */
  461. LELY_IO_EXTERN int io_sock_set_sndtimeo(io_handle_t handle, int timeout);
  462. /*!
  463. * Checks if Nagle's algorithm for send coalescing is enabled for a socket. This
  464. * function implements the IPPROTO_TCP/TCP_NODELAY option.
  465. *
  466. * \returns 1 if Nagle's algorithm is disabled and 0 otherwise, or -1 on error.
  467. * In the latter case, the error number can be obtained with `get_errnum()`.
  468. *
  469. * \see io_sock_set_tcp_nodelay()
  470. */
  471. LELY_IO_EXTERN int io_sock_get_tcp_nodelay(io_handle_t handle);
  472. /*!
  473. * Disables Nagle's algorithm for send coalescing if \a nodelay is non-zero, and
  474. * enables it otherwise. This function implements the IPPROTO_TCP/TCP_NODELAY
  475. * option. Nagle's algorithm is enabled by default.
  476. *
  477. * \returns 0 on success, or -1 on error. In the latter case, the error number
  478. * can be obtained with `get_errnum()`.
  479. *
  480. * \see io_sock_get_tcp_nodelay()
  481. */
  482. LELY_IO_EXTERN int io_sock_set_tcp_nodelay(io_handle_t handle, int nodelay);
  483. /*!
  484. * Obtains the amount of data (in bytes) in the input buffer of a socket.
  485. *
  486. * \returns the number of bytes that can be read, or -1 on error. In the latter
  487. * case, the error number can be obtained with `get_errnum()`.
  488. */
  489. LELY_IO_EXTERN ssize_t io_sock_get_nread(io_handle_t handle);
  490. /*!
  491. * Checks if the loopback of outgoing multicast datagrams is enabled for a
  492. * socket. This function implements the IPPROTO_IP/IP_MULTICAST_LOOP and
  493. * IPPROTO_IPV6/IPV6_MULTICAST_LOOP options.
  494. *
  495. * \returns 1 if multicast loopback is enabled and 0 if not, or -1 on error. In
  496. * the latter case, the error number can be obtained with `get_errnum()`.
  497. *
  498. * \see io_sock_set_mcast_loop()
  499. */
  500. LELY_IO_EXTERN int io_sock_get_mcast_loop(io_handle_t handle);
  501. /*!
  502. * Enables the loopback of outgoing multicast datagrams for a socket if \a loop
  503. * is non-zero, and disables this option otherwise (enabled by default). This
  504. * function implements the IPPROTO_IP/IP_MULTICAST_LOOP and
  505. * IPPROTO_IPV6/IPV6_MULTICAST_LOOP options.
  506. *
  507. * \returns 0 on success, or -1 on error. In the latter case, the error number
  508. * can be obtained with `get_errnum()`.
  509. *
  510. * \see io_sock_get_mcast_loop()
  511. */
  512. LELY_IO_EXTERN int io_sock_set_mcast_loop(io_handle_t handle, int loop);
  513. /*!
  514. * Obtains the TTL (time to live) value for IP multicast traffic on a socket.
  515. * This function implements the IPPROTO_IP/IP_MULTICAST_TTL and
  516. * IPPROTO_IPV6/IPV6_MULTICAST_HOPS options.
  517. *
  518. * \returns the TTL for IP multicast traffic, or -1 on error. In the latter
  519. * case, the error number can be obtained with `get_errnum()`.
  520. *
  521. * \see io_sock_set_mcast_ttl()
  522. */
  523. LELY_IO_EXTERN int io_sock_get_mcast_ttl(io_handle_t handle);
  524. /*!
  525. * Sets the TTL (time to live) value for IP multicast traffic on a socket (the
  526. * default is 1). This function implements the IPPROTO_IP/IP_MULTICAST_TTL and
  527. * IPPROTO_IPV6/IPV6_MULTICAST_HOPS options.
  528. *
  529. * \returns 0 on success, or -1 on error. In the latter case, the error number
  530. * can be obtained with `get_errnum()`.
  531. *
  532. * \see io_sock_get_mcast_ttl()
  533. */
  534. LELY_IO_EXTERN int io_sock_set_mcast_ttl(io_handle_t handle, int ttl);
  535. /*!
  536. * Joins an any-source multicast group.
  537. *
  538. * \param handle a valid IPv4 or IPv6 connectionless socket device handle.
  539. * \param index a network interface index. On Linux, if \a index is 0, the
  540. * interface is chosen automatically.
  541. * \param group a pointer to the address of the group to join.
  542. *
  543. * \returns 0 on success, or -1 on error. In the latter case, the error number
  544. * can be obtained with `get_errnum()`.
  545. *
  546. * \see io_sock_mcast_leave_group()
  547. */
  548. LELY_IO_EXTERN int io_sock_mcast_join_group(io_handle_t handle,
  549. unsigned int index, const io_addr_t *group);
  550. /*!
  551. * Blocks data from a given source to a given multicast group.
  552. *
  553. * \param handle a valid IPv4 or IPv6 connectionless socket device handle.
  554. * \param index a network interface index. On Linux, if \a index is 0, the
  555. * interface is chosen automatically.
  556. * \param group a pointer to the address of the multicast group.
  557. * \param source a pointer to the address of the source to block.
  558. *
  559. * \returns 0 on success, or -1 on error. In the latter case, the error number
  560. * can be obtained with `get_errnum()`.
  561. *
  562. * \see io_sock_mcast_unblock_source()
  563. */
  564. LELY_IO_EXTERN int io_sock_mcast_block_source(io_handle_t handle,
  565. unsigned int index, const io_addr_t *group,
  566. const io_addr_t *source);
  567. /*!
  568. * Unblocks data from a given source to a given multicast group.
  569. *
  570. * \param handle a valid IPv4 or IPv6 connectionless socket device handle.
  571. * \param index a network interface index. On Linux, if \a index is 0, the
  572. * interface is chosen automatically.
  573. * \param group a pointer to the address of the multicast group.
  574. * \param source a pointer to the address of the source to unblock.
  575. *
  576. * \returns 0 on success, or -1 on error. In the latter case, the error number
  577. * can be obtained with `get_errnum()`.
  578. *
  579. * \see io_sock_mcast_block_source()
  580. */
  581. LELY_IO_EXTERN int io_sock_mcast_unblock_source(io_handle_t handle,
  582. unsigned int index, const io_addr_t *group,
  583. const io_addr_t *source);
  584. /*!
  585. * Leaves an any-source multicast group.
  586. *
  587. * \param handle a valid IPv4 or IPv6 connectionless socket device handle.
  588. * \param index a network interface index. On Linux, if \a index is 0, the
  589. * interface is chosen automatically.
  590. * \param group a pointer to the address of the group to leave.
  591. *
  592. * \returns 0 on success, or -1 on error. In the latter case, the error number
  593. * can be obtained with `get_errnum()`.
  594. *
  595. * \see io_sock_mcast_join_group()
  596. */
  597. LELY_IO_EXTERN int io_sock_mcast_leave_group(io_handle_t handle,
  598. unsigned int index, const io_addr_t *group);
  599. /*!
  600. * Joins a source-specific multicast group.
  601. *
  602. * \param handle a valid IPv4 or IPv6 connectionless socket device handle.
  603. * \param index a network interface index. On Linux, if \a index is 0, the
  604. * interface is chosen automatically.
  605. * \param group a pointer to the address of the group to join.
  606. * \param source a pointer to the address of the source from which to receive
  607. * data.
  608. *
  609. * \returns 0 on success, or -1 on error. In the latter case, the error number
  610. * can be obtained with `get_errnum()`.
  611. *
  612. * \see io_sock_mcast_join_source_group()
  613. */
  614. LELY_IO_EXTERN int io_sock_mcast_join_source_group(io_handle_t handle,
  615. unsigned int index, const io_addr_t *group,
  616. const io_addr_t *source);
  617. /*!
  618. * Leaves a source-specific multicast group.
  619. *
  620. * \param handle a valid IPv4 or IPv6 connectionless socket device handle.
  621. * \param index a network interface index. On Linux, if \a index is 0, the
  622. * interface is chosen automatically.
  623. * \param group a pointer to the address of the group to leave.
  624. * \param source a pointer to the address of the source from which data was
  625. * received.
  626. *
  627. * \returns 0 on success, or -1 on error. In the latter case, the error number
  628. * can be obtained with `get_errnum()`.
  629. *
  630. * \see io_sock_mcast_leave_source_group()
  631. */
  632. LELY_IO_EXTERN int io_sock_mcast_leave_source_group(io_handle_t handle,
  633. unsigned int index, const io_addr_t *group,
  634. const io_addr_t *source);
  635. #ifdef __cplusplus
  636. }
  637. #endif
  638. #endif