@@ -57,12 +57,16 @@ pub(crate) use libc::c_int;
57
57
// Used in `Domain`.
58
58
pub ( crate ) use libc:: { AF_INET , AF_INET6 , AF_UNIX } ;
59
59
// Used in `Type`.
60
+ #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
61
+ pub ( crate ) use libc:: SOCK_DCCP ;
60
62
#[ cfg( all( feature = "all" , not( target_os = "redox" ) ) ) ]
61
63
pub ( crate ) use libc:: SOCK_RAW ;
62
64
#[ cfg( feature = "all" ) ]
63
65
pub ( crate ) use libc:: SOCK_SEQPACKET ;
64
66
pub ( crate ) use libc:: { SOCK_DGRAM , SOCK_STREAM } ;
65
67
// Used in `Protocol`.
68
+ #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
69
+ pub ( crate ) use libc:: IPPROTO_DCCP ;
66
70
#[ cfg( target_os = "linux" ) ]
67
71
pub ( crate ) use libc:: IPPROTO_MPTCP ;
68
72
#[ cfg( all( feature = "all" , any( target_os = "freebsd" , target_os = "linux" ) ) ) ]
@@ -382,6 +386,8 @@ impl_debug!(
382
386
Type ,
383
387
libc:: SOCK_STREAM ,
384
388
libc:: SOCK_DGRAM ,
389
+ #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
390
+ libc:: SOCK_DCCP ,
385
391
#[ cfg( not( target_os = "redox" ) ) ]
386
392
libc:: SOCK_RAW ,
387
393
#[ cfg( not( any( target_os = "redox" , target_os = "haiku" ) ) ) ]
@@ -419,6 +425,8 @@ impl_debug!(
419
425
libc:: IPPROTO_UDP ,
420
426
#[ cfg( target_os = "linux" ) ]
421
427
libc:: IPPROTO_MPTCP ,
428
+ #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
429
+ libc:: IPPROTO_DCCP ,
422
430
#[ cfg( all( feature = "all" , any( target_os = "freebsd" , target_os = "linux" ) ) ) ]
423
431
libc:: IPPROTO_SCTP ,
424
432
) ;
@@ -2213,6 +2221,258 @@ impl crate::Socket {
2213
2221
) )
2214
2222
. map ( |_| ( ) )
2215
2223
}
2224
+
2225
+ /// Set value for the `DCCP_SOCKOPT_SERVICE` option on this socket.
2226
+ ///
2227
+ /// Sets the DCCP service. The specification mandates use of service codes.
2228
+ /// If this socket option is not set, the socket will fall back to 0 (which
2229
+ /// means that no meaningful service code is present). On active sockets
2230
+ /// this is set before [`connect`]. On passive sockets up to 32 service
2231
+ /// codes can be set before calling [`bind`]
2232
+ ///
2233
+ /// [`connect`]: crate::Socket::connect
2234
+ /// [`bind`]: crate::Socket::bind
2235
+ #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
2236
+ #[ cfg_attr( docsrs, doc( cfg( feature = "all" , target_os = "linux" ) ) ) ]
2237
+ pub fn set_dccp_service ( & self , code : u32 ) -> io:: Result < ( ) > {
2238
+ unsafe {
2239
+ setsockopt (
2240
+ self . as_raw ( ) ,
2241
+ libc:: SOL_DCCP ,
2242
+ libc:: DCCP_SOCKOPT_SERVICE ,
2243
+ code,
2244
+ )
2245
+ }
2246
+ }
2247
+
2248
+ /// Get the value of the `DCCP_SOCKOPT_SERVICE` option on this socket.
2249
+ ///
2250
+ /// For more information about this option see [`set_dccp_service`]
2251
+ ///
2252
+ /// [`set_dccp_service`]: crate::Socket::set_dccp_service
2253
+ #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
2254
+ #[ cfg_attr( docsrs, doc( cfg( feature = "all" , target_os = "linux" ) ) ) ]
2255
+ pub fn dccp_service ( & self ) -> io:: Result < u32 > {
2256
+ unsafe { getsockopt ( self . as_raw ( ) , libc:: SOL_DCCP , libc:: DCCP_SOCKOPT_SERVICE ) }
2257
+ }
2258
+
2259
+ /// Set value for the `DCCP_SOCKOPT_CCID` option on this socket.
2260
+ ///
2261
+ /// This option sets both the TX and RX CCIDs at the same time.
2262
+ #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
2263
+ #[ cfg_attr( docsrs, doc( cfg( feature = "all" , target_os = "linux" ) ) ) ]
2264
+ pub fn set_dccp_ccid ( & self , ccid : u8 ) -> io:: Result < ( ) > {
2265
+ unsafe { setsockopt ( self . as_raw ( ) , libc:: SOL_DCCP , libc:: DCCP_SOCKOPT_CCID , ccid) }
2266
+ }
2267
+
2268
+ /// Get the value of the `DCCP_SOCKOPT_TX_CCID` option on this socket.
2269
+ ///
2270
+ /// For more information about this option see [`set_dccp_ccid`].
2271
+ ///
2272
+ /// [`set_dccp_ccid`]: crate::Socket::set_dccp_ccid
2273
+ #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
2274
+ #[ cfg_attr( docsrs, doc( cfg( feature = "all" , target_os = "linux" ) ) ) ]
2275
+ pub fn dccp_tx_ccid ( & self ) -> io:: Result < u32 > {
2276
+ unsafe { getsockopt ( self . as_raw ( ) , libc:: SOL_DCCP , libc:: DCCP_SOCKOPT_TX_CCID ) }
2277
+ }
2278
+
2279
+ /// Get the value of the `DCCP_SOCKOPT_RX_CCID` option on this socket.
2280
+ ///
2281
+ /// For more information about this option see [`set_dccp_ccid`].
2282
+ ///
2283
+ /// [`set_dccp_ccid`]: crate::Socket::set_dccp_ccid
2284
+ #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
2285
+ #[ cfg_attr( docsrs, doc( cfg( feature = "all" , target_os = "linux" ) ) ) ]
2286
+ pub fn dccp_xx_ccid ( & self ) -> io:: Result < u32 > {
2287
+ unsafe { getsockopt ( self . as_raw ( ) , libc:: SOL_DCCP , libc:: DCCP_SOCKOPT_RX_CCID ) }
2288
+ }
2289
+
2290
+ /// Set value for the `DCCP_SOCKOPT_SERVER_TIMEWAIT` option on this socket.
2291
+ ///
2292
+ /// Enables a listening socket to hold timewait state when closing the
2293
+ /// connection. This option must be set after `accept` returns.
2294
+ #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
2295
+ #[ cfg_attr( docsrs, doc( cfg( feature = "all" , target_os = "linux" ) ) ) ]
2296
+ pub fn set_dccp_server_timewait ( & self , hold_timewait : bool ) -> io:: Result < ( ) > {
2297
+ unsafe {
2298
+ setsockopt (
2299
+ self . as_raw ( ) ,
2300
+ libc:: SOL_DCCP ,
2301
+ libc:: DCCP_SOCKOPT_SERVER_TIMEWAIT ,
2302
+ hold_timewait as c_int ,
2303
+ )
2304
+ }
2305
+ }
2306
+
2307
+ /// Get the value of the `DCCP_SOCKOPT_SERVER_TIMEWAIT` option on this socket.
2308
+ ///
2309
+ /// For more information see [`set_dccp_server_timewait`]
2310
+ ///
2311
+ /// [`set_dccp_server_timewait`]: crate::Socket::set_dccp_server_timewait
2312
+ #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
2313
+ #[ cfg_attr( docsrs, doc( cfg( feature = "all" , target_os = "linux" ) ) ) ]
2314
+ pub fn dccp_server_timewait ( & self ) -> io:: Result < bool > {
2315
+ unsafe {
2316
+ getsockopt (
2317
+ self . as_raw ( ) ,
2318
+ libc:: SOL_DCCP ,
2319
+ libc:: DCCP_SOCKOPT_SERVER_TIMEWAIT ,
2320
+ )
2321
+ }
2322
+ }
2323
+
2324
+ /// Set value for the `DCCP_SOCKOPT_SEND_CSCOV` option on this socket.
2325
+ ///
2326
+ /// Both this option and `DCCP_SOCKOPT_RECV_CSCOV` are used for setting the
2327
+ /// partial checksum coverage. The default is that checksums always cover
2328
+ /// the entire packet and that only fully covered application data is
2329
+ /// accepted by the receiver. Hence, when using this feature on the sender,
2330
+ /// it must be enabled at the receiver too, with suitable choice of CsCov.
2331
+ #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
2332
+ #[ cfg_attr( docsrs, doc( cfg( feature = "all" , target_os = "linux" ) ) ) ]
2333
+ pub fn set_dccp_send_cscov ( & self , level : u32 ) -> io:: Result < ( ) > {
2334
+ unsafe {
2335
+ setsockopt (
2336
+ self . as_raw ( ) ,
2337
+ libc:: SOL_DCCP ,
2338
+ libc:: DCCP_SOCKOPT_SEND_CSCOV ,
2339
+ level,
2340
+ )
2341
+ }
2342
+ }
2343
+
2344
+ /// Get the value of the `DCCP_SOCKOPT_SEND_CSCOV` option on this socket.
2345
+ ///
2346
+ /// For more information on this option see [`set_dccp_send_cscov`].
2347
+ ///
2348
+ /// [`set_dccp_send_cscov`]: crate::Socket::set_dccp_send_cscov
2349
+ #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
2350
+ #[ cfg_attr( docsrs, doc( cfg( feature = "all" , target_os = "linux" ) ) ) ]
2351
+ pub fn dccp_send_cscov ( & self ) -> io:: Result < u32 > {
2352
+ unsafe { getsockopt ( self . as_raw ( ) , libc:: SOL_DCCP , libc:: DCCP_SOCKOPT_SEND_CSCOV ) }
2353
+ }
2354
+
2355
+ /// Set the value of the `DCCP_SOCKOPT_RECV_CSCOV` option on this socket.
2356
+ ///
2357
+ /// This option is only useful when combined with [`set_dccp_send_cscov`].
2358
+ ///
2359
+ /// [`set_dccp_send_cscov`]: crate::Socket::set_dccp_send_cscov
2360
+ #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
2361
+ #[ cfg_attr( docsrs, doc( cfg( feature = "all" , target_os = "linux" ) ) ) ]
2362
+ pub fn set_dccp_recv_cscov ( & self , level : u32 ) -> io:: Result < ( ) > {
2363
+ unsafe {
2364
+ setsockopt (
2365
+ self . as_raw ( ) ,
2366
+ libc:: SOL_DCCP ,
2367
+ libc:: DCCP_SOCKOPT_RECV_CSCOV ,
2368
+ level,
2369
+ )
2370
+ }
2371
+ }
2372
+
2373
+ /// Get the value of the `DCCP_SOCKOPT_RECV_CSCOV` option on this socket.
2374
+ ///
2375
+ /// For more information on this option see [`set_dccp_recv_cscov`].
2376
+ ///
2377
+ /// [`set_dccp_recv_cscov`]: crate::Socket::set_dccp_recv_cscov
2378
+ #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
2379
+ #[ cfg_attr( docsrs, doc( cfg( feature = "all" , target_os = "linux" ) ) ) ]
2380
+ pub fn dccp_recv_cscov ( & self ) -> io:: Result < u32 > {
2381
+ unsafe { getsockopt ( self . as_raw ( ) , libc:: SOL_DCCP , libc:: DCCP_SOCKOPT_RECV_CSCOV ) }
2382
+ }
2383
+
2384
+ /// Set value for the `DCCP_SOCKOPT_QPOLICY_TXQLEN` option on this socket.
2385
+ ///
2386
+ /// This option sets the maximum length of the output queue. A zero value is
2387
+ /// interpreted as unbounded queue length.
2388
+ #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
2389
+ #[ cfg_attr( docsrs, doc( cfg( feature = "all" , target_os = "linux" ) ) ) ]
2390
+ pub fn set_dccp_qpolicy_txqlen ( & self , length : u32 ) -> io:: Result < ( ) > {
2391
+ unsafe {
2392
+ setsockopt (
2393
+ self . as_raw ( ) ,
2394
+ libc:: SOL_DCCP ,
2395
+ libc:: DCCP_SOCKOPT_QPOLICY_TXQLEN ,
2396
+ length,
2397
+ )
2398
+ }
2399
+ }
2400
+
2401
+ /// Get the value of the `DCCP_SOCKOPT_QPOLICY_TXQLEN` on this socket.
2402
+ ///
2403
+ /// For more information on this option see [`set_dccp_qpolicy_txqlen`].
2404
+ ///
2405
+ /// [`set_dccp_qpolicy_txqlen`]: crate::Socket::set_dccp_qpolicy_txqlen
2406
+ #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
2407
+ #[ cfg_attr( docsrs, doc( cfg( feature = "all" , target_os = "linux" ) ) ) ]
2408
+ pub fn dccp_qpolicy_txqlen ( & self ) -> io:: Result < u32 > {
2409
+ unsafe {
2410
+ getsockopt (
2411
+ self . as_raw ( ) ,
2412
+ libc:: SOL_DCCP ,
2413
+ libc:: DCCP_SOCKOPT_QPOLICY_TXQLEN ,
2414
+ )
2415
+ }
2416
+ }
2417
+
2418
+ /// Get the value of the `DCCP_SOCKOPT_AVAILABLE_CCIDS` option on this socket.
2419
+ ///
2420
+ /// Returns the list of CCIDs supported by the endpoint.
2421
+ ///
2422
+ /// The parameter `N` is used to get the maximum number of supported
2423
+ /// endpoints. The [documentation] recommends a minimum of four at the time
2424
+ /// of writing.
2425
+ ///
2426
+ /// [documentation]: https://www.kernel.org/doc/html/latest/networking/dccp.html
2427
+ #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
2428
+ #[ cfg_attr( docsrs, doc( cfg( feature = "all" , target_os = "linux" ) ) ) ]
2429
+ pub fn dccp_available_ccids < const N : usize > ( & self ) -> io:: Result < CcidEndpoints < N > > {
2430
+ let mut endpoints = [ 0 ; N ] ;
2431
+ let mut length = endpoints. len ( ) as libc:: socklen_t ;
2432
+ syscall ! ( getsockopt(
2433
+ self . as_raw( ) ,
2434
+ libc:: SOL_DCCP ,
2435
+ libc:: DCCP_SOCKOPT_AVAILABLE_CCIDS ,
2436
+ endpoints. as_mut_ptr( ) . cast( ) ,
2437
+ & mut length,
2438
+ ) ) ?;
2439
+ Ok ( CcidEndpoints { endpoints, length } )
2440
+ }
2441
+
2442
+ /// Get the value of the `DCCP_SOCKOPT_GET_CUR_MPS` option on this socket.
2443
+ ///
2444
+ /// This option retrieves the current maximum packet size (application
2445
+ /// payload size) in bytes.
2446
+ #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
2447
+ #[ cfg_attr( docsrs, doc( cfg( feature = "all" , target_os = "linux" ) ) ) ]
2448
+ pub fn dccp_cur_mps ( & self ) -> io:: Result < u32 > {
2449
+ unsafe {
2450
+ getsockopt (
2451
+ self . as_raw ( ) ,
2452
+ libc:: SOL_DCCP ,
2453
+ libc:: DCCP_SOCKOPT_GET_CUR_MPS ,
2454
+ )
2455
+ }
2456
+ }
2457
+ }
2458
+
2459
+ /// See [`Socket::dccp_available_ccids`].
2460
+ #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
2461
+ #[ cfg_attr( docsrs, doc( cfg( feature = "all" , target_os = "linux" ) ) ) ]
2462
+ #[ derive( Debug ) ]
2463
+ pub struct CcidEndpoints < const N : usize > {
2464
+ endpoints : [ u8 ; N ] ,
2465
+ length : u32 ,
2466
+ }
2467
+
2468
+ #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
2469
+ #[ cfg_attr( docsrs, doc( cfg( feature = "all" , target_os = "linux" ) ) ) ]
2470
+ impl < const N : usize > std:: ops:: Deref for CcidEndpoints < N > {
2471
+ type Target = [ u8 ] ;
2472
+
2473
+ fn deref ( & self ) -> & [ u8 ] {
2474
+ & self . endpoints [ 0 ..self . length as usize ]
2475
+ }
2216
2476
}
2217
2477
2218
2478
#[ cfg_attr( docsrs, doc( cfg( unix) ) ) ]
0 commit comments