File tree Expand file tree Collapse file tree 3 files changed +34
-2
lines changed Expand file tree Collapse file tree 3 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -762,6 +762,28 @@ impl Type {
762
762
}
763
763
}
764
764
765
+ impl :: Protocol {
766
+ /// Protocol corresponding to `ICMPv4`
767
+ pub fn icmpv4 ( ) -> Self {
768
+ :: Protocol ( sys:: IPPROTO_ICMP )
769
+ }
770
+
771
+ /// Protocol corresponding to `ICMPv6`
772
+ pub fn icmpv6 ( ) -> Self {
773
+ :: Protocol ( sys:: IPPROTO_ICMPV6 )
774
+ }
775
+
776
+ /// Protocol corresponding to `TCP`
777
+ pub fn tcp ( ) -> Self {
778
+ :: Protocol ( sys:: IPPROTO_TCP )
779
+ }
780
+
781
+ /// Protocol corresponding to `UDP`
782
+ pub fn udp ( ) -> Self {
783
+ :: Protocol ( sys:: IPPROTO_UDP )
784
+ }
785
+ }
786
+
765
787
impl From < i32 > for Type {
766
788
fn from ( a : i32 ) -> Type {
767
789
Type ( a)
Original file line number Diff line number Diff line change @@ -62,6 +62,11 @@ cfg_if! {
62
62
use SockAddr ;
63
63
use utils:: One ;
64
64
65
+ pub const IPPROTO_ICMP : i32 = libc:: IPPROTO_ICMP ;
66
+ pub const IPPROTO_ICMPV6 : i32 = libc:: IPPROTO_ICMPV6 ;
67
+ pub const IPPROTO_TCP : i32 = libc:: IPPROTO_TCP ;
68
+ pub const IPPROTO_UDP : i32 = libc:: IPPROTO_UDP ;
69
+
65
70
#[ macro_use]
66
71
#[ cfg( target_os = "linux" ) ]
67
72
mod weak;
Original file line number Diff line number Diff line change @@ -34,6 +34,11 @@ const SD_SEND: c_int = 1;
34
34
const SIO_KEEPALIVE_VALS : DWORD = 0x98000004 ;
35
35
const WSA_FLAG_OVERLAPPED : DWORD = 0x01 ;
36
36
37
+ pub const IPPROTO_ICMP : i32 = ws2def:: IPPROTO_ICMP . 0 as i32 ;
38
+ pub const IPPROTO_ICMPV6 : i32 = ws2def:: IPPROTO_ICMPV6 . 0 as i32 ;
39
+ pub const IPPROTO_TCP : i32 = ws2def:: IPPROTO_TCP . 0 as i32 ;
40
+ pub const IPPROTO_UDP : i32 = ws2def:: IPPROTO_UDP . 0 as i32 ;
41
+
37
42
#[ repr( C ) ]
38
43
struct tcp_keepalive {
39
44
onoff : c_ulong ,
@@ -420,15 +425,15 @@ impl Socket {
420
425
421
426
pub fn nodelay ( & self ) -> io:: Result < bool > {
422
427
unsafe {
423
- let raw: c_int = self . getsockopt ( IPPROTO_TCP . 0 as c_int ,
428
+ let raw: c_int = self . getsockopt ( IPPROTO_TCP ,
424
429
TCP_NODELAY ) ?;
425
430
Ok ( raw != 0 )
426
431
}
427
432
}
428
433
429
434
pub fn set_nodelay ( & self , nodelay : bool ) -> io:: Result < ( ) > {
430
435
unsafe {
431
- self . setsockopt ( IPPROTO_TCP . 0 as c_int ,
436
+ self . setsockopt ( IPPROTO_TCP ,
432
437
TCP_NODELAY ,
433
438
nodelay as c_int )
434
439
}
You can’t perform that action at this time.
0 commit comments