Skip to content

Commit

Permalink
respond to local fqdn
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Gusarov committed Apr 13, 2020
1 parent 16383db commit a72ceb6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions qDNS/DnsServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ static void Main(string[] args)
{
using (var srv = new DnsServer())
{

for (var i = 0; i < args.Length; i++)
{
var arg = args[i].TrimStart(new[] { '-', '/' });
Expand Down Expand Up @@ -54,6 +53,7 @@ public DnsServer()
var interfaces = NetworkInterface.GetAllNetworkInterfaces();
var fwdAddresses = new HashSet<IPAddress>();
_myAddress.Add(new IPAddress(new byte[] {127, 0, 0, 1}));
_myAddress.Add(IPAddress.Parse("::1"));
foreach (var networkInterface in interfaces)
{

Expand Down Expand Up @@ -287,7 +287,7 @@ void Handle(RequestContext ctx)
{
Console.WriteLine(ex);
}
Console.WriteLine();
Console.WriteLine();


if (req.Questions.Count == 1)
Expand Down Expand Up @@ -390,6 +390,8 @@ static IPAddress MyLocalAddressFor(IPAddress from)

private bool HandleSelfName(RequestContext ctx)
{
var domain = IPGlobalProperties.GetIPGlobalProperties().DomainName;

RequestQuestion query;
if (ctx.Request.Questions.Count == 1)
{
Expand All @@ -402,7 +404,11 @@ private bool HandleSelfName(RequestContext ctx)

if ((query.Type == RecordType.A) && query.Class == RecordClass.IN)
{
if (Environment.MachineName.ToUpperInvariant() == query.Name.ToUpperInvariant())
var hostName = Environment.MachineName;
var fqdn = Environment.MachineName + "." + domain;

if (string.Equals(query.Name, hostName, StringComparison.OrdinalIgnoreCase)
|| string.Equals(query.Name, fqdn, StringComparison.OrdinalIgnoreCase))
{
// should respond with ip from specific interface
var local = MyLocalAddressFor(ctx.From.Address);
Expand Down

0 comments on commit a72ceb6

Please sign in to comment.