2 // Mono.Posix.UnixEndPoint: EndPoint derived class for AF_UNIX family sockets.
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (C) 2003 Ximian, Inc (http://www.ximian.com)
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
32 using System
.Net
.Sockets
;
38 [Obsolete ("Use Mono.Unix.UnixEndPoint")]
39 public class UnixEndPoint
: EndPoint
43 public UnixEndPoint (string filename
)
46 throw new ArgumentNullException ("filename");
49 throw new ArgumentException ("Cannot be empty.", "filename");
50 this.filename
= filename
;
53 public string Filename
{
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
];
99 public override string ToString() {
103 public override int GetHashCode ()
105 return filename
.GetHashCode ();
108 public override bool Equals (object o
)
110 UnixEndPoint other
= o
as UnixEndPoint
;
114 return (other
.filename
== filename
);