/// <summary>Sends Ganglia Metrics to the configured hosts</summary> /// <exception cref="System.IO.IOException"/> protected internal virtual void EmitToGangliaHosts() { try { foreach (EndPoint socketAddress in metricsServers) { if (socketAddress == null || !(socketAddress is IPEndPoint)) { throw new ArgumentException("Unsupported Address type"); } IPEndPoint inetAddress = (IPEndPoint)socketAddress; if (inetAddress.IsUnresolved()) { throw new UnknownHostException("Unresolved host: " + inetAddress); } DatagramPacket packet = new DatagramPacket(buffer, offset, socketAddress); datagramSocket.Send(packet); } } finally { // reset the buffer for the next metric to be built offset = 0; } }
private string GetHost(IPEndPoint isa) { //@@@ Will this work with literal IPv6 addresses, or do we //@@@ need to wrap these in [] for the string representation? //@@@ Having it in this method at least allows for easy workarounds. return(isa.IsUnresolved() ? isa.GetHostName() : isa.Address.GetHostAddress()); }
// check that the socket addr has: // 1) the InetSocketAddress has the correct hostname, ie. exact host/ip given // 2) the address is resolved, ie. has an ip // 3,4) the socket's InetAddress has the same hostname, and the correct ip // 5) the port is correct private void VerifyValues(IPEndPoint addr, string host, string ip, int port) { Assert.True(!addr.IsUnresolved()); // don't know what the standard resolver will return for hostname. // should be host for host; host or ip for ip is ambiguous if (!SecurityUtil.useIpForTokenService) { Assert.Equal(host, addr.GetHostName()); Assert.Equal(host, addr.Address.GetHostName()); } Assert.Equal(ip, addr.Address.GetHostAddress()); Assert.Equal(port, addr.Port); }
public static void Refresh(Configuration conf) { ICollection <string> tempServers = new HashSet <string>(); // trusted proxy servers such as http proxies foreach (string host in conf.GetTrimmedStrings(ConfHadoopProxyservers)) { IPEndPoint addr = new IPEndPoint(host, 0); if (!addr.IsUnresolved()) { tempServers.AddItem(addr.Address.GetHostAddress()); } } proxyServers = tempServers; }
/// <summary> /// Returns an InetSocketAddress that a client can use to connect to the /// given listening address. /// </summary> /// <param name="addr">of a listener</param> /// <returns>socket address that a client can use to connect to the server.</returns> public static IPEndPoint GetConnectAddress(IPEndPoint addr) { if (!addr.IsUnresolved() && addr.Address.IsAnyLocalAddress()) { try { addr = new IPEndPoint(Runtime.GetLocalHost(), addr.Port); } catch (UnknownHostException) { // shouldn't get here unless the host doesn't have a loopback iface addr = CreateSocketAddrForHost("127.0.0.1", addr.Port); } } return(addr); }
/// <exception cref="System.IO.IOException"/> public override void Connect(EndPoint addr, int timeout) { System.Diagnostics.Debug.Assert((addr is IPEndPoint)); IPEndPoint iaddr = (IPEndPoint)addr; EndPoint newAddr = null; if (iaddr.IsUnresolved()) { newAddr = new IPEndPoint(iaddr.GetHostName(), iaddr.Port - 10); } else { newAddr = new IPEndPoint(iaddr.Address, iaddr.Port - 10); } System.Console.Out.Printf("Test socket: rerouting %s to %s\n", iaddr, newAddr); base.Connect(newAddr, timeout); }
/// <summary>Construct the service key for a token</summary> /// <param name="addr">InetSocketAddress of remote connection with a token</param> /// <returns> /// "ip:port" or "host:port" depending on the value of /// hadoop.security.token.service.use_ip /// </returns> public static Text BuildTokenService(IPEndPoint addr) { string host = null; if (useIpForTokenService) { if (addr.IsUnresolved()) { // host has no ip address throw new ArgumentException(new UnknownHostException(addr.GetHostName())); } host = addr.Address.GetHostAddress(); } else { host = StringUtils.ToLowerCase(addr.GetHostName()); } return(new Text(host + ":" + addr.Port)); }
internal static IPEndPoint ParseEntry(string type, string fn, string line) { try { URI uri = new URI("dummy", line, null, null, null); int port = uri.GetPort() == -1 ? 0 : uri.GetPort(); IPEndPoint addr = new IPEndPoint(uri.GetHost(), port); if (addr.IsUnresolved()) { Log.Warn(string.Format("Failed to resolve address `%s` in `%s`. " + "Ignoring in the %s list." , line, fn, type)); return(null); } return(addr); } catch (URISyntaxException) { Log.Warn(string.Format("Failed to parse `%s` in `%s`. " + "Ignoring in " + "the %s list." , line, fn, type)); } return(null); }