2010-04-06 Jb Evain <jbevain@novell.com>
[mcs.git] / class / Mono.Posix / Mono.Posix / UnixEndPoint.cs
blob710a5ad5a1d68521199a304dd258db009bbef733
1 //
2 // Mono.Posix.UnixEndPoint: EndPoint derived class for AF_UNIX family sockets.
3 //
4 // Authors:
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (C) 2003 Ximian, Inc (http://www.ximian.com)
8 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System;
31 using System.Net;
32 using System.Net.Sockets;
33 using System.Text;
35 namespace Mono.Posix
37 [Serializable]
38 [Obsolete ("Use Mono.Unix.UnixEndPoint")]
39 public class UnixEndPoint : EndPoint
41 string filename;
43 public UnixEndPoint (string filename)
45 if (filename == null)
46 throw new ArgumentNullException ("filename");
48 if (filename == "")
49 throw new ArgumentException ("Cannot be empty.", "filename");
50 this.filename = filename;
53 public string Filename {
54 get {
55 return(filename);
57 set {
58 filename=value;
62 public override AddressFamily AddressFamily {
63 get { return AddressFamily.Unix; }
66 public override EndPoint Create (SocketAddress socketAddress)
69 * Should also check this
71 int addr = (int) AddressFamily.Unix;
72 if (socketAddress [0] != (addr & 0xFF))
73 throw new ArgumentException ("socketAddress is not a unix socket address.");
75 if (socketAddress [1] != ((addr & 0xFF00) >> 8))
76 throw new ArgumentException ("socketAddress is not a unix socket address.");
79 byte [] bytes = new byte [socketAddress.Size - 2];
80 for (int i = 0; i < bytes.Length; i++) {
81 bytes [i] = socketAddress [i + 2];
84 string name = Encoding.Default.GetString (bytes);
85 return new UnixEndPoint (name);
88 public override SocketAddress Serialize ()
90 byte [] bytes = Encoding.Default.GetBytes (filename);
91 SocketAddress sa = new SocketAddress (AddressFamily, bytes.Length + 2);
92 // sa [0] -> family low byte, sa [1] -> family high byte
93 for (int i = 0; i < bytes.Length; i++)
94 sa [i + 2] = bytes [i];
96 return sa;
99 public override string ToString() {
100 return(filename);
103 public override int GetHashCode ()
105 return filename.GetHashCode ();
108 public override bool Equals (object o)
110 UnixEndPoint other = o as UnixEndPoint;
111 if (other == null)
112 return false;
114 return (other.filename == filename);