@@ -452,76 +452,7 @@ public static unsafe IPPacketInformation GetIPPacketInformation(Interop.Winsock.
452452
453453 public static unsafe SocketError ReceiveMessageFrom ( Socket socket , SafeSocketHandle handle , byte [ ] buffer , int offset , int size , ref SocketFlags socketFlags , Internals . SocketAddress socketAddress , out Internals . SocketAddress receiveAddress , out IPPacketInformation ipPacketInformation , out int bytesTransferred )
454454 {
455- bool ipv4 , ipv6 ;
456- Socket . GetIPProtocolInformation ( socket . AddressFamily , socketAddress , out ipv4 , out ipv6 ) ;
457-
458- bytesTransferred = 0 ;
459- receiveAddress = socketAddress ;
460- ipPacketInformation = default ( IPPacketInformation ) ;
461- fixed ( byte * ptrBuffer = buffer )
462- fixed ( byte * ptrSocketAddress = socketAddress . Buffer )
463- {
464- Interop . Winsock . WSAMsg wsaMsg ;
465- wsaMsg . socketAddress = ( IntPtr ) ptrSocketAddress ;
466- wsaMsg . addressLength = ( uint ) socketAddress . Size ;
467- wsaMsg . flags = socketFlags ;
468-
469- WSABuffer wsaBuffer ;
470- wsaBuffer . Length = size ;
471- wsaBuffer . Pointer = ( IntPtr ) ( ptrBuffer + offset ) ;
472- wsaMsg . buffers = ( IntPtr ) ( & wsaBuffer ) ;
473- wsaMsg . count = 1 ;
474-
475- if ( ipv4 )
476- {
477- Interop . Winsock . ControlData controlBuffer ;
478- wsaMsg . controlBuffer . Pointer = ( IntPtr ) ( & controlBuffer ) ;
479- wsaMsg . controlBuffer . Length = sizeof ( Interop . Winsock . ControlData ) ;
480-
481- if ( socket . WSARecvMsgBlocking (
482- handle ,
483- ( IntPtr ) ( & wsaMsg ) ,
484- out bytesTransferred ) == SocketError . SocketError )
485- {
486- return GetLastSocketError ( ) ;
487- }
488-
489- ipPacketInformation = GetIPPacketInformation ( & controlBuffer ) ;
490- }
491- else if ( ipv6 )
492- {
493- Interop . Winsock . ControlDataIPv6 controlBuffer ;
494- wsaMsg . controlBuffer . Pointer = ( IntPtr ) ( & controlBuffer ) ;
495- wsaMsg . controlBuffer . Length = sizeof ( Interop . Winsock . ControlDataIPv6 ) ;
496-
497- if ( socket . WSARecvMsgBlocking (
498- handle ,
499- ( IntPtr ) ( & wsaMsg ) ,
500- out bytesTransferred ) == SocketError . SocketError )
501- {
502- return GetLastSocketError ( ) ;
503- }
504-
505- ipPacketInformation = GetIPPacketInformation ( & controlBuffer ) ;
506- }
507- else
508- {
509- wsaMsg . controlBuffer . Pointer = IntPtr . Zero ;
510- wsaMsg . controlBuffer . Length = 0 ;
511-
512- if ( socket . WSARecvMsgBlocking (
513- handle ,
514- ( IntPtr ) ( & wsaMsg ) ,
515- out bytesTransferred ) == SocketError . SocketError )
516- {
517- return GetLastSocketError ( ) ;
518- }
519- }
520-
521- socketFlags = wsaMsg . flags ;
522- }
523-
524- return SocketError . Success ;
455+ return ReceiveMessageFrom ( socket , handle , new Span < byte > ( buffer , offset , size ) , ref socketFlags , socketAddress , out receiveAddress , out ipPacketInformation , out bytesTransferred ) ;
525456 }
526457
527458 public static unsafe SocketError ReceiveMessageFrom ( Socket socket , SafeSocketHandle handle , Span < byte > buffer , ref SocketFlags socketFlags , Internals . SocketAddress socketAddress , out Internals . SocketAddress receiveAddress , out IPPacketInformation ipPacketInformation , out int bytesTransferred )
0 commit comments