dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/System/Net EndPoint.cs,1.4,1.5 IPAdd


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/System/Net EndPoint.cs,1.4,1.5 IPAddress.cs,1.9,1.10 IPEndPoint.cs,1.2,1.3 SocketAddress.cs,1.8,1.9
Date: Tue, 27 May 2003 03:54:27 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/System/Net
In directory subversions:/tmp/cvs-serv8822/System/Net

Modified Files:
        EndPoint.cs IPAddress.cs IPEndPoint.cs SocketAddress.cs 
Log Message:


Implement socket address serialization properly; add IPv6 support
to IPEndPoint and IPAddress.


Index: EndPoint.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System/Net/EndPoint.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** EndPoint.cs 26 May 2003 07:43:00 -0000      1.4
--- EndPoint.cs 27 May 2003 07:54:25 -0000      1.5
***************
*** 2,6 ****
   * EndPoint.cs - Implementation of the "System.Net.EndPoint" class.
   *
!  * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
   *
   * This program is free software, you can redistribute it and/or modify
--- 2,6 ----
   * EndPoint.cs - Implementation of the "System.Net.EndPoint" class.
   *
!  * Copyright (C) 2002, 2003  Southern Storm Software, Pty Ltd.
   *
   * This program is free software, you can redistribute it and/or modify
***************
*** 27,32 ****
--- 27,34 ----
  public abstract class EndPoint
  {
+       // Constructor.
        protected EndPoint() {}
        
+       // Create a new end point with a particular socket address.
        public virtual EndPoint Create(SocketAddress socketAddress) 
                        {
***************
*** 34,37 ****
--- 36,40 ----
                        }
        
+       // Serialize this end point into a socket address array.
        public virtual SocketAddress Serialize()
                        {
***************
*** 39,42 ****
--- 42,46 ----
                        }
  
+       // Get the address family of this end point.
        public virtual AddressFamily AddressFamily 
                        { 
***************
*** 47,55 ****
                        }
        
! }; //class EndPoint
! 
! }; //namespace System.Net
! 
! 
! 
  
--- 51,55 ----
                        }
        
! }; // class EndPoint
  
+ }; // namespace System.Net

Index: IPAddress.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System/Net/IPAddress.cs,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** IPAddress.cs        27 Nov 2002 02:53:52 -0000      1.9
--- IPAddress.cs        27 May 2003 07:54:25 -0000      1.10
***************
*** 2,6 ****
   * IPAddress.cs - Implementation of the "System.Net.IPAddress" class.
   *
!  * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
   *
   * Contributions by Gerard Toonstra <address@hidden>
--- 2,6 ----
   * IPAddress.cs - Implementation of the "System.Net.IPAddress" class.
   *
!  * Copyright (C) 2002, 2003  Southern Storm Software, Pty Ltd.
   *
   * Contributions by Gerard Toonstra <address@hidden>
***************
*** 28,38 ****
  using System.Runtime.CompilerServices;
  
  public class IPAddress
  {
  
!       // The IP address is stored in the low 4 bytes of "value_"
!       // in network byte order.
!       private long value_;
  
        public IPAddress(long newAddress)
                        {
--- 28,58 ----
  using System.Runtime.CompilerServices;
  
+ // Note: the IPv6 stuff isn't ECMA-compatible, strictly speaking,
+ // but it is very useful to have it available in ECMA environments.
+ 
  public class IPAddress
  {
+       // Internal state.
+       private AddressFamily family;
+       private long value;
+       internal ushort[] ipv6;
  
!       // Predefined addresses.
!       public static readonly IPAddress Any = new 
IPAddress(0x0000000000000000);
!       public static readonly IPAddress Broadcast =
!                       new IPAddress((long)(uint)HostToNetworkOrder
!                                                       
(unchecked((int)0xFFFFFFFF)));
!       public static readonly IPAddress Loopback =
!                       new 
IPAddress((long)(uint)HostToNetworkOrder(0x7F000001));
!       public static readonly IPAddress None = Broadcast;
!       public static readonly IPAddress IPv6Any =
!                       new IPAddress(new byte [16], 0);
!       public static readonly IPAddress IPv6Loopback =
!                       new IPAddress(new byte[] {0, 0, 0, 0, 0, 0, 0, 0,
!                                                                         0, 0, 
0, 0, 0, 0, 0, 1}, 0);
!       public static readonly IPAddress IPv6None =
!                       new IPAddress(new byte [16], 0);
  
+       // Constructors.
        public IPAddress(long newAddress)
                        {
***************
*** 42,53 ****
                                                ("newAddress", 
S._("Arg_OutOfRange"));
                                }
!                               this.value_ = newAddress;
                        }
  
        public override bool Equals(Object comparand)
                        {
!                               if(comparand is IPAddress)
                                {
!                                       return (value_ == 
((IPAddress)comparand).value_);
                                }
                                else
--- 62,120 ----
                                                ("newAddress", 
S._("Arg_OutOfRange"));
                                }
!                               this.family = AddressFamily.InterNetwork;
!                               this.value = newAddress;
!                               this.ipv6 = null;
!                       }
!       public IPAddress(byte[] address) : this(address, 0) {}
!       public IPAddress(byte[] address, long scopeid)
!                       {
!                               if(address == null)
!                               {
!                                       throw new 
ArgumentNullException("address");
!                               }
!                               else if(address.Length != 16)
!                               {
!                                       throw new ArgumentException
!                                               (S._("Arg_InvalidIPv6Address"));
!                               }
!                               if(scopeid < 0 || scopeid > 
(long)(UInt32.MaxValue))
!                               {
!                                       throw new ArgumentException
!                                               (S._("Arg_InvalidIPv6Scope"));
!                               }
!                               this.family = AddressFamily.InterNetworkV6;
!                               this.value = scopeid;
!                               this.ipv6 = new ushort [8];
!                               int posn;
!                               for(posn = 0; posn < 8; ++posn)
!                               {
!                                       this.ipv6[posn] =
!                                               (ushort)((address[posn * 2] << 
8) |
!                                                                (address[posn 
* 2 + 1]));
!                               }
                        }
  
+       // Determine if two objects are equal.
        public override bool Equals(Object comparand)
                        {
!                               IPAddress other = (comparand as IPAddress);
!                               if(other != null)
                                {
!                                       if(family != other.family || value != 
other.value)
!                                       {
!                                               return false;
!                                       }
!                                       if(ipv6 != null)
!                                       {
!                                               int posn;
!                                               for(posn = 0; posn < 8; ++posn)
!                                               {
!                                                       if(ipv6[posn] != 
other.ipv6[posn])
!                                                       {
!                                                               return false;
!                                                       }
!                                               }
!                                       }
!                                       return true;
                                }
                                else
***************
*** 57,64 ****
                        }
  
        public override int GetHashCode() 
                        {
!                               return unchecked(((int)(value_ ^ (value_ >> 
32)))
!                                                                               
& (int)0x7FFFFFFF);
                        }
  
--- 124,171 ----
                        }
  
+       // Get the bytes of this address.
+       public byte[] GetAddressBytes()
+                       {
+                               byte[] buf;
+                               if(family == AddressFamily.InterNetwork)
+                               {
+                                       int host = 
NetworkToHostOrder((int)value);
+                                       buf = new byte [4];
+                                       buf[0] = (byte)(host >> 24);
+                                       buf[1] = (byte)(host >> 16);
+                                       buf[2] = (byte)(host >> 8);
+                                       buf[3] = (byte)host;
+                                       return buf;
+                               }
+                               else
+                               {
+                                       buf = new byte [16];
+                                       int posn;
+                                       for(posn = 0; posn < 8; ++posn)
+                                       {
+                                               buf[posn * 2] = 
(byte)(ipv6[posn] >> 8);
+                                               buf[posn * 2 + 1] = 
(byte)(ipv6[posn]);
+                                       }
+                                       return buf;
+                               }
+                       }
+ 
+       // Get a hash code for this object.
        public override int GetHashCode() 
                        {
!                               if(family == AddressFamily.InterNetwork)
!                               {
!                                       return unchecked(((int)value) & 
0x7FFFFFFF);
!                               }
!                               else
!                               {
!                                       int hash = 0;
!                                       int posn;
!                                       for(posn = 0; posn < 8; ++posn)
!                                       {
!                                               hash = (hash << 5) + hash + 
ipv6[posn];
!                                       }
!                                       return unchecked((hash ^ (int)value) & 
0x7FFFFFFF);
!                               }
                        }
  
