2008-03-05 09:52:00 -05:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Microsoft Research Singularity
|
|
|
|
//
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
//
|
|
|
|
// Note: Simple Singularity test program.
|
|
|
|
//
|
|
|
|
using System;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Net.IP;
|
|
|
|
|
|
|
|
using Microsoft.Singularity;
|
|
|
|
using Microsoft.Singularity.Channels;
|
|
|
|
using Microsoft.Singularity.Directory;
|
|
|
|
using NetStack.Contracts;
|
|
|
|
using NetStack.Channels.Public;
|
|
|
|
|
|
|
|
using Microsoft.Contracts;
|
|
|
|
using Microsoft.SingSharp.Reflection;
|
|
|
|
using Microsoft.Singularity.Applications;
|
|
|
|
using Microsoft.Singularity.Io;
|
|
|
|
using Microsoft.Singularity.Configuration;
|
|
|
|
[assembly: Transform(typeof(ApplicationResourceTransform))]
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
namespace Microsoft.Singularity.Applications.Network
|
2008-03-05 09:52:00 -05:00
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
[ConsoleCategory(HelpMessage="Change network routing information", DefaultAction=true)]
|
2008-03-05 09:52:00 -05:00
|
|
|
internal class Parameters {
|
|
|
|
[InputEndpoint("data")]
|
|
|
|
public readonly TRef<UnicodePipeContract.Exp:READY> Stdin;
|
|
|
|
|
|
|
|
[OutputEndpoint("data")]
|
|
|
|
public readonly TRef<UnicodePipeContract.Imp:READY> Stdout;
|
|
|
|
|
|
|
|
[Endpoint]
|
|
|
|
public readonly TRef<IPContract.Imp:Start> ipRef;
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
[StringParameter( "n", Default=null, HelpMessage="new domain name")]
|
2008-03-05 09:52:00 -05:00
|
|
|
internal string name;
|
|
|
|
|
|
|
|
reflective internal Parameters();
|
|
|
|
|
|
|
|
internal int AppMain() {
|
|
|
|
DomainName.AppMain(this);
|
2008-11-17 18:29:00 -05:00
|
|
|
return 0;
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
|
2008-03-05 09:52:00 -05:00
|
|
|
/// <summary>
|
|
|
|
/// Class for configuring Domain Name.
|
|
|
|
/// </summary>
|
|
|
|
public class DomainName
|
|
|
|
{
|
|
|
|
internal static int AppMain(Parameters! config)
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
IPContract.Imp ipConn = ((!)config.ipRef).Acquire();
|
|
|
|
if (ipConn == null) {
|
2008-03-05 09:52:00 -05:00
|
|
|
Console.WriteLine("Could not initialize IP endpoint.");
|
|
|
|
return 1;
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
ipConn.RecvReady();
|
2008-03-05 09:52:00 -05:00
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
try {
|
|
|
|
if (config.name == null) {
|
2008-03-05 09:52:00 -05:00
|
|
|
char[]! in ExHeap repDomain;
|
|
|
|
ipConn.SendGetDomainName();
|
|
|
|
ipConn.RecvDomainName(out repDomain);
|
|
|
|
Console.WriteLine(Bitter.ToString2(repDomain));
|
|
|
|
delete repDomain;
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
else {
|
2008-03-05 09:52:00 -05:00
|
|
|
ipConn.SendSetDomainName(Bitter.FromString2(config.name));
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
switch receive {
|
2008-03-05 09:52:00 -05:00
|
|
|
case ipConn.Err():
|
|
|
|
Console.WriteLine("Error setting domain name");
|
|
|
|
return 1; // failure
|
|
|
|
|
|
|
|
case ipConn.OK():
|
|
|
|
Console.WriteLine("Set domain name successfully");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ipConn.ChannelClosed():
|
|
|
|
Console.WriteLine("Error setting domain name (channel closed)");
|
|
|
|
return 1; // failure
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
finally {
|
2008-03-05 09:52:00 -05:00
|
|
|
delete ipConn;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0; // success
|
|
|
|
}
|
|
|
|
} // end class DomainName
|
|
|
|
}
|