/// <summary> /// Note: Since this is a struct and this function can modify the fields of the struct, /// make sure you are calling this on a "ref" version of the struct, and if it's a member /// of another object, make sure it IS NOT readonly. /// </summary> /// <param name="dnsPriorityQuery">Callback that determines priority to select an address from Dns record. /// Use DnsPriority.(QueryName) for standard queries.</param> public void ForceIPResolution(PriorityQuery <IPAddress> dnsPriorityQuery) { if (ipEndPoint == null) { ipEndPoint = new IPEndPoint(EndPoints.DnsResolve(ipOrHost, dnsPriorityQuery), port); } }
public static void Connect(this Socket socket, ref StringEndPoint endpoint, PriorityQuery <IPAddress> dnsPriorityQuery) { if (endpoint.ipEndPoint == null) { endpoint.ipEndPoint = new IPEndPoint(EndPoints.DnsResolve(endpoint.ipOrHost, dnsPriorityQuery), endpoint.port); } socket.Connect(endpoint.ipEndPoint); }
public void DnsRefreshAddress() { IPAddress newAddress = EndPoints.DnsResolve(domainName, dnsPriorityQuery); if (lastRefreshEndPoint == null || !lastRefreshIPAddress.Equals(newAddress)) { //if (lastRefreshEndPoint != null) //Console.WriteLine("[DnsEndPointDebug] Address is different old='{0}' new='{1}'", lastRefreshIPAddress, newAddress); this.lastRefreshIPAddress = newAddress; this.lastRefreshEndPoint = new IPEndPoint(newAddress, port); } }
public static Int32 Run(String programName, String[] args, UInt16 defaultPort, InterfaceMapping interfaceMapping) { if (args.Length < 1) { Usage(programName); return(1); } String serverIPOrHostAndOptionalPort = args[0]; IPEndPoint serverEndPoint = EndPoints.ParseIPOrResolveHostWithOptionalPort( serverIPOrHostAndOptionalPort, defaultPort, DnsPriority.IPv4ThenIPv6); CommandLineClient client = new CommandLineClient(serverEndPoint, interfaceMapping); String line; // // Command line mode // if (args.Length > 1) { line = args[1]; for (int i = 2; i < args.Length; i++) { line += " " + args[i]; } client.ProcessLine(line); return(0); } // // Interactive Mode // do { Console.Write("->"); line = Console.ReadLine(); } while (client.ProcessLine(line)); return(0); }
public static void Connect(this Socket socket, String host, Int32 port) { var ip = EndPoints.ParseIPOrResolveHost(host, DnsPriority.IPv4ThenIPv6); socket.Connect(new IPEndPoint(ip, port)); }
static Int32 Main(String[] args) { Options options = new Options(); List <String> nonOptionArgs = options.Parse(args); if (nonOptionArgs.Count == 0) { options.PrintUsage(); return(1); } String command = nonOptionArgs[0]; if (nonOptionArgs.Count < 3) { return(options.ErrorAndUsage("Error: Missing command line arguments")); } String hostString = nonOptionArgs[1]; String oidString = nonOptionArgs[2]; IPEndPoint endPoint = EndPoints.ParseIPOrResolveHostWithOptionalPort(hostString, 161, DnsPriority.IPv4ThenIPv6); List <Byte> oidBytes = new List <Byte>(); Snmp.ParseOid(oidString, oidBytes); Byte[] oid = oidBytes.ToArray(); if (command.Equals("get", StringComparison.CurrentCultureIgnoreCase)) { if (nonOptionArgs.Count != 3) { return(options.ErrorAndUsage("Error: operation 'get' requires 2 arguments but there are {0}", nonOptionArgs.Count - 1)); } Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); Byte[] packet = new Byte[Snmp.MaximumBufferForGet( (UInt32)options.community.ArgValue.Length, (UInt32)oid.Length)]; UInt32 snmpContentLength = Snmp.SerializeGet(packet, 0, options.community.ArgValue, Snmp.NextID(), oid); socket.SendTo(packet, (Int32)snmpContentLength, 0, endPoint); } else if (command.Equals("set", StringComparison.CurrentCultureIgnoreCase)) { if (nonOptionArgs.Count != 5) { return(options.ErrorAndUsage("Error: operation 'set' requires 4 arguments but there are {0}", nonOptionArgs.Count - 1)); } Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); Byte[] value = Asn1.ParseValue(nonOptionArgs[3], nonOptionArgs[4]); Byte[] packet = new Byte[Snmp.MaximumBufferForSet( (UInt32)options.community.ArgValue.Length, (UInt32)oid.Length, (UInt32)value.Length)]; UInt32 snmpContentLength = Snmp.SerializeSet(packet, 0, options.community.ArgValue, Snmp.NextID(), oid, value); socket.SendTo(packet, (Int32)snmpContentLength, 0, endPoint); } else { Console.WriteLine("Error: Unknown operation '{0}'", command); return(1); } return(0); }