-
Notifications
You must be signed in to change notification settings - Fork 2
/
UnixSocketProxy.cs
43 lines (36 loc) · 1.15 KB
/
UnixSocketProxy.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using KeePassHttpProxy.Mono.Unix;
using System;
using System.Net.Sockets;
namespace KeePassNatMsgProxy
{
public class UnixSocketProxy : ProxyBase
{
private Socket _client;
protected override bool IsClientConnected => _client.Connected;
protected override int ClientRead(byte[] buffer, int offset, int length)
{
return _client.Receive(buffer, offset, length, SocketFlags.None);
}
protected override void ClientWrite(byte[] data)
{
_client.Send(data);
}
protected override void Close()
{
_client.Disconnect(true);
_client.Close();
}
protected override void Connect()
{
var path = $"/tmp/{ProxyName}";
var xdg = Environment.GetEnvironmentVariable("XDG_RUNTIME_DIR");
if (!string.IsNullOrEmpty(xdg))
{
path = System.IO.Path.Combine(xdg, ProxyName);
}
var rep = new UnixEndPoint(path);
_client = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP);
_client.Connect(rep);
}
}
}