public override bool Send(NetPacket pkt) { if (dhcpActive) { EthernetFrame eth = new EthernetFrame(pkt); if (eth.Protocol == (UInt16)EtherFrameType.IPv4) { IPPacket ipp = (IPPacket)eth.Payload; if (ipp.Protocol == (byte)IPType.UDP) { UDP udppkt = (UDP)ipp.Payload; if (udppkt.DestinationPort == 67) { dhcp.Send(udppkt); return true; } } } } return false; }
public override bool Recv(ref NetPacket pkt) { if (dhcpActive) { IPPayload retDHCP = dhcp.Recv(); if (retDHCP != null) { IPPacket retIP = new IPPacket(retDHCP); retIP.DestinationIP = new byte[] { 255, 255, 255, 255 }; retIP.SourceIP = DefaultDHCPConfig.DHCP_IP; EthernetFrame ef = new EthernetFrame(retIP); ef.SourceMAC = virturalDHCPMAC; ef.DestinationMAC = ps2MAC; ef.Protocol = (UInt16)EtherFrameType.IPv4; pkt = ef.CreatePacket(); return true; } } return false; }
public override bool Send(NetPacket pkt) { if (base.Send(pkt)) { return true; } //get_eth_protocol_hi(pkt.buffer); //get_eth_protocol_lo(pkt.buffer); //get_dest_eth_mac(pkt.buffer); //get_src_eth_mac(pkt.buffer); //get_dest_arp_mac(pkt.buffer,14); //get_src_arp_mac(pkt.buffer,14); //get_dest_arp_ip(pkt.buffer, 14); //get_dest_ip_ip(pkt.buffer, 14); EthernetFrame eth = null; if (!switched) { eth = new EthernetFrame(pkt); //If intercept DHCP, then get IP from DHCP process if (eth.Protocol == (UInt16)EtherFrameType.IPv4) { ps2IP = ((IPPacket)eth.Payload).SourceIP; //MAC } else if (eth.Protocol == (UInt16)EtherFrameType.ARP) { ps2IP = ((ARPPacket)eth.Payload).SenderProtocolAddress; //MAC //Need to also set Host MAC (SenderProtocolAddress) //Utils.memcpy(ref pkt.buffer, 14 + 8, host_mac, 0, 6); //ARP SetSrcMAC_ARP(pkt.buffer, 14, hostMAC); } //Set Sorce mac to host_mac SetSrcMAC_Eth(pkt.buffer, hostMAC); } else //Switched { byte[] host_mac_pkt = new byte[pkt.size]; Array.Copy(pkt.buffer, host_mac_pkt, pkt.size); //here we send a boadcast with both host_mac and ps2_mac //is destination address broadcast? if (Utils.memcmp(GetDestMAC_Eth(host_mac_pkt), 0, broadcastMAC, 0, 6)) { //Set Dest to host mac SetDestMAC_Eth(host_mac_pkt, hostMAC); PcapSendIO(host_mac_pkt, pkt.size); } } if (PcapSendIO(pkt.buffer, pkt.size)) { return false; } else { return true; } }