***************
*** 76,81 ****
        public static bool IsLoopback(IPAddress address)
                        {
!                               long mask = 
(long)(uint)HostToNetworkOrder(0x7F000000);
!                               return ((address.value_ & mask) == mask);
                        }
  
--- 183,195 ----
        public static bool IsLoopback(IPAddress address)
                        {
!                               if(address.family == AddressFamily.InterNetwork)
!                               {
!                                       long mask = 
(long)(uint)HostToNetworkOrder(0x7F000000);
!                                       return ((address.value & mask) == mask);
!                               }
!                               else
!                               {
!                                       return address.Equals(IPv6Loopback);
!                               }
                        }
  
***************
*** 90,95 ****
--- 204,212 ----
        extern public static short NetworkToHostOrder(short network);
  
+       [TODO]
        public static IPAddress Parse(String ipString)
                        {
+                               // TODO: ipv6 support
+ 
                                int parsed;
                                String[]  tokenizedString;
***************
*** 135,139 ****
        public override string ToString()
                        {
!                               int host = NetworkToHostOrder((int)value_);
                                return ((host >> 24) & 0xFF).ToString() + "." +
                                           ((host >> 16) & 0xFF).ToString() + 
"." +
--- 252,257 ----
        public override string ToString()
                        {
!                               // TODO: ipv6 support
!                               int host = NetworkToHostOrder((int)value);
                                return ((host >> 24) & 0xFF).ToString() + "." +
                                           ((host >> 16) & 0xFF).ToString() + 
"." +
***************
*** 142,161 ****
                        }
  
!       public static readonly IPAddress Any = new 
IPAddress(0x0000000000000000);
!       public static readonly IPAddress Broadcast =
!                       new IPAddress((long)(uint)HostToNetworkOrder
!                                                       
(unchecked((int)0xFFFFFFFF)));
!       public static readonly IPAddress Loopback =
!                       new 
IPAddress((long)(uint)HostToNetworkOrder(0x7F000001));
!       public static readonly IPAddress None = Broadcast;
! 
        public long Address
                        {
                                get
                                {
!                                       return value_;
                                }
                                set
                                {
                                        if((value < 0) || (value > 
0x00000000FFFFFFFF))
                                        {
--- 260,312 ----
                        }
  
!       // Get or set the IPv4 address.
        public long Address
                        {
                                get
                                {
!                                       if(family == AddressFamily.InterNetwork)
!                                       {
!                                               return value;
!                                       }
!                                       else
!                                       {
!                                               throw new SocketException();
!                                       }
!                               }
!                               set
!                               {
!                                       if(family != AddressFamily.InterNetwork)
!                                       {
!                                               throw new SocketException();
!                                       }
!                                       if((value < 0) || (value > 
0x00000000FFFFFFFF))
!                                       {
!                                               throw new 
ArgumentOutOfRangeException
!                                                       ("newAddress", 
S._("Arg_OutOfRange"));
!                                       }
!                                       this.value = value;
!                               }
!                       }
! 
!       // Get or set the IPv6 scope identifier.
!       public long ScopeId
!                       {
!                               get
!                               {
!                                       if(family == 
AddressFamily.InterNetworkV6)
!                                       {
!                                               return value;
!                                       }
!                                       else
!                                       {
!                                               throw new SocketException();
!                                       }
                                }
                                set
                                {
+                                       if(family != 
AddressFamily.InterNetworkV6)
+                                       {
+                                               throw new SocketException();
+                                       }
                                        if((value < 0) || (value > 
0x00000000FFFFFFFF))
                                        {
***************
*** 163,175 ****
                                                        ("newAddress", 
S._("Arg_OutOfRange"));
                                        }
!                                       value_ = value;
                                }
                        }
!                       
        public AddressFamily AddressFamily
                        {
                                get
                                {
!                                       return AddressFamily.InterNetwork;
                                }
                        }
--- 314,327 ----
                                                        ("newAddress", 
S._("Arg_OutOfRange"));
                                        }
!                                       this.value = value;
                                }
                        }
! 
!       // Get the address family of this IP address.
        public AddressFamily AddressFamily
                        {
                                get
                                {
!                                       return family;
                                }
                        }
***************
*** 178,180 ****
  
  }; // namespace System.Net
- 
--- 330,331 ----

Index: IPEndPoint.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System/Net/IPEndPoint.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** IPEndPoint.cs       21 Apr 2002 03:24:53 -0000      1.2
--- IPEndPoint.cs       27 May 2003 07:54:25 -0000      1.3
***************
*** 2,6 ****
   * IPEndPoint.cs - Implementation of the "System.Net.IPEndPoint" class.
   *
!  * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
   *
   * This program is free software, you can redistribute it and/or modify
--- 2,6 ----
   * IPEndPoint.cs - Implementation of the "System.Net.IPEndPoint" class.
   *
!  * Copyright (C) 2002, 2003  Southern Storm Software, Pty Ltd.
   *
   * This program is free software, you can redistribute it and/or modify
***************
*** 27,158 ****
  public class IPEndPoint : EndPoint
  {
        public const int MinPort = 0;
        public const int MaxPort = 65535;
  
!       private long myaddress;
!       private int myport;
!               
        public IPEndPoint(long address, int port) 
                        {
!                               if (address < 0)
!                                       throw new 
ArgumentOutOfRangeException("address", S._("ArgRange_NonNegative"));
!       
!                               if (port < MinPort || port > MaxPort)
                                        throw new 
ArgumentOutOfRangeException("port");
!                               
!                               myaddress = address;
!                               myport = port;                  
                        }
-       
- 
        public IPEndPoint(IPAddress address, int port)
                        {
!                               if (address == null)
                                        throw new 
ArgumentNullException("address");
!                               
!                               if (port < MinPort || port > MaxPort)
!                                       throw new 
ArgumentOutOfRangeException("port");                                            
      
! 
!                               myaddress = address.Address;
!                               myport = port;  
                        }
  
!       //Create the right IPEndPoint
        public override EndPoint Create(SocketAddress socketAddress) 
                        {
!                               // TODO: needs help
!                       #if false
!                               byte[] addrarray;
!                               byte[] portarray;
!                               String addrstring;
!                               String portstring;
!                                                               
!                               if (socketAddress.Family != 
AddressFamily.InterNetwork)
!                                       throw new 
ArgumentException("socketAddress");
! 
!                               //Bytes 3,4,5,6 are the address, 7,8 the port
!                               for (int x = 2; x == 6; x++)
!                               {
!                                       addrarray[x-2] = socketAddress[x];
!                               }               
!                               
!                               for (int x = 6; x == 8; x++)
!                               {
!                                       portarray[x-6] = socketAddress[x];
!                               }                                               
                                                
!                               
!                               addrstring = new String(addrarray);
!                               portstring = new String(portarray);             
                
!                               
!                               return new IPEndPoint(long.Parse(addrstring), 
int.Parse(portstring));
!                       #endif
!                               return null;
                        }
-       
-       public override bool Equals(object comparand)
-                       {
-                               if(comparand == null)
-                                       return false;
  
!                               if (!(comparand is System.Net.IPEndPoint))
!                                       return false;
!                                       
!                               IPEndPoint point = (IPEndPoint)comparand;
  
!                               if (!(point.myaddress == myaddress && 
!                                       point.myport == myport))
                                        return false;
!                               
!                               return true;                    
                        }
                        
!       [TODO]          
        public override int GetHashCode()
                        {
!                               return myaddress.GetHashCode() + 
myport.GetHashCode();
                        }
!       
        public override String ToString()
                        {
!                               IPAddress tempaddr = new IPAddress(myaddress);
!                               return tempaddr.ToString() + ":" + 
myport.ToString();
                        }
!       
        public IPAddress Address
                        {
                                get
                                {
!                                       return new IPAddress(myaddress);
                                }
                                set
                                {
!                                       myaddress = value.Address;
                                }
                        }
!       
        public override AddressFamily AddressFamily 
                        { 
                                get
                                {
!                                       return AddressFamily.InterNetwork; 
                                }       
                        }
  
        public int Port
                        {
                                get
                                {
!                                       return myport;
                                }
                                set
                                {       
!                                       if (value < MinPort || value > MaxPort)
                                                throw new 
ArgumentOutOfRangeException("port");
!       
!                                       myport = value;                         
                                }
                        }
        
! }; //class IPEndPoint
  
! }; //namespace System.Net
--- 27,233 ----
  public class IPEndPoint : EndPoint
  {
+       // Internal state.
+       private IPAddress address;
+       private int port;
+               
+       // Minimum and maximum port numbers.
        public const int MinPort = 0;
        public const int MaxPort = 65535;
  
!       // Constructors.
        public IPEndPoint(long address, int port) 
                        {
!                               this.address = new IPAddress(address);
!                               if(port < MinPort || port > MaxPort)
!                               {
                                        throw new 
ArgumentOutOfRangeException("port");
!                               }
!                               this.port = port;
                        }
        public IPEndPoint(IPAddress address, int port)
                        {
!                               if(address == null)
!                               {
                                        throw new 
ArgumentNullException("address");
!                               }
!                               if(port < MinPort || port > MaxPort)
!                               {
!                                       throw new 
ArgumentOutOfRangeException("port");
!                               }
!                               this.address = address;
!                               this.port = port;       
                        }
  
!       // Create a new end point with a particular socket address.
        public override EndPoint Create(SocketAddress socketAddress) 
                        {
!                               // Validate the socket address.
!                               if(socketAddress.Family != 
address.AddressFamily)
!                               {
!                                       throw new ArgumentException
!                                               (S._("Arg_InvalidSockAddr"), 
"socketAddress");
!                               }
! 
!                               // Different behaviour for IPv4 and IPv6.
!                               int port;
!                               int value;
!                               if(socketAddress.Family == 
AddressFamily.InterNetwork)
!                               {
!                                       // Validate the address size.
!                                       if(socketAddress.Size < 8)
!                                       {
!                                               throw new ArgumentException
!                                                       
(S._("Arg_InvalidSockAddr"), "socketAddress");
!                                       }
! 
!                                       // Extract the port and address.
!                                       port = (socketAddress[2] << 8) | 
socketAddress[3];
!                                       value = ((socketAddress[7]) |
!                                                        (socketAddress[6] << 
8) |
!                                                        (socketAddress[5] << 
16) |
!                                                        (socketAddress[4] << 
24));
!                                       value = 
IPAddress.HostToNetworkOrder(value);
! 
!                                       // Construct the new end point.
!                                       return new IPEndPoint(new 
IPAddress(value), port);
!                               }
!                               else
!                               {
!                                       // Validate the address size.
!                                       if(socketAddress.Size < 28)
!                                       {
!                                               throw new ArgumentException
!                                                       
(S._("Arg_InvalidSockAddr"), "socketAddress");
!                                       }
! 
!                                       // Extract the port and scope.
!                                       port = (socketAddress[2] << 8) | 
socketAddress[3];
!                                       value = ((socketAddress[27]) |
!                                                        (socketAddress[26] << 
8) |
!                                                        (socketAddress[25] << 
16) |
!                                                        (socketAddress[24] << 
24));
!                                       value = 
IPAddress.HostToNetworkOrder(value);
! 
!                                       // Extract the main part of the IPv6 
address.
!                                       byte[] buf = new byte [16];
!                                       int posn;
!                                       for(posn = 0; posn < 16; ++posn)
!                                       {
!                                               buf[posn] = socketAddress[posn 
+ 8];
!                                       }
! 
!                                       // Construct the new end point.
!                                       return new IPEndPoint(new 
IPAddress(buf, value), port);
!                               }
                        }
  
!       // Serialize this end point into a socket address array.
!       public override SocketAddress Serialize()
!                       {
!                               SocketAddress addr;
!                               if(address.AddressFamily == 
AddressFamily.InterNetwork)
!                               {
!                                       // Serialize an ipv4 address.
!                                       addr = new 
SocketAddress(AddressFamily.InterNetwork, 16);
!                                       addr[2] = (byte)(port >> 8);
!                                       addr[3] = (byte)port;
!                                       int host = IPAddress.NetworkToHostOrder
!                                               ((int)(address.Address));
!                                       addr[4] = (byte)(host >> 24);
!                                       addr[5] = (byte)(host >> 16);
!                                       addr[6] = (byte)(host >> 8);
!                                       addr[7] = (byte)host;
!                                       return addr;
!                               }
!                               else
!                               {
!                                       // Serialize an ipv6 address.
!                                       addr = new 
SocketAddress(AddressFamily.InterNetworkV6, 28);
!                                       addr[2] = (byte)(port >> 8);
!                                       addr[3] = (byte)port;
!                                       ushort[] ipv6 = address.ipv6;
!                                       int posn;
!                                       for(posn = 0; posn < 8; ++posn)
!                                       {
!                                               addr[posn + 8] = 
(byte)(ipv6[posn] >> 8);
!                                               addr[posn + 9] = 
(byte)(ipv6[posn]);
!                                       }
!                                       int scope = IPAddress.NetworkToHostOrder
!                                               ((int)(address.ScopeId));
!                                       addr[24] = (byte)(scope >> 24);
!                                       addr[25] = (byte)(scope >> 16);
!                                       addr[26] = (byte)(scope >> 8);
!                                       addr[27] = (byte)scope;
!                                       return addr;
!                               }
!                       }
  
!       // Determine if two objects are equal.
!       public override bool Equals(object comparand)
!                       {
!                               IPEndPoint other = (comparand as IPEndPoint);
!                               if(other != null)
!                               {
!                                       return (address.Equals(other.address) &&
!                                                       port == other.port);
!                               }
!                               else
!                               {
                                        return false;
!                               }
                        }
                        
!       // Get a hash code for this object.
        public override int GetHashCode()
                        {
!                               return address.GetHashCode() + 
port.GetHashCode();
                        }
! 
!       // Convert this object into a string.
        public override String ToString()
                        {
!                               return address.ToString() + ":" + 
port.ToString();
                        }
! 
!       // Get or set the IP address for this end point.
        public IPAddress Address
                        {
                                get
                                {
!                                       return address;
                                }
                                set
                                {
!                                       address = value;
                                }
                        }
! 
!       // Get the address family for this end point.
        public override AddressFamily AddressFamily 
                        { 
                                get
                                {
!                                       return address.AddressFamily;
                                }       
                        }
  
+       // Get the port for this end point.
        public int Port
                        {
                                get
                                {
!                                       return port;
                                }
                                set
                                {       
!                                       if(value < MinPort || value > MaxPort)
!                                       {
                                                throw new 
ArgumentOutOfRangeException("port");
!                                       }
!                                       port = value;                           
                                }
                        }
        
! }; // class IPEndPoint
  
! }; // namespace System.Net

Index: SocketAddress.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System/Net/SocketAddress.cs,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** SocketAddress.cs    1 Apr 2003 05:15:32 -0000       1.8
--- SocketAddress.cs    27 May 2003 07:54:25 -0000      1.9
***************
*** 2,6 ****
   * SocketAddress.cs - Implementation of the "System.Net.SocketAddress" class.
   *
!  * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
   *
   * This program is free software, you can redistribute it and/or modify
--- 2,6 ----
   * SocketAddress.cs - Implementation of the "System.Net.SocketAddress" class.
   *
!  * Copyright (C) 2002, 2003  Southern Storm Software, Pty Ltd.
   *
   * This program is free software, you can redistribute it and/or modify
***************
*** 21,222 ****
  namespace System.Net
  {
!       
  using System;
  using System.Net.Sockets;
  
  public class SocketAddress
  {
!       private byte[] myarray;
!       private AddressFamily family;   
!       
!       public SocketAddress(AddressFamily family) 
!               : this(family, 32)
!       {
!       }
!               
!       public SocketAddress(AddressFamily family, int size)
!       {
!               this.family = family;
!               if (size < 2) 
!               {
!                               throw new ArgumentOutOfRangeException();
!               }
!               this.myarray = new byte[size];
!       }
!               
!       public override bool Equals(object comparand) 
!       {
!               if (comparand is SocketAddress)
!               {
!                       return ((SocketAddress)comparand).ToString() ==
!                       ToString();
!               }
!               else
!               {
!                       return false;
!               }
  
!       }
  
        public override int GetHashCode()
!       {
!               int hash = 0;
!               int posn;
!               for(posn = 0; posn < myarray.Length; ++posn)
!               {
!                       hash = (hash << 5) + hash + myarray[posn];
!               }
!               return hash;
!       }
!               
!       public override string ToString()
!       {
!               string str;
!               switch(this.family) 
!               {       
!                       case AddressFamily.AppleTalk:
!                               str = "AppleTalk:";
!                               break;
!                       case AddressFamily.Atm:
!                               str = "Atm:";
!                               break;
!                       case AddressFamily.Banyan:
!                               str = "Banyan:";
!                               break;
!                       case AddressFamily.Ccitt:
!                               str = "Ccit:";
!                               break;
!                       case AddressFamily.Chaos:
!                               str = "Chaos:";
!                               break;
!                       case AddressFamily.Cluster:
!                               str = "Cluster:";
!                               break;
!                       case AddressFamily.DataKit:
!                               str = "DataKit:";
!                               break;
!                       case AddressFamily.DataLink:
!                               str = "DataLink:";
!                               break;
!                       case AddressFamily.DecNet:
!                               str = "DecNet:";
!                               break;
!                       case AddressFamily.Ecma:
!                               str = "Ecma:";
!                               break;
!                       case AddressFamily.FireFox:
!                               str = "FireFox:";
!                               break;
!                       case AddressFamily.HyperChannel:
!                               str = "HyperChannel:";
!                               break;
!                       case AddressFamily.Ieee12844:
!                               str = "Ieee12844:";
!                               break;
!                       case AddressFamily.ImpLink:
!                               str = "ImpLink:";
!                               break;          
!                       case AddressFamily.InterNetwork:
!                               str = "InterNetwork:";
!                               break;
!                       case AddressFamily.InterNetworkV6:
!                               str = "InterNetworkV6:";
!                               break;
!                       case AddressFamily.Ipx:
!                               str = "Ipx:";
!                               break;
!                       case AddressFamily.Irda:
!                               str = "Irda:";
!                               break;
!                       case AddressFamily.Iso:
!                               str = "Iso:";
!                               break;
!                       case AddressFamily.NetBios:
!                               str = "NetBios:";
!                               break;
!                       case AddressFamily.NetworkDesigners:
!                               str = "NetworkDesigners:";
!                               break;
!                       case AddressFamily.Pup:
!                               str = "Pup:";
!                               break;
!                       case AddressFamily.Sna:
!                               str = "Sna:";
!                               break;
!                       case AddressFamily.Unix:
!                               str = "Unix:";
!                               break;
!                       case AddressFamily.Unknown:
!                               str = "Unknown:";
!                               break;
!                       case AddressFamily.Unspecified:
!                               str = "Unspecified:";
!                               break;
!                       case AddressFamily.VoiceView:
!                               str = "VoiceView:";
!                               break;
!                       default:
!                               return null;
!               }
!               str += myarray.Length.ToString();
!               str += ':';
!               str += '{';
!               string tmp = String.Empty;
!               foreach(byte x in myarray) 
!               {
!                       tmp += x.ToString();
!                       tmp += ',';
!               }
!               // Got to get rid of trailing ','       
!               tmp = tmp.Substring(0, tmp.Length-1);
!               str += tmp;
!               str += '}';
!               return str;
!       }
!               
!       public AddressFamily Family
!       {
!               get
!               {
!                       return family;
!               }
!       }
!       
!       public byte this[int offset]
!       {
!               get
!               {
!                       return myarray[offset];                         
!               }
!               set
!               {
!                       if (offset < 0 || offset > this.Size)
!                               throw new ArgumentOutOfRangeException("item");
!                               myarray[offset] = value;
!               }
!       }
!       
!       
!       public int Size
!       {
!               get
!               {
!                       return myarray.Length;
!               }
!       }       
! 
! 
!    }
! } // class SocketAddress
! 
! 
! 
! 
! 
! 
! 
  
  
  
  
  
