2 // Mono.Unix.AbstractUnixEndPoint: EndPoint derived class for AF_UNIX family sockets.
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 // Alp Toker (alp@atoker.com)
8 // (C) 2003 Ximian, Inc (http://www.ximian.com)
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System
.Net
.Sockets
;
40 public class AbstractUnixEndPoint
: EndPoint
44 public AbstractUnixEndPoint (string path
)
47 throw new ArgumentNullException ("path");
50 throw new ArgumentException ("Cannot be empty.", "path");
63 public override AddressFamily AddressFamily
{
64 get { return AddressFamily.Unix; }
67 public override EndPoint
Create (SocketAddress socketAddress
)
70 * Should also check this
72 int addr = (int) AddressFamily.Unix;
73 if (socketAddress [0] != (addr & 0xFF))
74 throw new ArgumentException ("socketAddress is not a unix socket address.");
76 if (socketAddress [1] != ((addr & 0xFF00) >> 8))
77 throw new ArgumentException ("socketAddress is not a unix socket address.");
80 byte [] bytes
= new byte [socketAddress
.Size
- 2 - 1];
81 for (int i
= 0; i
< bytes
.Length
; i
++) {
82 bytes
[i
] = socketAddress
[2 + 1 + i
];
85 string name
= Encoding
.Default
.GetString (bytes
);
86 return new AbstractUnixEndPoint (name
);
89 public override SocketAddress
Serialize ()
91 byte [] bytes
= Encoding
.Default
.GetBytes (path
);
92 SocketAddress sa
= new SocketAddress (AddressFamily
, 2 + 1 + bytes
.Length
);
93 //NULL prefix denotes the abstract namespace, see unix(7)
94 //in this case, there is no NULL suffix
97 // sa [0] -> family low byte, sa [1] -> family high byte
98 for (int i
= 0; i
< bytes
.Length
; i
++)
99 sa
[i
+ 2 + 1] = bytes
[i
];
104 public override string ToString() {
108 public override int GetHashCode ()
110 return path
.GetHashCode ();
113 public override bool Equals (object o
)
115 AbstractUnixEndPoint other
= o
as AbstractUnixEndPoint
;
119 return (other
.path
== path
);