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 {
762762 }
763763}
764764
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+
765787impl From < i32 > for Type {
766788 fn from ( a : i32 ) -> Type {
767789 Type ( a)
Original file line number Diff line number Diff line change @@ -62,6 +62,11 @@ cfg_if! {
6262use SockAddr ;
6363use utils:: One ;
6464
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+
6570#[ macro_use]
6671#[ cfg( target_os = "linux" ) ]
6772mod weak;
Original file line number Diff line number Diff line change @@ -34,6 +34,11 @@ const SD_SEND: c_int = 1;
3434const SIO_KEEPALIVE_VALS : DWORD = 0x98000004 ;
3535const WSA_FLAG_OVERLAPPED : DWORD = 0x01 ;
3636
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+
3742#[ repr( C ) ]
3843struct tcp_keepalive {
3944 onoff : c_ulong ,
@@ -420,15 +425,15 @@ impl Socket {
420425
421426 pub fn nodelay ( & self ) -> io:: Result < bool > {
422427 unsafe {
423- let raw: c_int = self . getsockopt ( IPPROTO_TCP . 0 as c_int ,
428+ let raw: c_int = self . getsockopt ( IPPROTO_TCP ,
424429 TCP_NODELAY ) ?;
425430 Ok ( raw != 0 )
426431 }
427432 }
428433
429434 pub fn set_nodelay ( & self , nodelay : bool ) -> io:: Result < ( ) > {
430435 unsafe {
431- self . setsockopt ( IPPROTO_TCP . 0 as c_int ,
436+ self . setsockopt ( IPPROTO_TCP ,
432437 TCP_NODELAY ,
433438 nodelay as c_int )
434439 }
You can’t perform that action at this time.
0 commit comments