-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allowed IP/Port via rather than just IPEndPoint
- Loading branch information
Lee Walker
committed
May 18, 2015
1 parent
47c76c3
commit 312dfed
Showing
7 changed files
with
110 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Text; | ||
|
||
namespace SSQLib | ||
{ | ||
public class EndPointHelpers | ||
{ | ||
public static IPEndPoint GetIPEndPointFromHostName(string hostName, int port, bool throwIfMoreThanOneIP) | ||
{ | ||
var addresses = System.Net.Dns.GetHostAddresses(hostName); | ||
if (addresses.Length == 0) | ||
{ | ||
throw new ArgumentException( | ||
"Unable to retrieve address from specified host name.", | ||
"hostName" | ||
); | ||
} | ||
else if (throwIfMoreThanOneIP && addresses.Length > 1) | ||
{ | ||
throw new ArgumentException( | ||
"There is more that one IP address to the specified host.", | ||
"hostName" | ||
); | ||
} | ||
return new IPEndPoint(addresses[0], port); // Port gets validated here. | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using SSQLib; | ||
using System.Net; | ||
using Xunit; | ||
|
||
namespace Test.SSQLib | ||
{ | ||
public class PlayerTests | ||
{ | ||
[Fact] | ||
public void TestFakePlayerServerThrowsExceptionWithIpEndpoint() | ||
{ | ||
Assert.Throws(typeof(SSQLServerException), () => | ||
{ | ||
SSQL query = new SSQL(); | ||
//127.0.0.2 set to stop loopback potentially resolving and failing test | ||
query.Players(new IPEndPoint(IPAddress.Parse("127.0.0.2"), 27015)); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void TestFakePlayerServerThrowsExceptionWithStringIp() | ||
{ | ||
Assert.Throws(typeof(SSQLServerException), () => | ||
{ | ||
SSQL query = new SSQL(); | ||
//127.0.0.2 set to stop loopback potentially resolving and failing test | ||
query.Players("127.0.0.2", 27015); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters