public struct Linger {
public int l_onoff;
public int l_linger;
+
+ public override string ToString ()
+ {
+ return string.Format ("{0}, {1}", l_onoff, l_linger);
+ }
}
+ [Map]
+ [StructLayout (LayoutKind.Sequential)]
+ [CLSCompliant (false)]
+ public struct InAddr : IEquatable<InAddr> {
+ public uint s_addr;
+
+ public unsafe InAddr (byte b0, byte b1, byte b2, byte b3)
+ {
+ s_addr = 0;
+ fixed (uint* ptr = &s_addr) {
+ byte* bytePtr = (byte*) ptr;
+ bytePtr[0] = b0;
+ bytePtr[1] = b1;
+ bytePtr[2] = b2;
+ bytePtr[3] = b3;
+ }
+ }
+
+ public unsafe InAddr (byte[] buffer)
+ {
+ if (buffer.Length != 4)
+ throw new ArgumentException ("buffer.Length != 4", "buffer");
+ s_addr = 0;
+ fixed (uint* ptr = &s_addr)
+ Marshal.Copy (buffer, 0, (IntPtr) ptr, 4);
+ }
+
+ public unsafe void CopyFrom (byte[] source, int startIndex)
+ {
+ fixed (uint* ptr = &s_addr)
+ Marshal.Copy (source, startIndex, (IntPtr) ptr, 4);
+ }
+
+ public unsafe void CopyTo (byte[] destination, int startIndex)
+ {
+ fixed (uint* ptr = &s_addr)
+ Marshal.Copy ((IntPtr) ptr, destination, startIndex, 4);
+ }
+
+ public unsafe byte this[int index] {
+ get {
+ if (index < 0 || index >= 4)
+ throw new ArgumentOutOfRangeException ("index", "index < 0 || index >= 4");
+ fixed (uint* ptr = &s_addr)
+ return ((byte*) ptr)[index];
+ }
+ set {
+ if (index < 0 || index >= 4)
+ throw new ArgumentOutOfRangeException ("index", "index < 0 || index >= 4");
+ fixed (uint* ptr = &s_addr)
+ ((byte*) ptr)[index] = value;
+ }
+ }
+
+ public override string ToString ()
+ {
+ return NativeConvert.ToIPAddress (this).ToString ();
+ }
+
+ public override int GetHashCode ()
+ {
+ return s_addr.GetHashCode ();
+ }
+ public override bool Equals (object obj)
+ {
+ if (!(obj is InAddr))
+ return false;
+ return Equals ((InAddr) obj);
+ }
+ public bool Equals (InAddr value)
+ {
+ return s_addr == value.s_addr;
+ }
+ }
+
+ [Map]
+ [StructLayout (LayoutKind.Sequential)]
+ public struct In6Addr : IEquatable<In6Addr> {
+ ulong addr0;
+ ulong addr1;
+
+ public unsafe In6Addr (byte[] buffer)
+ {
+ if (buffer.Length != 16)
+ throw new ArgumentException ("buffer.Length != 16", "buffer");
+ addr0 = addr1 = 0;
+ fixed (ulong* ptr = &addr0)
+ Marshal.Copy (buffer, 0, (IntPtr) ptr, 16);
+ }
+
+ public unsafe void CopyFrom (byte[] source, int startIndex)
+ {
+ fixed (ulong* ptr = &addr0)
+ Marshal.Copy (source, startIndex, (IntPtr) ptr, 16);
+ }
+
+ public unsafe void CopyTo (byte[] destination, int startIndex)
+ {
+ fixed (ulong* ptr = &addr0)
+ Marshal.Copy ((IntPtr) ptr, destination, startIndex, 16);
+ }
+
+ public unsafe byte this[int index] {
+ get {
+ if (index < 0 || index >= 16)
+ throw new ArgumentOutOfRangeException ("index", "index < 0 || index >= 16");
+ fixed (ulong* ptr = &addr0)
+ return ((byte*) ptr)[index];
+ }
+ set {
+ if (index < 0 || index >= 16)
+ throw new ArgumentOutOfRangeException ("index", "index < 0 || index >= 16");
+ fixed (ulong* ptr = &addr0)
+ ((byte*) ptr)[index] = value;
+ }
+ }
+
+ public override string ToString ()
+ {
+ return NativeConvert.ToIPAddress (this).ToString ();
+ }
+
+ public override int GetHashCode ()
+ {
+ return addr0.GetHashCode () ^ addr1.GetHashCode ();
+ }
+ public override bool Equals (object obj)
+ {
+ if (!(obj is In6Addr))
+ return false;
+ return Equals ((In6Addr) obj);
+ }
+ public bool Equals (In6Addr value)
+ {
+ return addr0 == value.addr0 && addr1 == value.addr1;
+ }
+ }
+
#endregion
#region Classes