Mono.Zeroconf – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | // Copyright 2006 Alp Toker <alp@atoker.com> |
2 | // This software is made available under the MIT License |
||
3 | // See COPYING for details |
||
4 | |||
5 | using System; |
||
6 | using System.IO; |
||
7 | using System.Net; |
||
8 | using System.Net.Sockets; |
||
9 | |||
10 | using Mono.Unix; |
||
11 | using Mono.Unix.Native; |
||
12 | |||
13 | namespace NDesk.DBus.Transports |
||
14 | { |
||
15 | class UnixMonoTransport : UnixTransport |
||
16 | { |
||
17 | protected Socket socket; |
||
18 | |||
19 | public override void Open (string path, bool @abstract) |
||
20 | { |
||
21 | if (@abstract) |
||
22 | socket = OpenAbstractUnix (path); |
||
23 | else |
||
24 | socket = OpenUnix (path); |
||
25 | |||
26 | socket.Blocking = true; |
||
27 | SocketHandle = (long)socket.Handle; |
||
28 | //Stream = new UnixStream ((int)socket.Handle); |
||
29 | Stream = new NetworkStream (socket); |
||
30 | } |
||
31 | |||
32 | //send peer credentials null byte. note that this might not be portable |
||
33 | //there are also selinux, BSD etc. considerations |
||
34 | public override void WriteCred () |
||
35 | { |
||
36 | Stream.WriteByte (0); |
||
37 | } |
||
38 | |||
39 | protected Socket OpenAbstractUnix (string path) |
||
40 | { |
||
41 | AbstractUnixEndPoint ep = new AbstractUnixEndPoint (path); |
||
42 | |||
43 | Socket client = new Socket (AddressFamily.Unix, SocketType.Stream, 0); |
||
44 | client.Connect (ep); |
||
45 | |||
46 | return client; |
||
47 | } |
||
48 | |||
49 | public Socket OpenUnix (string path) |
||
50 | { |
||
51 | UnixEndPoint remoteEndPoint = new UnixEndPoint (path); |
||
52 | |||
53 | Socket client = new Socket (AddressFamily.Unix, SocketType.Stream, 0); |
||
54 | client.Connect (remoteEndPoint); |
||
55 | |||
56 | return client; |
||
57 | } |
||
58 | } |
||
59 | } |