2008-03-05 09:52:00 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Microsoft Research Singularity
|
|
|
|
//
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
//
|
|
|
|
// Note: Client-side helper for the IP Channel Contract
|
|
|
|
//
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Net.IP;
|
|
|
|
using Drivers.Net;
|
|
|
|
using Microsoft.SingSharp;
|
|
|
|
using Microsoft.Singularity;
|
|
|
|
using Microsoft.Singularity.Channels;
|
|
|
|
using Microsoft.Singularity.Directory;
|
|
|
|
using NetStack.Contracts;
|
|
|
|
using NetStack.Runtime;
|
|
|
|
|
|
|
|
namespace NetStack.Channels.Public
|
|
|
|
{
|
|
|
|
public class DNSImpConnection
|
|
|
|
{
|
|
|
|
// Converts the results of GerNameServers to IPv4 structures
|
|
|
|
public static IPv4[]! GetNameServers(DNSContract.Imp:ReadyState! ep)
|
|
|
|
{
|
|
|
|
uint[] in ExHeap addrList;
|
|
|
|
ep.SendGetNameServers();
|
|
|
|
ep.RecvAddressList(out addrList);
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
try {
|
2008-03-05 09:52:00 -05:00
|
|
|
IPv4[] retval;
|
|
|
|
if (addrList == null) {
|
|
|
|
retval = new IPv4[0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
retval = new IPv4[addrList.Length];
|
2008-11-17 18:29:00 -05:00
|
|
|
for (int i = 0; i < addrList.Length; ++i) {
|
2008-03-05 09:52:00 -05:00
|
|
|
retval[i] = new IPv4(addrList[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
finally {
|
2008-03-05 09:52:00 -05:00
|
|
|
delete addrList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Converts the retrieved address(es) to IPv4 structures.
|
|
|
|
// Returns true iff the named host was found successfully.
|
|
|
|
public static bool Resolve(DNSContract.Imp! ep, string name,
|
|
|
|
out string[] aliases, out IPv4[] addrs)
|
|
|
|
{
|
|
|
|
aliases = null;
|
|
|
|
addrs = null;
|
|
|
|
|
|
|
|
ep.SendResolve(Bitter.FromString(name));
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
switch receive {
|
2008-03-05 09:52:00 -05:00
|
|
|
case ep.RecvDNSResults(uint[] in ExHeap addrList,
|
|
|
|
char[][] in ExHeap aliasesResult) :
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
try {
|
|
|
|
if (aliasesResult != null) {
|
2008-03-05 09:52:00 -05:00
|
|
|
aliases = new string[aliasesResult.Length];
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
for (int i = 0; i < aliasesResult.Length; ++i) {
|
2008-03-05 09:52:00 -05:00
|
|
|
expose (aliasesResult[i]) {
|
|
|
|
aliases[i] = Bitter.ToString(aliasesResult[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aliases = new string[0];
|
|
|
|
}
|
|
|
|
if (addrList != null) {
|
|
|
|
addrs = new IPv4[addrList.Length];
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
for (int i = 0; i < addrList.Length; ++i) {
|
|
|
|
addrs[i] = new IPv4(addrList[i]);
|
|
|
|
}
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
addrs = new IPv4[0];
|
|
|
|
}
|
|
|
|
return true; // success;
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
finally {
|
2008-03-05 09:52:00 -05:00
|
|
|
delete aliasesResult; // does deep freeing
|
|
|
|
delete addrList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ep.RecvNotFound() :
|
|
|
|
return false; // failure
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|