--- 21,138 ----
  namespace System.Net
  {
! 
  using System;
+ using System.Text;
  using System.Net.Sockets;
  
  public class SocketAddress
  {
!       // Internal state.
!       private byte[] array;
  
!       // Constructors.
!       public SocketAddress(AddressFamily family) : this(family, 32) {}
!       public SocketAddress(AddressFamily family, int size)
!                       {
!                               if(size < 2) 
!                               {
!                                       throw new ArgumentOutOfRangeException();
!                               }
!                               array = new byte[size];
!                               array[0] = (byte)family;
!                               array[1] = (byte)(family >> 8);
!                       }
! 
!       // Determine if two objects are equal.
!       public override bool Equals(Object comparand) 
!                       {
!                               SocketAddress other = (comparand as 
SocketAddress);
!                               if(other != null)
!                               {
!                                       if(array.Length != other.array.Length)
!                                       {
!                                               return false;
!                                       }
!                                       int posn = array.Length;
!                                       while(posn > 0)
!                                       {
!                                               --posn;
!                                               if(array[posn] != 
other.array[posn])
!                                               {
!                                                       return false;
!                                               }
!                                       }
!                                       return true;
!                               }
!                               else
!                               {
!                                       return false;
!                               }
!                       }
  
+       // Get a hash code for this object.
        public override int GetHashCode()
!                       {
!                               int hash = 0;
!                               int posn;
!                               for(posn = 0; posn < array.Length; ++posn)
!                               {
!                                       hash = (hash << 5) + hash + array[posn];
!                               }
!                               return hash;
!                       }
! 
!       // Convert this object into a string.
!       public override String ToString()
!                       {
!                               StringBuilder builder = new StringBuilder();
!                               builder.Append(Family.ToString());
!                               builder.Append(String.Format(":{0}:{", Size));
!                               int posn = 2;
!                               while(posn < array.Length)
!                               {
!                                       if(posn > 2)
!                                       {
!                                               builder.Append(',');
!                                       }
!                                       builder.Append(array[posn].ToString());
!                                       ++posn;
!                               }
!                               builder.Append('}');
!                               return builder.ToString();
!                       }
  
+       // Get the address family from the socket address.
+       public AddressFamily Family
+                       {
+                               get
+                               {
+                                       return (AddressFamily)(array[0] | 
(array[1] << 8));
+                               }
+                       }
  
+       // Get or set a specific address element.
+       public byte this[int offset]
+                       {
+                               get
+                               {
+                                       return array[offset];
+                               }
+                               set
+                               {
+                                       array[offset] = value;
+                               }
+                       }
  
+       // Get the size of the socket address.
+       public int Size
+                       {
+                               get
+                               {
+                                       return array.Length;
+                               }
+                       }
  
+ }; // class SocketAddress
  
+ }; // namespace System.Net





reply via email to

[Prev in Thread] Current Thread [Next in Thread]