@@ -23,12 +23,12 @@ use windows_sys::Win32::Foundation::{SetHandleInformation, HANDLE, HANDLE_FLAG_I
2323use windows_sys:: Win32 :: Networking :: WinSock :: {
2424 self , tcp_keepalive, FIONBIO , IN6_ADDR , IN6_ADDR_0 , INVALID_SOCKET , IN_ADDR , IN_ADDR_0 ,
2525 POLLERR , POLLHUP , POLLRDNORM , POLLWRNORM , SD_BOTH , SD_RECEIVE , SD_SEND , SIO_KEEPALIVE_VALS ,
26- SOCKET_ERROR , WSABUF , WSAEMSGSIZE , WSAESHUTDOWN , WSAPOLLFD , WSAPROTOCOL_INFOW ,
27- WSA_FLAG_NO_HANDLE_INHERIT , WSA_FLAG_OVERLAPPED ,
26+ SOCKET_ERROR , SO_PROTOCOL_INFOW , WSABUF , WSAEMSGSIZE , WSAESHUTDOWN , WSAPOLLFD ,
27+ WSAPROTOCOL_INFOW , WSA_FLAG_NO_HANDLE_INHERIT , WSA_FLAG_OVERLAPPED ,
2828} ;
2929use windows_sys:: Win32 :: System :: Threading :: INFINITE ;
3030
31- use crate :: { MsgHdr , RecvFlags , SockAddr , TcpKeepalive , Type } ;
31+ use crate :: { MsgHdr , Protocol , RecvFlags , SockAddr , TcpKeepalive , Type } ;
3232
3333#[ allow( non_camel_case_types) ]
3434pub ( crate ) type c_int = std:: os:: raw:: c_int ;
@@ -920,6 +920,19 @@ impl crate::Socket {
920920 Ok ( ( ) )
921921 }
922922 }
923+
924+ /// Returns the [`Protocol`] of this socket by checking the `SO_PROTOCOL_INFOW`
925+ /// option on this socket.
926+ #[ cfg( feature = "all" ) ]
927+ pub fn protocol ( & self ) -> io:: Result < Option < Protocol > > {
928+ let info = unsafe {
929+ getsockopt :: < WSAPROTOCOL_INFOW > ( self . as_raw ( ) , SOL_SOCKET , SO_PROTOCOL_INFOW ) ?
930+ } ;
931+ match info. iProtocol {
932+ 0 => Ok ( None ) ,
933+ p => Ok ( Some ( Protocol :: from ( p) ) ) ,
934+ }
935+ }
923936}
924937
925938#[ cfg_attr( docsrs, doc( cfg( windows) ) ) ]
0 commit comments