/// <summary> /// Find route "mac" address /// </summary> /// <param name="ip"></param> public unsafe static bool FindRoute(byte[] ip, byte *DestMac) { if (InLocalNetwork(ip)) { ARP.Lookup(ip, DestMac); if (DestMac[0] == 0x00 && DestMac[1] == 0x00 && DestMac[2] == 0x00 && DestMac[3] == 0x00 && DestMac[4] == 0x00 && DestMac[5] == 0x00) { byte[] mac = new byte[6]; for (int i = 0; i < 6; i++) { mac[i] = 0xFF; } ARP.ArpSend(ARP.OP_REQUEST, mac, ip); return(false); } } else { for (int i = 0; i < 6; i++) { DestMac[i] = m_gateway_mac[i]; } } return(true); }
/// <summary> /// FS finddir /// </summary> /// <param name="node">The node</param> /// <param name="name">The name to look for</param> /// <returns>The node</returns> private static unsafe Node findDirImpl(Node node, string name) { byte[] ip = NetworkTools.StringToIp(name); if (ip == null) { return(null); } byte *dstMac = (byte *)Heap.Alloc(6); Memory.Memset(dstMac, 0, 6); ARP.Lookup(ip, dstMac); if (dstMac[0] == 0x00 && dstMac[1] == 0x00 && dstMac[2] == 0x00 && dstMac[3] == 0x00 && dstMac[4] == 0x00 && dstMac[5] == 0x00) { byte[] mac = new byte[6]; for (int i = 0; i < 6; i++) { mac[i] = 0xFF; } ARP.ArpSend(ARP.OP_REQUEST, mac, ip); Heap.Free(mac); return(null); } Heap.Free(dstMac); return(new Node()); }
/// <summary> /// Set gateway /// </summary> /// <param name="ip">IP</param> public unsafe static void SetGateway(byte[] ip) { /* * We just always assume subnet is 255.255.255.0 */ for (int i = 0; i < 3; i++) { m_ip_local_network[i] = ip[i]; } ARP.Lookup(ip, (byte *)Util.ObjectToVoidPtr(m_gateway_mac)); }