예제 #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
파일: Route.cs 프로젝트: muqiuq/BeASwitch
 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
파일: Subnet.cs 프로젝트: muqiuq/BeASwitch
 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
파일: Subnet.cs 프로젝트: muqiuq/BeASwitch
 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
파일: Subnet.cs 프로젝트: muqiuq/BeASwitch
 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
파일: Subnet.cs 프로젝트: muqiuq/BeASwitch
        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
파일: Subnet.cs 프로젝트: muqiuq/BeASwitch
 public Subnet(string ipAddress, int mask)
 {
     IpAddress = new IPv4Address(ipAddress);
     Mask      = mask;
 }
예제 #9
0
파일: Subnet.cs 프로젝트: muqiuq/BeASwitch
 public Subnet(IPv4Address ipAddress, int mask)
 {
     IpAddress = ipAddress;
     Mask      = mask;
 }