private void Discover() { dhcpState = STATE.SELECT; //initialisation stage GameObject dhcpPacket = Instantiate(packetPrefab); //setup packet Packet packet = dhcpPacket.GetComponent <Packet>(); packet.CreatePacket("DHCP"); packet.internet.setIP("0.0.0.0", "src"); packet.internet.setIP("255.255.255.255", "dest"); packet.netAccess.setMAC("FF:FF:FF:FF:FF:FF", "dest"); packet.netAccess.setMAC(pc.MAC, "src"); //attach dhcp component packet.gameObject.AddComponent <DHCP>(); DHCP dhcp = packet.GetComponent <DHCP>(); dhcp.CreateDHCP("DHCPDISCOVER"); //populate dhcp with data dhcp.servAddr = packet.internet.getIP("dest"); dhcp.cliAddr = packet.internet.getIP("src"); //send packet out to network pc.sendPacket(packet); }
/// <summary> /// Initializes networking /// </summary> private static unsafe void initNetworking() { // Networking Network.Init(); Route.Init(); // Networking protocols IPV4.Init(); ICMP.Init(); // Transport protocols UDP.Init(); TCP.Init(); ARP.Init(); DHCP.Init(); // Network drivers E1000.Init(); PCNet2.Init(); RTL8139.Init(); DHCP.Discover(); //Thread packetHandler = new Thread(); //packetHandler.Context.CreateNewContext(Util.MethodToPtr(HttpTest), 0, null, true); //Tasking.KernelTask.AddThread(packetHandler); }
public void Release() { GameObject dhcpPacket = Instantiate(packetPrefab); Packet packet = dhcpPacket.GetComponent <Packet>(); packet.CreatePacket("DHCP"); packet.internet.setIP(pc.IP, "src"); packet.internet.setIP(dhcpserver, "dest"); packet.netAccess.setMAC("FF:FF:FF:FF:FF:FF", "dest"); packet.netAccess.setMAC(pc.MAC, "src"); //attach dhcp component packet.gameObject.AddComponent <DHCP>(); DHCP dhcp = packet.GetComponent <DHCP>(); dhcp.CreateDHCP("DHCPRELEASE"); //populate with data dhcp.cliAddr = pc.IP; dhcp.cliMac = pc.MAC; dhcp.leaseAddr = pc.IP; dhcp.servAddr = dhcpserver; dhcpState = STATE.INIT; pc.sendPacket(packet); }
//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)); } }
private void UseConfig(Packet packet) { dhcpState = STATE.BOUND; DHCP dhcp = packet.gameObject.GetComponent <DHCP>(); dhcpserver = dhcp.servAddr; pc.GetComponent <Subnet>().SetConfiguration(dhcp); }
public void Get() { var dhcp = new DHCP { Bytes = new Byte[32] }; dhcp.SetByte(0, 1); dhcp.OperationCode.Should().Be(1); }
public void Get() { var dhcp = new DHCP { Bytes = new Byte[32] }; dhcp.SetByte(1, 1); dhcp.HardwareType.Should().Be(1); }
public void Get() { var dhcp = new DHCP { Bytes = new Byte[32] }; dhcp.SetByte(2, 6); dhcp.HardwareLength.Should().Be(6); }
public void Get() { var dhcp = new DHCP { Bytes = new Byte[32] }; dhcp.SetByte(10, 0xAB); dhcp.SetByte(11, 0xCD); dhcp.Flags.Should().Be(0xABCD); }
public void Set() { var dhcp = new DHCP { Bytes = new Byte[32] }; dhcp.OperationCode = 2; dhcp.OperationCode.Should().Be(2); dhcp.GetByte(0).Should().Be(2); }
public void Get() { var dhcp = new DHCP { Bytes = new Byte[32] }; dhcp.SetByte(8, 0xAB); dhcp.SetByte(9, 0xCD); dhcp.Seconds.Should().Be(0xABCD); }
public void dhcp_discover() { var dhcp = new DHCP { Bytes = new Byte[] { 0x01, 0x01, 0x06, 0x00, 0x00, 0x00, 0x3d, 0x1d, 0x12, 0x34, 0x56, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x82, 0x01, 0xfc, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, 0x53, 0x63, 0x35, 0x01, 0x01, 0x3d, 0x07, 0x01, 0x00, 0x0b, 0x82, 0x01, 0xfc, 0x42, 0x32, 0x04, 0x00, 0x00, 0x00, 0x00, 0x37, 0x04, 0x01, 0x03, 0x06, 0x2a, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }; dhcp.OperationCode.Should().Be(1); dhcp.HardwareType.Should().Be(1); dhcp.HardwareLength.Should().Be(6); dhcp.TransactionId.Should().Be(0x00003d1d); dhcp.Seconds.Should().Be(0x1234); dhcp.Flags.Should().Be(0x5678); dhcp.ClientIPAddress.ToString().Should().Be("0.0.0.0"); dhcp.YourClientIPAddress.ToString().Should().Be("0.0.0.0"); dhcp.ServerIPAddress.ToString().Should().Be("0.0.0.0"); dhcp.GatewayIPAddress.ToString().Should().Be("0.0.0.0"); dhcp.ClientHardwareAddress.ToString().Should().Be("00:0B:82:01:FC:42"); }
public void Set() { var dhcp = new DHCP { Bytes = new Byte[32] }; dhcp.Seconds = 0xCDEF; dhcp.Seconds.Should().Be(0xCDEF); dhcp.GetByte(8).Should().Be(0xCD); dhcp.GetByte(9).Should().Be(0xEF); }
public void Set() { var dhcp = new DHCP { Bytes = new Byte[32] }; dhcp.Flags = 0xCDEF; dhcp.Flags.Should().Be(0xCDEF); dhcp.GetByte(10).Should().Be(0xCD); dhcp.GetByte(11).Should().Be(0xEF); }
public void Get() { var dhcp = new DHCP { Bytes = new Byte[32] }; dhcp.SetByte(24, 192); dhcp.SetByte(25, 168); dhcp.SetByte(26, 0); dhcp.SetByte(27, 1); dhcp.GatewayIPAddress.ToString().Should().Be("192.168.0.1"); }
public void Get() { var dhcp = new DHCP { Bytes = new Byte[32] }; dhcp.SetByte(4, 0x12); dhcp.SetByte(5, 0x34); dhcp.SetByte(6, 0x56); dhcp.SetByte(7, 0x78); dhcp.TransactionId.Should().Be(0x12345678); }
public void Get() { var dhcp = new DHCP { Bytes = new Byte[32] }; dhcp.SetByte(20, 192); dhcp.SetByte(21, 168); dhcp.SetByte(22, 0); dhcp.SetByte(23, 1); dhcp.ServerIPAddress.ToString().Should().Be("192.168.0.1"); }
public void Get() { var dhcp = new DHCP { Bytes = new Byte[32] }; dhcp.SetByte(16, 192); dhcp.SetByte(17, 168); dhcp.SetByte(18, 0); dhcp.SetByte(19, 1); dhcp.YourClientIPAddress.ToString().Should().Be("192.168.0.1"); }
public void Get() { var dhcp = new DHCP { Bytes = new Byte[32] }; dhcp.SetByte(12, 192); dhcp.SetByte(13, 168); dhcp.SetByte(14, 0); dhcp.SetByte(15, 1); dhcp.ClientIPAddress.ToString().Should().Be("192.168.0.1"); }
public void Set() { var dhcp = new DHCP { Bytes = new Byte[32] }; dhcp.TransactionId = 0x12345678; dhcp.TransactionId.Should().Be(0x12345678); dhcp.GetByte(4).Should().Be(0x12); dhcp.GetByte(5).Should().Be(0x34); dhcp.GetByte(6).Should().Be(0x56); dhcp.GetByte(7).Should().Be(0x78); }
void RemoveLease(Packet packet) { //strip dhcp from packet DHCP dhcp = packet.gameObject.GetComponent <DHCP>(); //get lease to remove it string leaseIP = dhcp.leaseAddr; bool value; if (IPList.TryGetValue(leaseIP, out value)) { //if it's in the list, set it free IPList[leaseIP] = false; numLeases++; } }
public void Get() { var dhcp = new DHCP { Bytes = new Byte[64] }; dhcp.SetByte(28, 0x12); dhcp.SetByte(29, 0x34); dhcp.SetByte(30, 0x56); dhcp.SetByte(31, 0x78); dhcp.SetByte(32, 0x9A); dhcp.SetByte(33, 0xBC); dhcp.ClientHardwareAddress.ToString().Should().Be("12:34:56:78:9A:BC"); }
public void SetConfiguration(DHCP dhcp) { //set ip GetComponent <PC>().IP = dhcp.leaseAddr; //set mask mask = dhcp.mask; validMask = ValidateMask(mask); if (GetComponent <PC>()) { network = ResolveNetwork(GetComponent <PC>().IP); broadcast = ResolveBroadcast(GetComponent <PC>().IP); defaultGateway = dhcp.gateway; Debug.Log(GetComponent <PC>().GetID() + ": Network is: " + network); } CalculateCIDR(); }
public void Set() { var dhcp = new DHCP { Bytes = new Byte[32] }; dhcp.ServerIPAddress = new IPAddress { Bytes = new Byte[] { 192, 168, 0, 1 } }; dhcp.ServerIPAddress.ToString().Should().Be("192.168.0.1"); dhcp.GetByte(20).Should().Be(192); dhcp.GetByte(21).Should().Be(168); dhcp.GetByte(22).Should().Be(0); dhcp.GetByte(23).Should().Be(1); }
public void Set() { var dhcp = new DHCP { Bytes = new Byte[32] }; dhcp.GatewayIPAddress = new IPAddress { Bytes = new Byte[] { 192, 168, 0, 1 } }; dhcp.GatewayIPAddress.ToString().Should().Be("192.168.0.1"); dhcp.GetByte(24).Should().Be(192); dhcp.GetByte(25).Should().Be(168); dhcp.GetByte(26).Should().Be(0); dhcp.GetByte(27).Should().Be(1); }
public void Set() { var dhcp = new DHCP { Bytes = new Byte[32] }; dhcp.YourClientIPAddress = new IPAddress { Bytes = new Byte[] { 192, 168, 0, 1 } }; dhcp.YourClientIPAddress.ToString().Should().Be("192.168.0.1"); dhcp.GetByte(16).Should().Be(192); dhcp.GetByte(17).Should().Be(168); dhcp.GetByte(18).Should().Be(0); dhcp.GetByte(19).Should().Be(1); }
public void Set() { var dhcp = new DHCP { Bytes = new Byte[64] }; dhcp.ClientHardwareAddress = new MACAddress { Bytes = new Byte[] { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC } }; dhcp.ClientHardwareAddress.ToString().Should().Be("12:34:56:78:9A:BC"); dhcp.GetByte(28).Should().Be(0x12); dhcp.GetByte(29).Should().Be(0x34); dhcp.GetByte(30).Should().Be(0x56); dhcp.GetByte(31).Should().Be(0x78); dhcp.GetByte(32).Should().Be(0x9A); dhcp.GetByte(33).Should().Be(0xBC); }
//TODO: send this client to the server to store private void Request(Packet packet) { //request stage dhcpState = STATE.REQUEST; /* * Packet arpReq = new ARP("ARP REQUEST"); * arpReq.internet.setIP(GetComponent<PC>().getIP(), "src"); //set the src ip * arpReq.internet.setIP(packet.internet.getIP("dest"), "dest"); //set the dest ip * arpReq.netAccess.setMAC(GetComponent<PC>().MAC, "src"); * GetComponent<PC>().requestARP(arpReq);*/ DHCP dhcp = packet.gameObject.GetComponent <DHCP>(); dhcp.type = "DHCPREQUEST"; dhcp.servAddr = packet.internet.getIP("src"); packet.internet.setIP("0.0.0.0", "src"); packet.internet.setIP(dhcp.servAddr, "dest"); packet.netAccess.setMAC(packet.netAccess.getMAC("src"), "dest"); packet.netAccess.setMAC(dhcp.cliMac, "src"); pc.sendPacket(packet); }
private void Offer(Packet packet) { //fill in lease addr, mask, gateway, cliMac, DHCP dhcp = packet.GetComponent <DHCP>(); dhcp.type = "DHCPOFFER"; dhcp.cliMac = packet.netAccess.getMAC("src"); dhcp.mask = netmask; dhcp.gateway = gateway; if ((dhcp.leaseAddr = GetLease()) == null) { //handle no leases left Debug.LogAssertion("SERVERDHCP: NO LEASES LEFT"); } else { packet.netAccess.setMAC(GetComponent <Router>().getMAC(), "src"); packet.netAccess.setMAC(dhcp.cliMac, "dest"); packet.internet.setIP(gateway, "src"); packet.internet.setIP("255.255.255.255", "dest"); port.send(packet); } }
//forwards incoming packets //Transparent Bridge Algorithm /* * 1. if dest mac is in mactable, send to port * 2. if outport is the same as in port, ignore packet * 3. if dest mac is not in the mactable, flood vlan that port came from * 4. if dest mac is broadcast, flood vlan that port came from * */ public bool handlePacket(Packet packet, Port incomingPort) { Debug.Log(id + ": Receiving packet"); //dhcp check if (packet.type.Contains("DHCP")) { if (packet.GetComponent <DHCP>().type.Equals("DHCPREQUEST")) { DHCP dhcp = packet.GetComponent <DHCP>(); Debug.LogAssertion(id + ": Receiving DHCP PACKET of type: " + dhcp.type); } } bool IsInMacTable = false; //check if mac is recognised for (int i = 0; i < macTable.Count; i++) { //check if dest mac is in mactable if (packet.netAccess.getMAC("dest").Equals(macTable[i])) { IsInMacTable = true; } } //if it is.... if (IsInMacTable) { //if outgoing port is the same as incoming OR if the vlans are not the same if (getPort(packet.netAccess.getMAC("dest")).Equals(incomingPort) || (getPort(packet.netAccess.getMAC("dest")).link.vlan != incomingPort.link.vlan)) { //if tagged if (packet.gameObject.GetComponent <Link>()) { //it came from a trunk and is either going through another trunk, an access link, or it's faulty if (incomingPort.link.type.Equals("trunk")) { if (getPort(packet.netAccess.getMAC("dest")).link.type.Equals("trunk")) { return(getPort(packet.netAccess.getMAC("dest")).send(packet)); } else if (getPort(packet.netAccess.getMAC("dest")).link.type.Equals("access")) { //if its going out an access link, make sure to remove the vlan tag Destroy(packet.gameObject.GetComponent <Link>()); return(getPort(packet.netAccess.getMAC("dest")).send(packet)); } } //send it through trunked ports if (getPort(packet.netAccess.getMAC("dest")).link.type.Equals("trunk")) { return(getPort(packet.netAccess.getMAC("dest")).send(packet)); } //if the vlan tag matches the port if (packet.gameObject.GetComponent <Link>().vlan.Equals(getPort(packet.netAccess.getMAC("dest")).link.vlan)) { return(getPort(packet.netAccess.getMAC("dest")).send(packet)); } else { return(false); } } else { //if its not tagged, it's come from an access link and either going to a trunk or a faulty packet if (incomingPort.link.type.Equals("access") && getPort(packet.netAccess.getMAC("dest")).link.type.Equals("trunk")) { //tag the packet with vlan info Link vlanTag = packet.gameObject.AddComponent <Link>(); vlanTag.vlan = incomingPort.link.vlan; //send packet through trunk return(getPort(packet.netAccess.getMAC("dest")).send(packet)); } else { return(false); } } } //else if the mac address is broadcast, do it else if (packet.netAccess.getMAC("dest").Equals("FF:FF:FF:FF:FF:FF")) { return(broadcast(packet, incomingPort)); } else { //else forward packet to port with same vlan return(getPort(packet.netAccess.getMAC("dest")).send(packet)); } } //if it isnt else { //just broadcast on vlan anyway , flood return(broadcast(packet, incomingPort)); } /* * //if mac is addressed to a broadcast, do so * if (packet.netAccess.getMAC ("dest").Equals ("FF:FF:FF:FF:FF:FF")) { * Debug.Log(id + ": BroadCast MAC ADDRESS!"); * broadcast (packet, incomingPort); * } * //else just unicast to MAC address user * else * { * Debug.Log(id + ": Sending packet to specific MAC: " + packet.netAccess.getMAC("dest")); * //iterate through mactable * for (int i = 0; i < macTable.Count; i++) { * //if dest mac matches one on table, forward * if(packet.netAccess.getMAC("dest").Equals(macTable[i])){ * getPort (macTable[i]).send (packet); * } * } * * * }*/ }