public void UDP_DoubleSetup() { Assert.True(UDP.Setup()); Assert.True(UDP.Setup()); }
public Client(int _clientId) { id = _clientId; tcp = new TCP(id); udp = new UDP(id); }
public NanoEndPoint(string host, ushort port) { address = new Address(); address.port = port; UDP.SetHostName(ref address, host); }
//bool thing = false; public override IPPayload Recv() { if (!open) { return(null); } if (isFixedPort) { return(null); } if (client.Available != 0) { IPEndPoint remoteIPEndPoint; //this isn't a filter remoteIPEndPoint = new IPEndPoint(IPAddress.Any, 0); byte[] recived = null; try { recived = client.Receive(ref remoteIPEndPoint); Log_Verb("Got Data"); } catch (SocketException err) { Log_Error("UDP Recv Error: " + err.Message); Log_Error("Error Code: " + err.ErrorCode); RaiseEventConnectionClosed(); return(null); } UDP iRet = new UDP(recived); iRet.DestinationPort = srcPort; iRet.SourcePort = destPort; if (isMulticast) { Log_Error(remoteIPEndPoint.ToString()); DestIP = remoteIPEndPoint.Address.GetAddressBytes(); //assumes ipv4 iRet.SourcePort = (UInt16)remoteIPEndPoint.Port; } lock (deathClock) { deathClock.Restart(); } if (destPort == 53) { Log_Info("DNS Packet Sent From " + remoteIPEndPoint.Address); Log_Info("Contents"); PacketReader.DNS.DNS pDNS = new PacketReader.DNS.DNS(recived); } return(iRet); } lock (deathClock) { if (deathClock.Elapsed.TotalSeconds > MAX_IDLE) { client.Close(); RaiseEventConnectionClosed(); } } return(null); }
public override bool Send(IPPayload payload) { ICMP icmp = (ICMP)payload; switch (icmp.Type) { case 8: //Echo //Code == zero Log_Verb("Send Ping"); lock (sentry) { open += 1; } PingData pd; pd.Data = icmp.Data; pd.HeaderData = icmp.HeaderData; Ping nPing = new Ping(); nPing.PingCompleted += PingCompleate; lock (sentry) { pings.Add(nPing); } nPing.SendAsync(new IPAddress(DestIP), pd); System.Threading.Thread.Sleep(1); //Hack Fix break; case 3: // switch (icmp.Code) { case 3: Log_Error("Recived Packet Rejected, Port Closed"); IPPacket retPkt = new IPPacket(icmp); byte[] srvIP = retPkt.SourceIP; byte prot = retPkt.Protocol; UInt16 srvPort = 0; UInt16 ps2Port = 0; switch (prot) { case (byte)IPType.TCP: TCP tcp = (TCP)retPkt.Payload; srvPort = tcp.SourcePort; ps2Port = tcp.DestinationPort; break; case (byte)IPType.UDP: UDP udp = (UDP)retPkt.Payload; srvPort = udp.SourcePort; ps2Port = udp.DestinationPort; break; } ConnectionKey Key = new ConnectionKey(); Key.IP0 = srvIP[0]; Key.IP1 = srvIP[1]; Key.IP2 = srvIP[2]; Key.IP3 = srvIP[3]; Key.Protocol = prot; Key.PS2Port = ps2Port; Key.SRVPort = srvPort; //is from NormalPort Session s; connections.TryGetValue(Key, out s); if (s != null) { s.Reset(); Log_Info("Reset Rejected Connection"); break; } //Is from FixedPort Key.IP0 = 0; Key.IP1 = 0; Key.IP2 = 0; Key.IP3 = 0; Key.SRVPort = 0; connections.TryGetValue(Key, out s); if (s != null) { s.Reset(); Log_Info("Reset Rejected Connection"); break; } Log_Error("Failed To Reset Rejected Connection"); break; default: throw new NotImplementedException("Unsupported ICMP Code For Destination Unreachable" + icmp.Code); } break; default: throw new NotImplementedException("Unsupported ICMP Type" + icmp.Type); } return(true); }
public Client(int id) { this.id = id; tcp = new TCP(id); udp = new UDP(id); }
public ServerSideClient(int clientId) { id = clientId; tcp = new TCP(id); udp = new UDP(id); }
public void SendPlayerData() { string keysPressed = ""; for (int i = 33; i <= 122; i++) { if (Input.GetKey(((char)i).ToString().ToLower() + "")) { string input = ((char)i).ToString().ToLower(); if (!keysPressed.Contains(input)) { keysPressed += input; } } } if (Input.GetKey(KeyCode.Space)) { keysPressed += " "; } string clientData = DataParserAndFormatter.GetClientInputFormatted(keysPressed, Input.GetMouseButtonDown(0), Input.GetMouseButtonDown(1), player.transform.rotation, camera.transform.rotation, camera.transform.position, UDP.GetLocalIPAddress()); udp.Send(clientData, serverIP); //send position and orientation and ipaddr of client to server for update }
public void SendClassData(String classPath, int[] abilityIds) { udp.Send(DataParserAndFormatter.GetClassPathAndAbilityIdsFormatted(classPath, abilityIds, UDP.GetLocalIPAddress()), serverIP); }
public bool Poll() { return(UDP.Poll(socket, 0) > 0); }
public void Send(IEndPoint endPoint, byte[] packet, int length) { var nanoEndPoint = (NanoEndPoint)endPoint; UDP.Send(socket, ref nanoEndPoint.address, packet, length); }
public void UDP_SetupCleanup() { Assert.True(UDP.Setup()); Assert.True(UDP.Cleanup()); }
public void UDP_DoubleCleanup() { Assert.True(UDP.Cleanup()); Assert.True(UDP.Cleanup()); }
public void UDP_Cleanup() { Assert.True(UDP.Cleanup()); }
public void Start() { tcp = new TCP(); udp = new UDP(); }
private Client() { tcp = new TCP(this); udp = new UDP(this); }
public Client(int clientId) { Id = clientId; Tcp = new TCP(Id); Udp = new UDP(Id); }
public ServerSideClient(int _client_id) { id = _client_id; tcp = new TCP(_client_id); udp = new UDP(_client_id); }
private void Start() { tcp = new TCP(); udp = new UDP(); DontDestroyOnLoad(this); }
//htonl(0x7F000001); // 127.0.0.1 public void Append(IPEndPoint source, IPEndPoint destination, ProtocolType protocol, byte[] payload, DateTime?timestamp = null) { PcapItemHeader packetHeader; Ethernet packetEthernet; IPv4 packetIP; byte[] sourceBytes, destinationBytes; byte[] payloadItemHeader, payloadEthernet, payloadIP, payloadTransport, payloadData; int index; switch (protocol) { case ProtocolType.Udp: UDP packetUDP; packetUDP = new UDP((UInt16)source.Port, (UInt16)destination.Port, (UInt16)payload.Length); payloadTransport = packetUDP.GetBytes(); break; case ProtocolType.Tcp: TCP packetTCP; UInt16 connection1, connection2; UInt64 seqAck; UInt32 seq, ack; connection1 = tcpConnectionId(source, destination); connection2 = tcpConnectionId(destination, source); if (tcpWindows.ContainsKey(connection1)) { seqAck = tcpWindows[connection1]; seq = (UInt32)(seqAck >> 32); ack = (UInt32)seqAck; } else { seq = 1; ack = 1; seqAck = ((UInt64)seq << 32) | ack; tcpWindows.Add(connection1, seqAck); } packetTCP = new TCP((UInt16)source.Port, (UInt16)destination.Port, seq, ack); seq += (UInt32)payload.Length; seqAck = ((UInt64)seq << 32) | ack; tcpWindows[connection1] = seqAck; if (tcpWindows.ContainsKey(connection2)) { seqAck = tcpWindows[connection2]; seq = (UInt32)(seqAck >> 32); ack = (UInt32)payload.Length; seqAck = ((UInt64)seq << 32) | ack; tcpWindows[connection2] = seqAck; } else { seq = 1; ack = (UInt32)payload.Length; seqAck = ((UInt64)seq << 32) | ack; tcpWindows.Add(connection2, seqAck); } payloadTransport = packetTCP.GetBytes(); break; case ProtocolType.IP: payloadTransport = new byte[] { }; break; default: throw new System.ArgumentException("This protocol is not supported", "protocol"); } /* ipv4 */ packetIP = new IPv4(source.Address, destination.Address, protocol, (UInt16)(payloadTransport.Length + payload.Length)); payloadIP = packetIP.GetBytes(); /* ethernet */ sourceBytes = source.Address.GetAddressBytes(); destinationBytes = destination.Address.GetAddressBytes(); packetEthernet = new Ethernet(new byte[3] { sourceBytes[1], sourceBytes[2], sourceBytes[3] }, new byte[3] { destinationBytes[1], destinationBytes[2], destinationBytes[3] }); payloadEthernet = packetEthernet.GetBytes(); /* pcap packet header */ if (timestamp == null) { timestamp = DateTime.UtcNow; } packetHeader = new PcapItemHeader((DateTime)timestamp, (UInt32)(payloadEthernet.Length + payloadIP.Length + payloadTransport.Length + payload.Length)); payloadItemHeader = packetHeader.GetBytes(); payloadData = new byte[payloadItemHeader.Length + payloadEthernet.Length + payloadIP.Length + payloadTransport.Length + payload.Length]; index = 0; payloadItemHeader.CopyTo(payloadData, index); index += payloadItemHeader.Length; payloadEthernet.CopyTo(payloadData, index); index += payloadEthernet.Length; payloadIP.CopyTo(payloadData, index); index += payloadIP.Length; payloadTransport.CopyTo(payloadData, index); index += payloadTransport.Length; payload.CopyTo(payloadData, index); index += payload.Length; content.Write(payloadData, 0, payloadData.Length); }
public override bool Send(IPPayload payload) { lock (deathClock) { deathClock.Restart(); } UDP udp = (UDP)payload; if (destPort != 0) { //client already created if (!(udp.DestinationPort == destPort && udp.SourcePort == srcPort)) { Log_Error("UDP packet invalid for current session (Duplicate key?)"); return(false); } } else { //create client destPort = udp.DestinationPort; srcPort = udp.SourcePort; //Multicast address start with 0b1110 if ((DestIP[0] & 0xF0) == 0xE0) { isMulticast = true; } //needs testing if (isMulticast) { Log_Info("Is Multicast"); client = new UdpClient(new IPEndPoint(adapterIP, 0)); //client.JoinMulticastGroup(address); } else { IPAddress address = new IPAddress(DestIP); client = new UdpClient(new IPEndPoint(adapterIP, 0)); client.Connect(address, destPort); } if (srcPort != 0) { open = true; } } if (destPort == 53) { Log_Info("DNS Packet Sent To " + new IPAddress(DestIP)); Log_Info("Contents"); PacketReader.DNS.DNS pDNS = new PacketReader.DNS.DNS(udp.GetPayload()); } if (isBroadcast) { client.Send(udp.GetPayload(), udp.GetPayload().Length, new IPEndPoint(IPAddress.Broadcast, destPort)); } else if (isMulticast | isFixedPort) { client.Send(udp.GetPayload(), udp.GetPayload().Length, new IPEndPoint(new IPAddress(DestIP), destPort)); } else { client.Send(udp.GetPayload(), udp.GetPayload().Length); } if (srcPort == 0) { RaiseEventConnectionClosed(); } return(true); }
public bool SendUDP(ConnectionKey Key, IPPacket ipPkt) { Log_Verb("UDP"); UDP udp = (UDP)ipPkt.Payload; Key.PS2Port = udp.SourcePort; Key.SRVPort = udp.DestinationPort; if (udp.DestinationPort == 67) { //DHCP return(dhcpServer.Send(ipPkt.Payload)); } if (udp.DestinationPort == 53 && Utils.memcmp(ipPkt.DestinationIP, 0, DefaultDHCPConfig.DHCP_IP, 0, 4)) { //DNS return(dnsServer.Send(ipPkt.Payload)); } int res = SendFromConnection(Key, ipPkt); if (res == 1) { return(true); } else if (res == 0) { return(false); } else { Log_Verb("Creating New Connection with key " + Key); Log_Info("Creating New UDP Connection with Dest Port " + udp.DestinationPort); UDPSession s; if (udp.SourcePort == udp.DestinationPort || //Used for LAN games that assume the destination port Utils.memcmp(ipPkt.DestinationIP, 0, dhcpServer.Broadcast, 0, 4) || Utils.memcmp(ipPkt.DestinationIP, 0, dhcpServer.LimitedBroadcast, 0, 4)) //Broadcast packets { //Limit of one udpclient per local port //need to reuse the udpclient UDPFixedPort fPort; if (fixedUDPPorts.ContainsKey(udp.SourcePort)) { Log_Verb("Using Existing UDPFixedPort"); fPort = fixedUDPPorts[udp.SourcePort]; } else { ConnectionKey fKey = new ConnectionKey { Protocol = (byte)IPType.UDP, PS2Port = udp.SourcePort, SRVPort = 0 }; Log_Verb("Creating New UDPFixedPort with key " + fKey); Log_Info("Creating New UDPFixedPort with Port " + udp.SourcePort); fPort = new UDPFixedPort(fKey, adapterIP, udp.SourcePort); fPort.ConnectionClosedEvent += HandleFixedPortClosed; fPort.DestIP = new byte[] { 0, 0, 0, 0 }; fPort.SourceIP = dhcpServer.PS2IP; if (!connections.TryAdd(fKey, fPort) | !fixedUDPPorts.TryAdd(udp.SourcePort, fPort)) { fPort.Dispose(); throw new Exception("Connection Add Failed"); } } s = fPort.NewClientSession(Key, Utils.memcmp(ipPkt.DestinationIP, 0, dhcpServer.Broadcast, 0, 4) | Utils.memcmp(ipPkt.DestinationIP, 0, dhcpServer.LimitedBroadcast, 0, 4)); } else { s = new UDPSession(Key, adapterIP); } s.ConnectionClosedEvent += HandleConnectionClosed; s.DestIP = ipPkt.DestinationIP; s.SourceIP = dhcpServer.PS2IP; if (!connections.TryAdd(Key, s)) { throw new Exception("Connection Add Failed"); } return(s.Send(ipPkt.Payload)); } }
// This method describes the main logic functionality of the Server // FIXME override Processor_Loop? protected static void SwitchLogic() { ulong local_icmp_code_type, local_chksum_udp, d, u; //, ipv4; uint i = 0, free = 0, mem_cnt = 0; byte ii = 0, local_magic_num = 0, local_opcode = 0; uint pkt_size = 0; bool exist = false, is_ipv4 = false, is_udp = false, is_icmp = false; uint cam_addr = 0, tmp_addr = 0, addr = 0; bool good_IP_checksum = false, error = false; ulong local_key_value, local_extras, local_flag; while (true) // Process packets indefinately { pkt_size = ReceiveFrame(); // Extract information from the Ethernet, IP, TCP, UDP frames for (i = 0; i <= 11; i++) { d = tdata[i]; u = tuser_low[i]; Kiwi.Pause(); Extract_headers(i, d, u); } Kiwi.Pause(); // We need to store the shared-threat variables here // otherwise if we use it explicity we get long compilation times is_ipv4 = IPv4; is_udp = proto_UDP; is_icmp = proto_ICMP; local_magic_num = magic_num; local_opcode = opcode; local_icmp_code_type = ICMP_code_type; local_chksum_udp = chksum_UDP; local_key_value = key_value; local_extras = extras; local_flag = flag; Kiwi.Pause(); // ############################# // # Server Logic -- START // ############################# // ####################################################################################### // # MEMCACHED SERVER if (is_ipv4 && is_udp) { chksumIP = Emu.Protocols.IPv4.calc_IP_checksum(dataplane.tdata); good_IP_checksum = (chksumIP == (ulong)0x00); //Kiwi.Pause(); if ((local_magic_num == Memcached.REQUEST) && good_IP_checksum) //&& (local_chksum_udp==(ulong)0x00ffff)) { // Interpret Memcached opcode as CAM operation. var cam_opcode = Memcached.Memcached_Operation(local_opcode); // Execute CAM operation. addr = CAM_Control(cam_opcode, key); Kiwi.Pause(); // Execute Memcached operation. switch (local_opcode) { case Memcached.SET_op: VALUES_MEM[addr] = key_value; EXTRAS_MEM[addr] = extras; break; case Memcached.GET_op: key_value = VALUES_MEM[addr]; flag = EXTRAS_MEM[addr]; break; default: break; } error = addr == (uint)MEM_SIZE; Kiwi.Pause(); chksum_UDP = (ulong)0x00; chksumIP = 0x00; swap_multiple_fields(is_udp, is_icmp); Kiwi.Pause(); // Create the response packet + reset appropriate fields(ex. UDP checksum) switch (local_opcode) { case Memcached.SET_op: pkt_size = Memcached.Memcached_SET(ref dataplane.tdata, IP_total_length, UDP_total_length); // Set the correct metadata for the datapath // Fixed size response packet for SET - DELETE success tuser_low[0] = (src_port << 24) | (src_port << 16) | (ulong)74; tkeep[9] = (byte)0x03; //pkt_size = 8; break; case Memcached.DELETE_op: pkt_size = Memcached_DELETE(error); break; case Memcached.GET_op: pkt_size = Memcached_GET(error); break; } Kiwi.Pause(); tmp = tdata[3]; Kiwi.Pause(); chksumIP = Emu.Protocols.IPv4.calc_IP_checksum(dataplane.tdata); Kiwi.Pause(); // Set the new IP checksum - as we dont change any info in the header, // the checksum should remane the same - but anyway recalc and put it back tdata[3] = (chksumIP >> 8 | (chksumIP & (ulong)0x00ff) << 8) | tmp; Kiwi.Pause(); // Here is the UDP checksum - clear it and preserve the other data tmp = tdata[5]; //we have already clear the UDP checksum Kiwi.Pause(); // The 4th element in the buffer is the start of the UDP frame for (i = 4; i <= pkt_size; i++) { tmp2 = (i != 4) ? tdata[i] : tdata[i] >> 16; Kiwi.Pause(); chksum_UDP = UDP.calc_UDP_checksum(chksum_UDP, tmp2); } tmp3 = (tdata[4] & (ulong)0xffff000000000000) | (ulong)0x001100; // Here is the new UDP length + proto type tmp2 = src_ip << 32 | dst_ip; // (optimization) src, dst IPs Kiwi.Pause(); chksum_UDP = UDP.calc_UDP_checksum(chksum_UDP, tmp3); // (optimization) 11U = 0x11 = UDP proto_type , UDP length Kiwi.Pause(); chksum_UDP = UDP.calc_UDP_checksum(chksum_UDP, tmp2); Kiwi.Pause(); // 1's complement of the result tmp2 = (ulong)((chksum_UDP ^ ~(ulong)0x00) & (ulong)0x00ffff); Kiwi.Pause(); // make it back to little endian tmp3 = (ulong)((tmp2 >> 8) | (ulong)(tmp2 & (ulong)0x00ff) << 8); // Set the new UDP checksum tdata[5] = tmp | tmp3; } } // # // ########################################################################################### Kiwi.Pause(); // ############################# // # Server Logic -- END // ############################# // Procedure calchksum_ICMPl for transmiting packet SendFrame(pkt_size); //End of frame, ready for next frame IPv4 = false; proto_UDP = false; proto_ICMP = false; chksum_UDP = 0x00; pkt_size = 0x00; } }
public Client(int _id) { id = _id; tcp = new TCP(id); udp = new UDP(id); }
public Client(byte clientID) { id = clientID; tcp = new TCP(id); udp = new UDP(id); }
public static async void SendToElastic(this sFlowDatagram datagram) { string request = ""; string datetime = DateTime.Now.ToString("o"); foreach (Sample sample in datagram.Samples) { if (sample == null) { continue; } Dictionary <string, object> doc = new Dictionary <string, object>(); doc.Add("@timestamp", datetime); doc.Add("sflow_source", datagram.AgentAddress.ToString()); doc.Add("sflow_sequence", datagram.SequenceNumber); if (sample.Type == SampleType.Flow) { FlowSample flowSample = (FlowSample)sample; doc.Add("sampling_rate", flowSample.SamplingRate); doc.Add("sampling_pool", flowSample.SamplingPool); doc.Add("dropped_packets", flowSample.DroppedPackets); doc.Add("frame_in_interface_value", flowSample.InputInterface.Value); doc.Add("frame_out_interface_value", flowSample.OutputInterface.Value); doc.Add("frame_out_interface_format", flowSample.OutputInterface.Format.ToString()); doc.Add("frame_out_interface_discard", flowSample.OutputInterface.DiscardReason.ToString()); foreach (FlowRecord record in flowSample.Records) { if (record.Type == FlowRecordType.RawPacketHeader) { RawPacketHeader rawPacketHeader = (RawPacketHeader)record; doc.Add("frame_length_octets", rawPacketHeader.FrameLength); if (rawPacketHeader.HeaderProtocol == HeaderProtocol.Ethernet) { EthernetFrame ethFrame = (EthernetFrame)rawPacketHeader.Header; doc.Add("mac_source", ethFrame.SourceMAC.ToString()); doc.Add("mac_destination", ethFrame.DestinationMAC.ToString()); doc.Add("packet_type", ethFrame.PacketType.ToString()); ProtocolType ProtocolType = 0; if (ethFrame.PacketType == PacketType.IPv4) { IPv4Packet packet = (IPv4Packet)ethFrame.Packet; doc.Add("ip_source", packet.SourceAddress.ToString()); doc.Add("ip_destination", packet.DestinationAddress.ToString()); doc.Add("ip_ttl", packet.TimeToLive); doc.Add("protocol_type", packet.ProtocolType.ToString()); ProtocolType = packet.ProtocolType; } if (ProtocolType == ProtocolType.TCP) { TCP TCP = (TCP)ethFrame.Packet.Payload; doc.Add("port_source", TCP.SourcePort); doc.Add("port_destination", TCP.DestinationPort); } else if (ProtocolType == ProtocolType.UDP) { UDP UDP = (UDP)ethFrame.Packet.Payload; doc.Add("port_source", UDP.SourcePort); doc.Add("port_destination", UDP.DestinationPort); } } } else if (record.Type == FlowRecordType.ExtSwitchData) { SwitchData switchData = (SwitchData)record; doc.Add("vlan_in", switchData.IncomingVLAN); doc.Add("vlan_out", switchData.OutgoingVLAN); } } } else if (sample.Type == SampleType.Counter) { CounterSample countSample = (CounterSample)sample; foreach (CounterRecord record in countSample.Records) { if (record.Type == CounterRecordType.GenericInterface) { Generic gi = (Generic)record; doc.Add("if_direction", gi.IfDirection.ToString()); doc.Add("if_in_broadcast_pkts", gi.IfInBroadcastPkts); doc.Add("if_index", gi.IfIndex); doc.Add("if_in_discards", gi.IfInDiscards); doc.Add("if_in_errors", gi.IfInErrors); doc.Add("if_in_multicast_pkts", gi.IfInMulticastPkts); doc.Add("if_in_octets", gi.IfInOctets); doc.Add("if_in_unicast_pkts", gi.IfInUcastPkts); doc.Add("if_in_unknown_protos", gi.IfInUnknownProtos); doc.Add("if_out_broadcast_pkts", gi.IfOutBroadcastPkts); doc.Add("if_out_discards", gi.IfOutDiscards); doc.Add("if_out_errors", gi.IfOutErrors); doc.Add("if_out_multicast_pkts", gi.IfOutMulticastPkts); doc.Add("if_out_octets", gi.IfOutOctets); doc.Add("if_out_unicast_ptks", gi.IfOutUcastPkts); doc.Add("if_promiscuous_mode", gi.IfPromiscuousMode); doc.Add("if_speed", gi.IfSpeed); doc.Add("if_type", gi.IfType); doc.Add("if_status_up_admin", gi.IfStatus.HasFlag(Generic.IfStatusFlags.IfAdminStatusUp)); doc.Add("if_status_up_operational", gi.IfStatus.HasFlag(Generic.IfStatusFlags.IfOperStatusUp)); } else if (record.Type == CounterRecordType.EthernetInterface) { Ethernet eth = (Ethernet)record; doc.Add("eth_alignment_errors", eth.AlignmentErrors); doc.Add("eth_carrier_sense_errors", eth.CarrierSenseErrors); doc.Add("eth_deferred_transmissions", eth.DeferredTransmissions); doc.Add("eth_excessive_collisions", eth.ExcessiveCollisions); doc.Add("eth_fcs_errors", eth.FCSErrors); doc.Add("eth_frame_too_longs", eth.FrameTooLongs); doc.Add("eth_mac_recieve_errors", eth.InternalMacReceiveErrors); doc.Add("eth_mac_transmit_errors", eth.InternalMacTransmitErrors); doc.Add("eth_late_collisions", eth.LateCollisions); doc.Add("eth_multiple_collision_frames", eth.MultipleCollisionFrames); doc.Add("eth_single_collision_frames", eth.SingleCollisionFrames); doc.Add("eth_sqe_test_errors", eth.SQETestErrors); doc.Add("eth_symbol_errors", eth.SymbolErrors); } else if (record.Type == CounterRecordType.VLAN) { VLAN vlan = (VLAN)record; doc.Add("vlan_multicast_pkts", vlan.MulticastPkts); doc.Add("vlan_octets", vlan.Octets); doc.Add("vlan_unicast_pkts", vlan.UCastPkts); doc.Add("vlan_id", vlan.VlanID); } else if (record.Type == CounterRecordType.ProcessorInformation) { ProcessorInfo pi = (ProcessorInfo)record; doc.Add("stats_cpu_percent_1m", pi.Cpu1mPercentage); doc.Add("stats_cpu_percent", pi.Cpu5mPercentage); doc.Add("stats_cpu_5s_percent", pi.Cpu5sPercentage); doc.Add("stats_memory_free", pi.FreeMemory); doc.Add("stats_memory_total", pi.TotalMemory); } } } request += "{\"create\":{\"_index\":\"" + PREFIX + sample.Type.ToString().ToLower() + "\"}}\n"; request += JsonConvert.SerializeObject(doc) + '\n'; } try { MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(request)); await HC.PostAsync(URI + "/_bulk", new StreamContent(ms) { Headers = { ContentType = MediaTypeHeaderValue.Parse("application/json") } }); ms.Dispose(); } catch (Exception e) { Console.WriteLine(e.Message); } }
public override bool Send(IPPayload payload) { DHCP dhcp = new DHCP(payload.GetPayload()); hType = dhcp.HardwareType; hLen = dhcp.HardwareAddressLength; xID = dhcp.TransactionID; cMac = dhcp.ClientHardwareAddress; cookie = dhcp.MagicCookie; DHCPopClientID clientID = null; byte msg = 0; byte[] reqList = null; uint leaseTime = 86400; for (int i = 0; i < dhcp.Options.Count; i++) { switch (dhcp.Options[i].Code) { case 0: //Error.WriteLine("Got NOP"); continue; case 1: Log_Info("Got SubnetMask?"); if (Utils.memcmp(NetMask, 0, ((DHCPopSubnet)dhcp.Options[i]).SubnetMask, 0, 4) == false) { throw new Exception("SubnetMask missmatch"); } break; case 3: Log_Info("Got Router?"); if (((DHCPopRouter)dhcp.Options[i]).RouterIPs.Count != 1) { throw new Exception("RouterIPs count missmatch"); } if (Utils.memcmp(Gateway, 0, ((DHCPopRouter)dhcp.Options[i]).RouterIPs[0], 0, 4) == false) { throw new Exception("RouterIPs missmatch"); } break; case 6: Log_Info("Got DNS?"); if ((((DHCPopDNS)dhcp.Options[i]).DNSServers.Count != 0 & DNS1 == null) || (((DHCPopDNS)dhcp.Options[i]).DNSServers.Count != 1 & DNS2 == null) || (((DHCPopDNS)dhcp.Options[i]).DNSServers.Count != 2 & DNS2 != null)) { throw new Exception("DNS count missmatch"); } if ((DNS1 != null && Utils.memcmp(DNS1, 0, ((DHCPopDNS)dhcp.Options[i]).DNSServers[0], 0, 4) == false) || (DNS2 != null && Utils.memcmp(DNS2, 0, ((DHCPopDNS)dhcp.Options[i]).DNSServers[1], 0, 4) == false)) { throw new Exception("DNS missmatch"); } break; case 12: Log_Info("Got HostName"); //TODO use name? break; case 50: Log_Info("Got Request IP"); if (Utils.memcmp(PS2IP, 0, ((DHCPopREQIP)dhcp.Options[i]).IPaddress, 0, 4) == false) { throw new Exception("ReqIP missmatch"); } break; case 51: Log_Info("Got Requested Lease Time"); leaseTime = ((DHCPopIPLT)(dhcp.Options[i])).IPLeaseTime; break; case 53: msg = ((DHCPopMSG)(dhcp.Options[i])).Message; Log_Info("Got MSG ID = " + msg); break; case 54: Log_Info("Got Server IP"); if (Utils.memcmp(DefaultDHCPConfig.DHCP_IP, 0, ((DHCPopSERVIP)dhcp.Options[i]).ServerIP, 0, 4) == false) { throw new Exception("ServIP missmatch"); } break; case 55: reqList = ((DHCPopREQLIST)(dhcp.Options[i])).RequestList; Log_Verb("Got Request List of length " + reqList.Length); for (int rID = 0; rID < reqList.Length; rID++) { Log_Verb("Requested : " + reqList[rID]); } break; case 56: Log_Verb("Got String Message of " + ((DHCPopMSGStr)dhcp.Options[i]).Message); break; case 57: maxMs = ((DHCPopMMSGS)(dhcp.Options[i])).MaxMessageSize; Log_Verb("Got Max Message Size of " + maxMs); break; case 60: Log_Verb("Got Class Id of " + ((DHCPopClassID)dhcp.Options[i]).ClassID); break; case 61: Log_Verb("Got Client ID"); clientID = (DHCPopClientID)dhcp.Options[i]; //Ignore break; case 255: Log_Verb("Got END"); break; default: Log_Error("Got Unknown Option " + dhcp.Options[i].Code); throw new Exception("Got Unknown Option " + dhcp.Options[i].Code); //break; } } DHCP retPay = new DHCP { OP = 2, HardwareType = hType, HardwareAddressLength = hLen, TransactionID = xID, YourIP = PS2IP,//IPaddress.GetAddressBytes(); ServerIP = DefaultDHCPConfig.DHCP_IP, ClientHardwareAddress = cMac, MagicCookie = cookie }; if (msg == 1 || msg == 3) //Fill out Requests { if (msg == 1) { retPay.Options.Add(new DHCPopMSG(2)); } if (msg == 3) { retPay.Options.Add(new DHCPopMSG(5)); } if (reqList != null) { for (int i = 0; i < reqList.Length; i++) { switch (reqList[i]) { case 1: Log_Verb("Sending Subnet"); //retPay.Options.Add(new DHCPopSubnet(NetMask.GetAddressBytes())); retPay.Options.Add(new DHCPopSubnet(NetMask)); break; case 3: Log_Verb("Sending Router"); if (Gateway != null) { retPay.Options.Add(new DHCPopRouter(new List <byte[]>() { Gateway })); } break; case 6: Log_Verb("Sending DNS"); if (DNS1 != null) { if (DNS2 != null) { retPay.Options.Add(new DHCPopDNS(new List <byte[]>() { DNS1, DNS2 })); } else { retPay.Options.Add(new DHCPopDNS(new List <byte[]>() { DNS1 })); } } break; case 15: Log_Verb("Sending Domain Name"); //retPay.Options.Add(new DHCPopDNSNAME(Dns.GetHostName())); retPay.Options.Add(new DHCPopDNSNAME("PCSX2-CLRDEV9")); break; case 28: Log_Verb("Sending Broadcast Addr"); retPay.Options.Add(new DHCPopBCIP(Broadcast)); break; case 50: Log_Verb("Sending PS2 IP Addr"); retPay.Options.Add(new DHCPopREQIP(PS2IP)); break; case 53: Log_Verb("Sending MSG (Already Added)"); break; case 54: Log_Verb("Sending Server Identifier (Already Added)"); break; case 77: //Isn't this surpossed to be sent by the client? Log_Error("Request for User-Class, Ignoring"); break; default: Log_Error("Got Unknown Req " + reqList[i]); throw new Exception("Got Unknown Req " + reqList[i]); } } retPay.Options.Add(new DHCPopIPLT(leaseTime)); } } if (msg == 7) { Log_Info("PS2 has Disconnected"); return(true); } retPay.Options.Add(new DHCPopSERVIP(DefaultDHCPConfig.DHCP_IP)); retPay.Options.Add(new DHCPopEND()); byte[] udpPayload = retPay.GetBytes((UInt16)(maxMs - (8 + 20))); UDP retudp = new UDP(udpPayload) { SourcePort = 67, DestinationPort = 68 }; recvBuff.Enqueue(retudp); return(true); }
public Client(int _internalId) { internalId = _internalId; tcp = new TCP(internalId); udp = new UDP(internalId); }
private void Start() { tcp = new TCP(); udp = new UDP(); }
public void UDP_Setup() { Assert.True(UDP.Setup()); }