@@ -92,7 +92,6 @@ public WireGuardAdapterState GetAdapterState()
92
92
93
93
public bool ParseConfFile ( string [ ] lines , out WgConfig wgConfig )
94
94
{
95
- //TODO: Resolve EndPoint, Set DNS
96
95
//Dns.GetHostEntry(host).AddressList.First(addr => addr.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
97
96
//loctlWireGuardConfig _loctlWireGuardConfig = wgConfig.LoctlWireGuardConfig;
98
97
wgConfig = new WgConfig ( ) ;
@@ -109,11 +108,6 @@ public bool ParseConfFile(string[] lines, out WgConfig wgConfig )
109
108
{
110
109
peerSize ++ ;
111
110
}
112
- if ( lineLower . StartsWith ( "endpoint" ) )
113
- {
114
- //TODO: support endpoints
115
- //List<IPNetwork> allowedIps = new List<IPNetwork>();
116
- }
117
111
}
118
112
119
113
@@ -125,7 +119,7 @@ public bool ParseConfFile(string[] lines, out WgConfig wgConfig )
125
119
126
120
if ( line . StartsWith ( "#" ) )
127
121
{
128
- continue ; ;
122
+ continue ;
129
123
}
130
124
var lineLower = line . Trim ( ) . ToLower ( ) ;
131
125
if ( lineLower . Length == 0 )
@@ -255,15 +249,15 @@ public bool ParseConfFile(string[] lines, out WgConfig wgConfig )
255
249
var addrs = value . Split ( ':' ) ;
256
250
//check dns
257
251
IPEndPoint endPoint ;
258
- try
259
- {
260
- var ipEntry = Dns . GetHostEntry ( addrs [ 0 ] ) ;
261
- endPoint = new IPEndPoint ( ipEntry . AddressList [ 0 ] , Convert . ToInt32 ( addrs [ 1 ] ) ) ;
262
- }
263
- catch
252
+ if ( ValidateIPv4 ( addrs [ 0 ] ) )
264
253
{
265
- endPoint = new IPEndPoint ( IPAddress . Parse ( addrs [ 0 ] ) , Convert . ToInt32 ( addrs [ 1 ] ) ) ;
254
+ endPoint = new IPEndPoint ( IPAddress . Parse ( addrs [ 0 ] ) , Convert . ToInt32 ( addrs [ 1 ] ) ) ;
266
255
}
256
+ else
257
+ {
258
+ var ipEntry = Dns . GetHostEntry ( addrs [ 0 ] ) ;
259
+ endPoint = new IPEndPoint ( ipEntry . AddressList [ 0 ] , Convert . ToInt32 ( addrs [ 1 ] ) ) ;
260
+ }
267
261
if ( endPoint . AddressFamily == AddressFamily . InterNetworkV6 )
268
262
{
269
263
wgConfig . LoctlWireGuardConfig . WgPeerConfigs [ peerCount - 1 ] . client . Endpoint . Ipv6 . sin6_family = Win32 . ADDRESS_FAMILY . AF_INET6 ;
@@ -313,7 +307,26 @@ public bool ParseConfFile(string[] lines, out WgConfig wgConfig )
313
307
}
314
308
return true ;
315
309
}
316
-
310
+ public bool ValidateIPv4 ( string ipString )
311
+ {
312
+ if ( String . IsNullOrWhiteSpace ( ipString ) )
313
+ {
314
+ return false ;
315
+ }
316
+
317
+ string [ ] splitValues = ipString . Split ( '.' ) ;
318
+ if ( splitValues . Length != 4 )
319
+ {
320
+ return false ;
321
+ }
322
+
323
+ byte tempForParsing ;
324
+
325
+ return splitValues . All ( r => byte . TryParse ( r , out tempForParsing ) ) ;
326
+
327
+ }
328
+
329
+
317
330
public void SetConfiguration ( WgConfig wgConfig )
318
331
{
319
332
var _loctlWireGuardConfig = wgConfig . LoctlWireGuardConfig ;
0 commit comments