using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using skyscraper5.Mpeg2;
using skyscraper5.Skyscraper.Net;
using skyscraper5.Skyscraper.Plugins;

namespace skyscraper5.Dvb.DataBroadcasting.IntDescriptors
{
	[SkyscraperPlugin]
	[TsDescriptor(0x0f,"INT")]
    internal class TargetIpSlashDescriptor : TsDescriptor
    {
        public TargetIpSlashDescriptor(byte[] buffer)
        {
            int length = buffer.Length / 5;
            Targets = new CidrSubnet[length];
            for (int i = 0; i < length; i++)
            {
                byte[] ipBuffer = new byte[4];
                Array.Copy(buffer, i * 5, ipBuffer, 0, 4);
                IPAddress address = new IPAddress(ipBuffer);
                byte netmask = buffer[(i * 5) + 4];
                Targets[i] = new CidrSubnet(address, netmask);
            }
        }

        public CidrSubnet[] Targets { get; private set; }
    }
}
