// 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; IPv4[] addrList; String[] aliasesResult; ep.Resolve(name, out addrList, out aliasesResult); if (aliasesResult != null) { aliases = aliasesResult; } else { aliases = new string[0]; } if (addrList != null) { addrs = addrList; } else { addrs = new IPv4[0]; } return(true); // success; }
/// <summary> /// 查找IP的位置信息 /// </summary> /// <param name="ipv4">ipv4</param> /// <returns></returns> public Location Find(IPv4 ipv4) { var result = _17IPv4DBHelper.Find(ipv4); if (result == null || result.Length == 0) { return(null); } var location = new Location { IP = ipv4, }; if (result.Length > 1) { location.Country = result[0]; } if (result.Length > 2) { location.State = result[1]; } if (result.Length > 3) { location.City = result[2]; } return(location); }
//"A comparison of hashing schemes for address lookup in // computer networks" Raj Jain DEC tech report 1989 //i.e. XOR rules! private byte Hash(IPv4 src, IPv4 dst, ushort sPort, ushort dPort) { uint t = ((uint)(src ^ dst)) ^ (uint)(sPort ^ dPort); byte h = (byte)(t ^ (t >> 24) ^ (t >> 16) ^ (t >> 8)); return(h); }
// create a new entry public ArpEntry(IPv4 ipAddress, EthernetAddress mac, bool dynamic) { this.ipAddress = ipAddress; this.mac = mac; this.dynamic = dynamic; this.entryAge = ArpTable.MaxAge; }
private void StartupConfig() { cmbIPs.ItemsSource = IPv4.GetActiveIP4s(); for (int port = 49200; port <= 49500; port++) { cmbPorts.Items.Add(port); } Config.GetConfig(out string savedIP, out int savedPort); try { cmbIPs.SelectedItem = savedIP; } catch { cmbIPs.SelectedItem = "127.0.0.1"; } try { cmbPorts.SelectedItem = savedPort; } catch { cmbPorts.SelectedItem = 49200; } btnStartServer.Visibility = Visibility.Visible; btnStopServer.Visibility = Visibility.Hidden; grpCarPark.Visibility = Visibility.Hidden; }
public void ArpRequest(IPv4 sourceIP, IPv4 targetIP, EthernetAddress localMac, Bytes header, Bytes buffer, IAdapter adapter) { // AutoResetEvent requestComplete = AddPendingRequest(targetIP, TimeSpan.FromSeconds(3), localMac, header, buffer, adapter); // initiate an arp request... DebugPrint("Initiating request " + "({0},{1}) --> ({2},{3})\n", sourceIP, localMac, targetIP, EthernetAddress.Zero); //eventially we'll want to follow Orion's conservation of //packets philosophy Bytes arpHeader = new Bytes(new byte [EthernetHeader.Size]); Bytes arpMsg = new Bytes(new byte [ArpHeader.Size]); //xxx I'd like to get rid of EthernetHeader eventually... EthernetHeader.Write(arpHeader, localMac, EthernetAddress.Broadcast, EthernetHeader.PROTOCOL_ARP); ArpHeader.Write(arpMsg, localMac, sourceIP, ArpHeader.ARP_REQUEST, EthernetAddress.Zero, targetIP); adapter.PopulateTxRing(arpHeader, arpMsg); // DebugPrint("ArpRequest: waiting for reply\n"); //requestComplete.WaitOne(); // DebugPrint("ArpRequest: reply received!\n"); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private void processMessageUDP(pspsharp.network.protocols.NetPacket packet, pspsharp.network.protocols.EtherFrame frame, pspsharp.network.protocols.IPv4 ipv4) throws java.io.EOFException private void processMessageUDP(NetPacket packet, EtherFrame frame, IPv4 ipv4) { UDP udp = new UDP(); udp.read(packet); //if (log.DebugEnabled) { Console.WriteLine(string.Format("processMessageUDP {0}", udp)); } switch (udp.destinationPort) { case UDP_PORT_DNS: processMessageDNS(packet, frame, ipv4, udp); break; case UDP.UDP_PORT_DHCP_SERVER: processMessageDHCP(packet, frame, ipv4, udp); break; default: Console.WriteLine(string.Format("processMessageUDP unknown destination port 0x{0:X}", udp.destinationPort)); break; } }
private void UpdatePendingRequests(IPv4 ipAddress, EthernetAddress macAddress) { using (pendingRequestsLock.Lock()) { //Sigh...we're missing a linked list in the current Singularity C# runtime foreach (PendingArpRequest pendingRequest in pendingRequests) { VTable.Assert(pendingRequest != null); if (pendingRequest.address == ipAddress) { pendingRequest.active = false; DebugStub.WriteLine("found waiting arp request...sending on out"); VectorQueueByte txBuffer = pendingRequest.txContainer.Acquire(); Bytes header = txBuffer.ExtractHead(); Bytes buffer = txBuffer.ExtractHead(); VTable.Assert(header != null); VTable.Assert(buffer != null); pendingRequest.txContainer.Release(txBuffer); //Format ethernet header EthernetHeader.Write(header, pendingRequest.localMac, macAddress, EthernetHeader.PROTOCOL_IP); //send it! VTable.Assert(pendingRequest.adapter != null); pendingRequest.adapter.PopulateTxRing(header, buffer); continue; } } } }
private StatusCode AskDnsServer(IPv4 dnsServer, byte[] !outData, out byte[] rcvData) { Core core = Core.Instance(); UdpModule udpModule = core.GetProtocolByName("UDP") as UdpModule; if (udpModule == null) { rcvData = null; return(StatusCode.TransportError); } UdpSession udpSession = udpModule.CreateBoundSession(IPv4.Any, 0, dnsServer, Dns.Format.ServerPort); udpSession.WriteData(outData); rcvData = udpSession.PollCopyData(TimeSpan.FromTicks(timeout.Ticks)); if (rcvData == null) { return(StatusCode.Timeout); } return(StatusCode.Success); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private void processMessageDHCP(pspsharp.network.protocols.NetPacket packet, pspsharp.network.protocols.EtherFrame frame, pspsharp.network.protocols.IPv4 ipv4, pspsharp.network.protocols.UDP udp) throws java.io.EOFException private void processMessageDHCP(NetPacket packet, EtherFrame frame, IPv4 ipv4, UDP udp) { DHCP dhcp = new DHCP(); dhcp.read(packet); //if (log.DebugEnabled) { Console.WriteLine(string.Format("processMessageDHCP {0}", dhcp)); } if (dhcp.isDiscovery(udp, ipv4)) { // Send back a DHCP offset message sendDHCPReply(frame, ipv4, udp, dhcp, DHCP.DHCP_OPTION_MESSAGE_TYPE_DHCPOFFER); } else if (dhcp.isRequest(udp, ipv4, LocalIpAddress)) { // Send back a DHCP acknowledgment message sendDHCPReply(frame, ipv4, udp, dhcp, DHCP.DHCP_OPTION_MESSAGE_TYPE_DHCPACK); } else { Console.WriteLine(string.Format("Unknown DHCP request {0}", dhcp)); } }
//public static void DoEvents() //{ // System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate { })); //} private void StartupConfig() { cmbIPs.ItemsSource = IPv4.GetActiveIP4s(); for (int port = 49200; port <= 49500; port++) { cmbPorts.Items.Add(port); } Config.GetConfig(out string myIP, out string serverIP, out int savedPort, out string myName); try { cmbIPs.SelectedItem = myIP; } catch { cmbIPs.SelectedItem = "127.0.0.1"; } try { cmbPorts.SelectedItem = savedPort; } catch { cmbPorts.SelectedItem = 49200; } txtServerIP.Text = serverIP; txtMyCar.Text = myName; btnConnectToServer.Visibility = Visibility.Visible; btnDisconnectFromServer.Visibility = Visibility.Hidden; grpMyCar.Visibility = Visibility.Hidden; }
public static bool IsValidIPv4(IPv4 ip) { if ((ip == null) || (ip.IsNull)) return false; else return true; }
//way too many copies. But for now we'll live with it. private StatusCode AskDnsServer(IPv4 dnsServer, byte[] outData, out byte[] rcvData) { UDP udp = new UDP(); udp.Bind(IPv4.Any, 0); udp.Connect(dnsServer, Dns.Format.ServerPort); Bytes packet = Bitter.FromByteArray(outData); udp.WriteData(packet); Bytes buffer; buffer = udp.PollReadData(TimeSpan.FromTicks(timeout.Ticks)); //This is silly..I'll come back and clean this up. udp.Close(); if (buffer == null) { rcvData = null; return(StatusCode.Timeout); } rcvData = new byte[buffer.Length]; Bitter.ToByteArray(buffer, 0, buffer.Length, rcvData, 0); //delete buffer; return(StatusCode.Success); }
public void SearchIPv4PrefixMap(IPv4PrefixMap map) { int threadCount = Math.Max(Environment.ProcessorCount - 1, 2); int searchesPerThread = settings.Value.SearchCount / threadCount; //TODO: Convert to PLINQ expression? var sw = Stopwatch.StartNew(); var batches = Enumerable.Range(1, threadCount) .Select(id => Task.Run(() => map.FindNetworks(id, GenerateRandomIPAddresses(searchesPerThread)).ToList())) .ToArray(); Task.WaitAll(batches); sw.Stop(); long searchTime = sw.ElapsedMilliseconds; var totalResultCount = batches.Select(x => x.Result.Count).Sum(); var results = batches.SelectMany(x => x.Result.Take(5)); Console.WriteLine("Sample Search Results"); foreach (var x in results) { string block = $"{x.Prefix} ({(x.Prefix.HasFlag ? "Azure" : "Amazon")})"; string message = $" * [{x.Thread}] ip: {IPv4.ConvertToString(x.Address),-17} net: {block,-27} miss: {x.Counter,-5}"; Console.WriteLine(message); } Console.WriteLine(); Console.WriteLine($"Found {totalResultCount} matching addresses in {map.Count} distinct prefixes ({searchTime} ms)"); }
public static int GenerateSequenceNumber(IPv4 localHost, IPv4 remoteHost, ushort localPort, ushort remotePort) { // No MD5 for now so perform a weak hash long isn = DateTime.UtcNow.Ticks; snBase = snBase + 2287 * snBase; isn += snBase; int i = 0; foreach (byte b in localHost.GetAddressBytes()) { isn ^= ((long)b) << i; i += 8; } foreach (byte b in localHost.GetAddressBytes()) { isn ^= ((long)b) << i; i += 8; } isn += (localPort << 16) | remotePort; return((int)((isn >> 32) ^ isn)); }
public override List <IPv4Prefix> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { if (reader.TokenType != JsonTokenType.StartArray) { throw new FormatException(); } var value = new List <IPv4Prefix>(); while (reader.Read()) { if (reader.TokenType == JsonTokenType.String) { value.Add(IPv4.ParsePrefix(reader.GetString())); } else if (reader.TokenType == JsonTokenType.EndArray) { return(value); } else { throw new FormatException(); } } throw new FormatException(); }
public void Resolve(String repName, out IPv4[] addrsAsUint, out String[] aliases) { IPv4HostEntry hostEntry; BasicDnsClient client = new BasicDnsClient(); string name = repName; BasicDnsClient.StatusCode result = client.Resolve(name, out hostEntry); if (result != BasicDnsClient.StatusCode.Success) { throw new Exception("Resolve: NotFound"); } else { VTable.Assert(hostEntry != null); // Convert the alias strings aliases = new String[hostEntry.Aliases.Length]; for (int i = 0; i < hostEntry.Aliases.Length; ++i) { aliases[i] = hostEntry.Aliases[i]; } // Convert the IP addresses IPv4[] addrs = hostEntry.AddressList; addrsAsUint = new IPv4[addrs.Length]; for (int i = 0; i < addrs.Length; ++i) { addrsAsUint[i] = addrs[i]; } } }
public void BoundsCheck() { var ip = new IPv4(); const string input = "0.254.255.0"; Assert.True(ip.isIPv4Address(input)); }
public void ShouldHaveFourNumbers() { var ip = new IPv4(); const string input = ".16.254.1"; Assert.False(ip.isIPv4Address(input)); }
public static int Write(Bytes pkt, EthernetAddress srchw, IPv4 srcip, ushort operation, EthernetAddress targethw, IPv4 targetip) { int o = 0; pkt[o++] = 0x00; pkt[o++] = 0x01; // hardware type = 0x0001 pkt[o++] = 0x08; pkt[o++] = 0x00; // protocol type = 0x0800 pkt[o++] = 0x06; // hardware addr len (bytes) pkt[o++] = 0x04; // protocol address len (bytes) pkt[o++] = (byte)(operation >> 8); pkt[o++] = (byte)(operation & 0xff); srchw.CopyOut(pkt.Array, pkt.Start + o); o += EthernetAddress.Length; srcip.CopyOut(pkt.Array, pkt.Start + o); o += IPv4.Length; targethw.CopyOut(pkt.Array, pkt.Start + o); o += EthernetAddress.Length; targetip.CopyOut(pkt.Array, pkt.Start + o); o += IPv4.Length; return(o); }
public void ArpRequest(IPv4 sourceIP, IPv4 targetIP, Multiplexer !targetMux, ArpRequestCallback callback, object cookie, TimeSpan timeout) { // //XXXX Check pending request does not already exist! // EthernetAddress localMac = targetMux.Adapter.HardwareAddress; AddPendingRequest(targetIP, callback, cookie, timeout); // initiate an arp request... DebugPrint("Initiating request " + "({0},{1}) --> ({2},{3})\n", sourceIP, localMac, targetIP, EthernetAddress.Zero); byte[] data = new byte[ArpFormat.Size + EthernetFormat.Size]; int pos = EthernetFormat.Write(data, 0, localMac, EthernetAddress.Broadcast, EthernetFormat.PROTOCOL_ARP); ArpFormat.Write(data, pos, localMac, sourceIP, ArpFormat.Type.ARP_REQUEST, EthernetAddress.Zero, targetIP); NetPacket pkt = new NetPacket(data); pkt.Mux = targetMux; OnProtocolSend(pkt); }
private TCP MatchTCPSession(IPv4 srcAddress, ushort srcPort, IPv4 destAddress, ushort destPort, byte hash) { ChainedHashNode chainedHashNode = chainedHash[hash]; VTable.Assert(chainedHashNode != null); TCP tcpSession = chainedHashNode.sideCache; if ((tcpSession != null) && IsTCPSessionMatch(tcpSession, srcAddress, srcPort, destAddress, destPort)) { DebugPrint("Found TCP session in cache\n"); return(tcpSession); } tcpSession = null; LinkedListNode currentNode = chainedHashNode.linkedList.head; int numMatches = 0; while (currentNode != null) { TCP tmpTcpSession = currentNode.theObject as TCP; DebugStub.Assert(tmpTcpSession != null); VTable.Assert(tmpTcpSession != null); numMatches++; if (IsTCPSessionMatch(tmpTcpSession, srcAddress, srcPort, destAddress, destPort)) { DebugPrint("Found TCP session -- {0} matches required\n", numMatches); chainedHashNode.sideCache = tmpTcpSession; tcpSession = tmpTcpSession; break; } currentNode = currentNode.nxt; } return(tcpSession); }
internal override void ReceiveEvent(DhcpFormat dhcp) { //DebugStub.WriteLine("FSM DHCP packet SELECTING.\n"); // Check if message is in response to our request if (dhcp.BootMessageType != DhcpFormat.BootType.Reply || dhcp.TransactionID != client.TransactionID || dhcp.GetHardwareAddress() != client.MacAddress) { DebugStub.WriteLine("FSM DHCP bad id.\n"); return; } IPv4 serverAddress = dhcp.NextServerIPAddress; // Check if offered address is valid (ie not zero // and below class E) IPv4 offeredAddress = dhcp.YourIPAddress; if (offeredAddress == IPv4.Any || offeredAddress.IsMulticast()) { DebugStub.WriteLine("FSM DHCP multicast addr.\n"); return; } // Check if message is an offer SortedList offeredOptions = dhcp.GetOptions(); DhcpByteOption messageType = offeredOptions[DhcpMessageType.OptionCode] as DhcpByteOption; if (messageType == null || messageType.Value != (byte)DhcpFormat.MessageType.Offer) { DebugStub.WriteLine("FSM DHCP not an offer.\n"); return; } // Must have parameters byte [] parameters = new byte [] { DhcpSubnetMask.OptionCode, DhcpRouter.OptionCode, // DhcpDomainNameServer.OptionCode }; foreach (byte p in parameters) { IDhcpOption ido = offeredOptions[p] as IDhcpOption; if (ido == null) { DebugStub.WriteLine("FSM DHCP missing option 0x{0:x2}.\n", DebugStub.ArgList(p)); return; } } client.CancelStateTimeout(); client.ChangeState(new DhcpClientStateRequesting(client, serverAddress, offeredAddress, offeredOptions)); }
public static void WriteInterfaceLine([Claims] InterfaceInfo ifInfo, string !ifName) { bool found = false; delete ifInfo.driverName; delete ifInfo.driverVersion; InterfaceIPInfo[] in ExHeap ipConfigs = ifInfo.ipConfigs; if (ipConfigs != null) { for (int i = 0; i < ipConfigs.Length; i++) { InterfaceIPInfo ipc = ipConfigs[i]; IPv4 ipv4 = new IPv4(ipc.address); Console.WriteLine("TESTUTIL:IPAddress: {0,-14}", ipv4); DebugStub.WriteLine("TESTUTIL:IPAddress:{0}:", __arglist(ipv4.ToString())); found |= true; } delete ipConfigs; } if (found == false) { DebugStub.WriteLine("TESTUTIL:IPAddress: Not available."); } }
public bool Connect(IPv4 remoteAddr, ushort remotePort) { this.remoteIPAddress = remoteAddr; this.remotePort = remotePort; return(true); }
internal static int Delete(DeleteConfig !config) { if (config.servers == null) { Console.WriteLine("no servers given"); return(-1); } DNSContract.Imp dnsConn = ((!)config.dnsRef).Acquire(); if (dnsConn == null) { Console.WriteLine("Could not initialize DNS endpoint."); return(1); } dnsConn.RecvReady(); for (int i = 0; i < config.servers.Length; i++) { IPv4 resolver; if (IPv4.Parse(config.servers[i], out resolver) == false) { Console.WriteLine("Invalid IP address: {0}", config.servers[i]); } dnsConn.SendRemoveNameServer((uint)resolver); dnsConn.RecvAck(); } delete dnsConn; return(0); }
public TcpConnection(Ethernet ethHeader, IPv4 ipHeader, Network.Header.Tcp tcpHeader, TTransmitter packetTransmitter, PipeScheduler readScheduler, PipeScheduler writeScheduler, MemoryPool <byte> memoryPool, IConnectionDispatcher connectionDispatcher) { _packetTransmitter = packetTransmitter; _connectionDispatcher = connectionDispatcher; _remoteAddress = ipHeader.SourceAddress; _localAddress = ipHeader.DestinationAddress; _outboundEthernetHeader = new Ethernet() { Destination = ethHeader.Source, Ethertype = EtherType.IPv4, Source = ethHeader.Destination }; var pseudo = new TcpV4PseudoHeader() { Destination = _remoteAddress, Source = _localAddress, ProtocolNumber = Internet.Ip.ProtocolNumber.Tcp, Reserved = 0 }; _pseudoPartialSum = Checksum.PartialCalculate(ref Unsafe.As <TcpV4PseudoHeader, byte>(ref pseudo), Unsafe.SizeOf <TcpV4PseudoHeader>()); LocalAddress = new System.Net.IPAddress(_localAddress.Address); RemoteAddress = new System.Net.IPAddress(_remoteAddress.Address); RemotePort = tcpHeader.SourcePort; LocalPort = tcpHeader.DestinationPort; OutputReaderScheduler = readScheduler ?? throw new ArgumentNullException(nameof(readScheduler)); InputWriterScheduler = writeScheduler ?? throw new ArgumentNullException(nameof(writeScheduler)); MemoryPool = memoryPool ?? throw new ArgumentNullException(nameof(memoryPool)); ConnectionClosed = _closedToken.Token; }
/// <summary> /// Read a named IPv4 parameter from a <c>ProtocolParams</c> /// instance. /// </summary> /// <returns><paramref name="defaultValue"/> if <paramref name="parameters"/> /// is <c>null</c> or <paramref name="parameterName"/> cannot be found. /// Otherwise it returns the named parameter as an IPv4 address.</returns> public static IPv4 LookupIPv4(ProtocolParams parameters, string parameterName, IPv4 defaultValue) { if (parameters == null) { return(defaultValue); } else if (parameterName == null) { throw new ArgumentNullException(); } string sValue = parameters[parameterName]; if (sValue == null) { return(defaultValue); } try { return(IPv4.Parse(sValue)); } catch (FormatException) { Core.Log("Failed on parameter \"{0}\" value \"{1}\"\n", parameterName, sValue); } return(defaultValue); }
// methods: public static int Write(byte [] !pkt, int offset, EthernetAddress srchw, IPv4 srcip, Type operation, EthernetAddress targethw, IPv4 targetip) { int o = offset; pkt[o++] = 0x00; pkt[o++] = 0x01; // hardware type = 0x0001 pkt[o++] = 0x08; pkt[o++] = 0x00; // protocol type = 0x0800 pkt[o++] = 0x06; // hardware addr len (bytes) pkt[o++] = 0x04; // protocol address len (bytes) pkt[o++] = (byte)(((ushort)operation) >> 8); pkt[o++] = (byte)(((ushort)operation) & 0xff); srchw.CopyOut(pkt, o); o += EthernetAddress.Length; srcip.CopyOut(pkt, o); o += IPv4.Length; targethw.CopyOut(pkt, o); o += EthernetAddress.Length; targetip.CopyOut(pkt, o); o += IPv4.Length; return(o); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private void processMessageDatagram(pspsharp.network.protocols.NetPacket packet, pspsharp.network.protocols.EtherFrame frame) throws java.io.EOFException private void processMessageDatagram(NetPacket packet, EtherFrame frame) { IPv4 ipv4 = new IPv4(); ipv4.read(packet); //if (log.DebugEnabled) { Console.WriteLine(string.Format("processMessageDatagram IPv4 {0}", ipv4)); } switch (ipv4.protocol) { case IPv4_PROTOCOL_ICMP: processMessageDatagramICMP(packet, frame, ipv4); break; case IPv4_PROTOCOL_TCP: processMessageTCP(packet, frame, ipv4); break; case IPv4_PROTOCOL_UDP: processMessageUDP(packet, frame, ipv4); break; default: Console.WriteLine(string.Format("processMessageDatagram unknown protocol {0:D}", ipv4.protocol)); break; } }
private void Respond(DhcpFormat request, DhcpFormat.MessageType m) { DhcpFormat response = new DhcpFormat(m); response.TransactionID = request.TransactionID; EthernetAddress hwAddress = request.GetHardwareAddress(); response.SetHardwareAddress(hwAddress); switch (m) { case DhcpFormat.MessageType.Offer: response.NextServerIPAddress = ServerAddress; response.AddOption( DhcpIPAddressLeaseTime.Create(RebindingTime) ); goto case DhcpFormat.MessageType.Ack; case DhcpFormat.MessageType.Ack: response.YourIPAddress = HostAddress; assignedAddress = HostAddress; FillOptions(request, response); break; case DhcpFormat.MessageType.Nak: // Nothing to do break; default: return; } SendResponsePacket(response); }
public void Send(byte[] data, IPv4.Address dest, Int32 destPort) { IPv4.Address source = IPv4.Config.FindNetwork(dest); IPv4.UDPPacket packet = new IPv4.UDPPacket(source, dest, (UInt16)this.localPort, (UInt16)destPort, data); Sys.Console.WriteLine("Sending " + packet.ToString()); IPv4.OutgoingBuffer.AddPacket(packet); }
public static IPv4 CreateIPv4(SqlByte i1, SqlByte i2, SqlByte i3, SqlByte i4) { IPv4 ip = new IPv4(i1.Value, i2.Value, i3.Value, i4.Value); if (ip == null) return IPv4.Null; else return ip; }
public static int SwitchIPv4(ref IPv4 ip1, ref IPv4 ip2) { if ((ip1 == null) || (ip2 == null) || ip1.IsNull || ip2.IsNull) return (0); IPv4 ipTemp = ip1; ip1 = ip2; ip2 = ipTemp; return (1); }
internal static MACAddress Resolve(IPv4.Address ipAddress) { ensureCacheExists(); if (cache.ContainsKey(ipAddress.Hash) == false) { return null; } return cache[ipAddress.Hash]; }
internal static void Update(IPv4.Address ipAddress, MACAddress macAddress) { ensureCacheExists(); if (ipAddress == null) { global::System.Console.Write(""); } UInt32 ip_hash = ipAddress.Hash; if (ip_hash == 0) { return; } if (cache.ContainsKey(ip_hash) == false) { cache.Add(ip_hash, macAddress); } else { cache[ip_hash] = macAddress; } }
internal static bool Contains(IPv4.Address ipAddress) { ensureCacheExists(); return cache.ContainsKey(ipAddress.Hash); }
/// <summary> /// Configure a IP configuration on the given network device. /// <remarks>Multiple IP Configurations can be made, like *nix environments</remarks> /// </summary> /// <param name="nic"><see cref="Cosmos.Hardware.NetworkDevice"/> that will have the assigned configuration</param> /// <param name="config"><see cref="Cosmos.System.Network.IPv4.Config"/> instance that defines the IP Address, Subnet /// Mask and Default Gateway for the device</param> public static void ConfigIP(NetworkDevice nic, IPv4.Config config) { AddressMap.Add(config.IPAddress.Hash, nic); IPv4.Config.Add(config); nic.DataReceived = HandlePacket; }
public byte[] Receive(ref IPv4.EndPoint source) { if (this.rxBuffer.Count < 1) { return null; } DataGram packet = rxBuffer.Dequeue(); source.address = packet.source.address; source.port = packet.source.port; return packet.data; }
public override void Visit(IPv4 node) { this.action(node); }
public override void ExplicitVisit(IPv4 fragment) { _fragments.Add(fragment); }
internal void receiveData(IPv4.UDPPacket packet) { byte[] data = packet.UDP_Data; IPv4.EndPoint source = new IPv4.EndPoint(packet.SourceIP, packet.SourcePort); Sys.Console.WriteLine("Received " + data.Length + " bytes data from " + source.ToString()); this.rxBuffer.Enqueue(new DataGram(data, source)); }
internal DataGram(byte[] data, IPv4.EndPoint src) { this.data = data; this.source = src; }
public UdpClient(IPv4.Address dest, Int32 destPort) : this(0) { this.destination = dest; this.destinationPort = destPort; }
public void Connect(IPv4.Address dest, Int32 destPort) { this.destination = dest; this.destinationPort = destPort; }