Пример #1
0
 public IPv4Packet(string sourceMAC, string destMAC, IPv4Address sourceIP, IPv4Address destIP, string content = "")
 {
     SourceMAC = sourceMAC;
     DestMAC   = destMAC;
     SourceIP  = sourceIP;
     DestIP    = destIP;
     Content   = content;
 }
Пример #2
0
 public Route(Subnet subnet, RouterPort routerPort, IPv4Address gateway = null, IPv4Address src = null)
 {
     this.gateway    = gateway;
     this.Subnet     = subnet;
     this.RouterPort = routerPort;
     this.src        = src;
     if (src != null && gateway != null)
     {
         throw new ArgumentException("Can't have source and gateway simultaneously");
     }
 }
Пример #3
0
 public SubnetMatchResult Match(IPv4Address otherIpv4Address)
 {
     byte[] srcIp     = otherIpv4Address.GetBytes();
     byte[] netaddr   = GetNetAddress().GetBytes();
     byte[] maskBytes = MaskToBytes(Mask);
     byte[] result    = new byte[4];
     for (int a = 0; a < srcIp.Length; a++)
     {
         result[a] = (byte)(srcIp[a] & maskBytes[a]);
     }
     return(new SubnetMatchResult(Helper.Equals(netaddr, result), this, otherIpv4Address));
 }
Пример #4
0
 public IPv4Address GetBroadcast()
 {
     if (broadcastAddr == null)
     {
         byte[] broadcastAddrBytes = GetNetAddress().GetBytes();
         byte[] invertedMask       = InvertedMask(Mask);
         for (int a = 0; a < 4; a++)
         {
             broadcastAddrBytes[a] = (byte)(broadcastAddrBytes[a] | invertedMask[a]);
         }
         broadcastAddr = new IPv4Address(new System.Net.IPAddress(broadcastAddrBytes));
     }
     return(broadcastAddr);
 }
Пример #5
0
 public IPv4Address GetNetAddress()
 {
     if (netAddress == null)
     {
         byte[] addr      = IpAddress.GetBytes();
         byte[] maskBytes = MaskToBytes(Mask);
         byte[] result    = new byte[4];
         for (int a = 0; a < addr.Length; a++)
         {
             result[a] = (byte)(addr[a] & maskBytes[a]);
         }
         netAddress = new IPv4Address(new System.Net.IPAddress(result));
     }
     return(netAddress);
 }
Пример #6
0
        public Subnet GenerateNewWithLowestBitWithinMaskIncreased()
        {
            byte[] maskBytes = new byte[4];
            int    maskRest  = Mask;
            int    count     = 0;

            while (maskRest > 0)
            {
                if (maskRest == 1)
                {
                    maskBytes[count / 8] += (byte)(0x80 >> ((byte)count % 8));
                }
                maskRest--;
                count++;
            }
            byte[] addr   = IpAddress.GetBytes();
            byte[] result = new byte[4];
            for (int a = 0; a < addr.Length; a++)
            {
                result[a] = (byte)(addr[a] | maskBytes[a]);
            }
            netAddress = new IPv4Address(new System.Net.IPAddress(result));
            return(new Subnet(netAddress, Mask));
        }
Пример #7
0
 public SubnetMatchResult(bool isMatch, Subnet subnet, IPv4Address ipAddress)
 {
     IsMatch   = isMatch;
     Subnet    = subnet;
     IpAddress = ipAddress;
 }
Пример #8
0
 public Subnet(string ipAddress, int mask)
 {
     IpAddress = new IPv4Address(ipAddress);
     Mask      = mask;
 }
Пример #9
0
 public Subnet(IPv4Address ipAddress, int mask)
 {
     IpAddress = ipAddress;
     Mask      = mask;
 }