Ejemplo n.º 1
0
        public virtual bool isMessageOfType(UDP udp, IPv4 ipv4, int messageType)
        {
            if (opcode != DHCP_BOOT_REQUEST)
            {
                return(false);
            }
            if (udp.sourcePort != UDP_PORT_DHCP_CLIENT || udp.destinationPort != UDP_PORT_DHCP_SERVER)
            {
                return(false);
            }
            if (!Array.Equals(ipv4.sourceIPAddress, nullIPAddress))
            {
                return(false);
            }
            if (!Array.Equals(ipv4.destinationIPAddress, broadcastIPAddress))
            {
                return(false);
            }
            DHCPOption option = getOptionByTag(DHCP_OPTION_MESSAGE_TYPE);

            if (option == null || option.Length != 1)
            {
                return(false);
            }
            int optionMessageType = option.DataAsInt;

            if (optionMessageType != messageType)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
 public IPv4(IPv4 ipv4)
 {
     version = ipv4.version;
     internetHeaderLength            = ipv4.internetHeaderLength;
     differentiatedServicesCodePoint = ipv4.differentiatedServicesCodePoint;
     explicitCongestionNotification  = ipv4.explicitCongestionNotification;
     totalLength          = ipv4.totalLength;
     identification       = ipv4.identification;
     flags                = ipv4.flags;
     fragmentOffset       = ipv4.fragmentOffset;
     timeToLive           = ipv4.timeToLive;
     protocol             = ipv4.protocol;
     headerChecksum       = ipv4.headerChecksum;
     sourceIPAddress      = ipv4.sourceIPAddress;
     destinationIPAddress = ipv4.destinationIPAddress;
     options              = ipv4.options;
 }
Ejemplo n.º 3
0
        public virtual bool isRequest(UDP udp, IPv4 ipv4, sbyte[] requestedIpAddress)
        {
            if (!isMessageOfType(udp, ipv4, DHCP_OPTION_MESSAGE_TYPE_DHCPREQUEST))
            {
                return(false);
            }

            // Verify that the requested IP address is matching
            // the one specified in the options.
            DHCPOption requestedIpAddressOption = getOptionByTag(DHCP_OPTION_REQUESTED_IP_ADDRESS);

            if (requestedIpAddressOption == null || requestedIpAddressOption.Length != 4)
            {
                return(false);
            }
            if (!Array.Equals(requestedIpAddress, requestedIpAddressOption.data))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void computeChecksum(IPv4 ipv4) throws java.io.EOFException
        public virtual void computeChecksum(IPv4 ipv4)
        {
            // Computes the checksum with 0 at the checksum FieldInfo
            checksum = 0;

            // The checksum also covers a 12 bytes pseudo header
            NetPacket checksumPacket = new NetPacket(12 + sizeOf());

            // Pseudo header:
            // - source IP address (4 bytes)
            // - destination IP address (4 bytes)
            // - 0 (1 byte)
            // - protocol (1 byte)
            // - TCP Length (2 bytes)
            checksumPacket.writeBytes(ipv4.sourceIPAddress);
            checksumPacket.writeBytes(ipv4.destinationIPAddress);
            checksumPacket.write8(0);
            checksumPacket.write8(ipv4.protocol);
            checksumPacket.write16(sizeOf());
            write(checksumPacket);
            checksum = computeInternetChecksum(checksumPacket.Buffer, 0, checksumPacket.Offset);
        }
Ejemplo n.º 5
0
 public virtual bool isDiscovery(UDP udp, IPv4 ipv4)
 {
     return(isMessageOfType(udp, ipv4, DHCP_OPTION_MESSAGE_TYPE_DHCPDISCOVER));
 }