The Labs \ Source Viewer \ SSCLI \ System.Net.Sockets \ IPPacketInformation

  1. //------------------------------------------------------------------------------
  2. // <copyright file="IPPacketInformation.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. namespace System.Net.Sockets
  16. {
  17.     using System.Net;
  18.    
  19.     public struct IPPacketInformation
  20.     {
  21.         IPAddress address;
  22.         int networkInterface;
  23.        
  24.         internal IPPacketInformation(IPAddress address, int networkInterface)
  25.         {
  26.             this.address = address;
  27.             this.networkInterface = networkInterface;
  28.         }
  29.        
  30.         public IPAddress Address {
  31.             get { return address; }
  32.         }
  33.        
  34.         public int Interface {
  35.             get { return networkInterface; }
  36.         }
  37.        
  38.         public static bool operator ==(IPPacketInformation packetInformation1, IPPacketInformation packetInformation2)
  39.         {
  40.             return packetInformation1.Equals(packetInformation2);
  41.         }
  42.        
  43.         public static bool operator !=(IPPacketInformation packetInformation1, IPPacketInformation packetInformation2)
  44.         {
  45.             return !packetInformation1.Equals(packetInformation2);
  46.         }
  47.        
  48.         public override bool Equals(object comparand)
  49.         {
  50.             if ((object)comparand == null) {
  51.                 return false;
  52.             }
  53.            
  54.             if (!(comparand is IPPacketInformation))
  55.                 return false;
  56.            
  57.             IPPacketInformation obj = (IPPacketInformation)comparand;
  58.            
  59.             if (address.Equals(obj.address) && networkInterface == obj.networkInterface)
  60.                 return (true);
  61.            
  62.             return false;
  63.         }
  64.        
  65.         public override int GetHashCode()
  66.         {
  67.             return address.GetHashCode() + networkInterface.GetHashCode();
  68.         }
  69.        
  70.     }
  71.     // enum SocketFlags
  72. }

Developer Fusion