Example #1
0
            public IPPacket(byte[] buffer)
            {
                try
                {
                    byte versionAndHeaderLength = buffer[0];
                    Version = (versionAndHeaderLength >> 4) == 4 ? ProtocolFamily.InterNetwork : ProtocolFamily.InterNetworkV6;
                    HeaderLength = (byte)((versionAndHeaderLength & 15) * 4); // 0b1111 = 15

                    Protocol = (ProtocolType)buffer[9];

                    SourceIPAddress = new IPAddress(BitConverter.ToUInt32(buffer, 12));
                    DestinationIPAddress = new IPAddress(BitConverter.ToUInt32(buffer, 16));

                    Data = buffer.Skip(HeaderLength).ToArray();

                    IsValid = true;
                }
                catch (Exception ex)
                {
                    Version = ProtocolFamily.Unknown;
                    HeaderLength = 0;

                    Protocol = ProtocolType.Unknown;

                    SourceIPAddress = null;
                    DestinationIPAddress = null;

                    Data = null;

                    IsValid = false;
                    Log.Ex(ex, "IP 패킷 파싱 에러");
                }
            }
Example #2
0
            public IPPacket(byte[] buffer)
            {
                try
                {
                    byte versionAndHeaderLength = buffer[0];
                    Version      = (versionAndHeaderLength >> 4) == 4 ? ProtocolFamily.InterNetwork : ProtocolFamily.InterNetworkV6;
                    HeaderLength = (byte)((versionAndHeaderLength & 15) * 4); // 0b1111 = 15

                    Protocol = (ProtocolType)buffer[9];

                    SourceIPAddress      = new IPAddress(BitConverter.ToUInt32(buffer, 12));
                    DestinationIPAddress = new IPAddress(BitConverter.ToUInt32(buffer, 16));

                    Data = buffer.Skip(HeaderLength).ToArray();

                    IsValid = true;
                }
                catch (Exception ex)
                {
                    Version      = ProtocolFamily.Unknown;
                    HeaderLength = 0;

                    Protocol = ProtocolType.Unknown;

                    SourceIPAddress      = null;
                    DestinationIPAddress = null;

                    Data = null;

                    IsValid = false;
                    Log.Ex(ex, "IP 패킷 파싱 에러");
                }
            }
Example #3
0
 public ConnectionPolicy(QQClient client, string id, ProtocolFamily supportedFamily, ProtocolFamily relocateFamily)
 {
     this.ID              = id;
     this.client          = client;
     this.SupportedFamily = supportedFamily;
     this.RelocateFamily  = relocateFamily;
     helper = new PacketHelper();
 }
Example #4
0
 public ConnectionPolicy(QQClient client, string id, ProtocolFamily supportedFamily, ProtocolFamily relocateFamily)
 {
     this.ID = id;
     this.client = client;
     this.SupportedFamily = supportedFamily;
     this.RelocateFamily = relocateFamily;
     helper = new PacketHelper();
 }
Example #5
0
 /// <summary>
 /// Performs shallow copy.
 /// </summary>
 /// <param name="h"></param>
 public void Clone(Header h)
 {
     pDUType         = h.pDUType;
     protocolVersion = h.protocolVersion;
     exerciseID      = h.exerciseID;
     protocolFamily  = h.protocolFamily;
     timeStamp       = h.timeStamp;
     length          = h.length;
 }
Example #6
0
        /// <summary>
        /// 把ByteBuffer中的内容解析成一个InPacket子类,从buf的当前位置开始解析,直到limit为止
        /// * 不论解析成功或者失败,要把buf的position置于length后
        ///     <remark>abu 2008-03-07 </remark>
        /// </summary>
        /// <returns></returns>
        public InPacket ParseIn(ProtocolFamily supportedFamily, ByteBuffer buf, QQUser user)
        {
            IParser parser = FindParser(supportedFamily, buf);

            if (parser == null)
            {
                return(null);
            }
            return(ParseIn(parser, buf, parser.GetLength(buf), user));
        }
Example #7
0
        /// <summary>
        /// </summary>
        /// <param name="supportedFamily">The supported family.</param>
        /// <param name="buf">The buf.</param>
        /// <param name="user">The user.</param>
        /// <returns></returns>
        public OutPacket ParseOut(ProtocolFamily supportedFamily, ByteBuffer buf, QQClient client)
        {
            IParser parser = FindParser(supportedFamily, buf);

            if (parser == null)
            {
                return(null);
            }
            return(ParseOut(parser, buf, parser.GetLength(buf), client));
        }
Example #8
0
        protected IPSocket(Context context, AddressFamily addressFamily, ProtocolFamily protocolFamily)
            : base(context, addressFamily)
        {
            int err;

            fd = SocketFunctions.manos_socket_create((int)addressFamily, (int)protocolFamily, out err);
            if (fd < 0)
            {
                throw Errors.SocketFailure("Could not create socket", err);
            }
        }
Example #9
0
            public IPPacket(byte[] buffer)
            {
                try
                {
                    byte versionAndHeaderLength = buffer[0];
                    Version = (versionAndHeaderLength >> 4) == 4 ? ProtocolFamily.InterNetwork : ProtocolFamily.InterNetworkV6;
                    HeaderLength = (byte)((versionAndHeaderLength & 15) * 4); // 0b1111 = 15

                    byte dscpAndEcn = buffer[1];
                    DifferentiatedServices = (byte)(dscpAndEcn >> 2);
                    Congestion = (byte)(dscpAndEcn & 3); // 0b11 = 3

                    TotalLength = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(buffer, 2));
                    Identification = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(buffer, 4));

                    ushort flagsAndOffset = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(buffer, 6));
                    Flags = (byte)(flagsAndOffset >> 13);
                    FragmentOffset = (ushort)(flagsAndOffset & 8191); // 0b1111111111111 = 8191

                    TTL = buffer[8];
                    Protocol = (ProtocolType)buffer[9];
                    Checksum = IPAddress.NetworkToHostOrder(BitConverter.ToInt16(buffer, 10));

                    SourceIPAddress = new IPAddress(BitConverter.ToUInt32(buffer, 12));
                    DestinationIPAddress = new IPAddress(BitConverter.ToUInt32(buffer, 16));

                    Data = new byte[buffer.Length - HeaderLength];
                    Buffer.BlockCopy(buffer, HeaderLength, Data, 0, Data.Length);

                    IsValid = true;
                }
                catch
                {
                    Version = ProtocolFamily.Unknown;
                    HeaderLength = 0;
                    DifferentiatedServices = 0;
                    Congestion = 0;
                    TotalLength = 0;
                    Identification = 0;
                    Flags = 0;
                    FragmentOffset = 0;
                    TTL = 0;
                    Protocol = ProtocolType.Unknown;
                    Checksum = 0;

                    SourceIPAddress = null;
                    DestinationIPAddress = null;

                    Data = null;

                    IsValid = false;
                }
            }
Example #10
0
            public IPPacket(byte[] buffer)
            {
                try
                {
                    byte versionAndHeaderLength = buffer[0];
                    Version      = (versionAndHeaderLength >> 4) == 4 ? ProtocolFamily.InterNetwork : ProtocolFamily.InterNetworkV6;
                    HeaderLength = (byte)((versionAndHeaderLength & 15) * 4); // 0b1111 = 15

                    byte dscpAndEcn = buffer[1];
                    DifferentiatedServices = (byte)(dscpAndEcn >> 2);
                    Congestion             = (byte)(dscpAndEcn & 3); // 0b11 = 3

                    TotalLength    = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(buffer, 2));
                    Identification = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(buffer, 4));

                    ushort flagsAndOffset = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(buffer, 6));
                    Flags          = (byte)(flagsAndOffset >> 13);
                    FragmentOffset = (ushort)(flagsAndOffset & 8191); // 0b1111111111111 = 8191

                    TTL      = buffer[8];
                    Protocol = (ProtocolType)buffer[9];
                    Checksum = IPAddress.NetworkToHostOrder(BitConverter.ToInt16(buffer, 10));

                    SourceIPAddress      = new IPAddress(BitConverter.ToUInt32(buffer, 12));
                    DestinationIPAddress = new IPAddress(BitConverter.ToUInt32(buffer, 16));

                    Data = new byte[buffer.Length - HeaderLength];
                    Buffer.BlockCopy(buffer, HeaderLength, Data, 0, Data.Length);

                    IsValid = true;
                }
                catch
                {
                    Version                = ProtocolFamily.Unknown;
                    HeaderLength           = 0;
                    DifferentiatedServices = 0;
                    Congestion             = 0;
                    TotalLength            = 0;
                    Identification         = 0;
                    Flags          = 0;
                    FragmentOffset = 0;
                    TTL            = 0;
                    Protocol       = ProtocolType.Unknown;
                    Checksum       = 0;

                    SourceIPAddress      = null;
                    DestinationIPAddress = null;

                    Data = null;

                    IsValid = false;
                }
            }
Example #11
0
        /// <summary>
        /// 查找一个能解析buf中内容的parser
        /// </summary>
        /// <param name="supportedFamily">The supported family.</param>
        /// <param name="buf">The buf.</param>
        /// <returns></returns>
        private IParser FindParser(ProtocolFamily supportedFamily, ByteBuffer buf)
        {
            IParser parser = parsers[supportedFamily];

            if (parser != null)
            {
                if (parser.Accept(buf))
                {
                    return(parser);
                }
            }
            return(null);
        }
Example #12
0
        protected IPSocket(Context context, AddressFamily addressFamily, ProtocolFamily protocolFamily)
            : base(context, addressFamily)
        {
            var family = addressFamily == AddressFamily.InterNetwork
                                ? System.Net.Sockets.AddressFamily.InterNetwork
                                : System.Net.Sockets.AddressFamily.InterNetworkV6;

            var type = protocolFamily == ProtocolFamily.Tcp
                                ? System.Net.Sockets.SocketType.Stream
                                : System.Net.Sockets.SocketType.Dgram;

            var protocol = protocolFamily == ProtocolFamily.Tcp
                                ? System.Net.Sockets.ProtocolType.Tcp
                                : System.Net.Sockets.ProtocolType.Udp;

            this.socket = new System.Net.Sockets.Socket(family, type, protocol);
        }
Example #13
0
        /// <summary>
        /// Decode network data.
        /// </summary>
        /// <param name="br"></param>
        public override void Decode(BinaryReader br)
        {
            isDirty         = true;
            protocolVersion = ( ProtocolVersion )br.ReadByte();
            exerciseID      = br.ReadByte();
            pDUType         = ( PDUType )br.ReadByte();
            protocolFamily  = ( ProtocolFamily )br.ReadByte();
            timeStamp       = new TimeStamp(br);
            length          = br.ReadUInt16();

            #if DIS_VERSION_7
            ownershipStatus = br.ReadByte();
            pduStatus       = br.ReadByte();
            #else
            br.BaseStream.Seek(2, SeekOrigin.Current);   // Skip padding
            #endif
        }
Example #14
0
        /// <summary> 把position设置到下一个包的起始位置处。一般当某段数据没有parser
        /// * 可以时,调用此方法跳过这段数据
        /// </summary>
        /// <param name="supportedFamily">The supported family.</param>
        /// <param name="buf">The buf.</param>
        /// <returns>true表示重定位成功,false表示失败或者推迟重定位</returns>
        public bool Relocate(ProtocolFamily supportedFamily, ByteBuffer buf)
        {
            int offset = buf.Position;

            if (parsers[supportedFamily] != null)
            {
                int relocated = parsers[supportedFamily].Relocate(buf);
                if (relocated > offset)
                {
                    buf.Position = relocated;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            return(false);
        }
Example #15
0
 /// <summary>
 /// Deletes all ARP table entries for the specified interface on the local computer.
 /// </summary>
 /// <param name="family">The address family to delete.</param>
 /// <param name="interfaceIndex">The index of the interface for which to delete all ARP entries.</param>
 public static bool FlushArpTable(ProtocolFamily family, uint interfaceIndex)
 {
     return(Win32.FlushIpNetTable2((ushort)family, interfaceIndex) == 0);
 }
Example #16
0
        /// <summary>
        /// Opens a datagram channel.
        ///
        /// <para> The {@code family} parameter is used to specify the {@link
        /// ProtocolFamily}. If the datagram channel is to be used for IP multicasting
        /// then this should correspond to the address type of the multicast groups
        /// that this channel will join.
        ///
        /// </para>
        /// <para> The new channel is created by invoking the {@link
        /// java.nio.channels.spi.SelectorProvider#openDatagramChannel(ProtocolFamily)
        /// openDatagramChannel} method of the system-wide default {@link
        /// java.nio.channels.spi.SelectorProvider} object.  The channel will not be
        /// connected.
        ///
        /// </para>
        /// </summary>
        /// <param name="family">
        ///          The protocol family
        /// </param>
        /// <returns>  A new datagram channel
        /// </returns>
        /// <exception cref="UnsupportedOperationException">
        ///          If the specified protocol family is not supported. For example,
        ///          suppose the parameter is specified as {@link
        ///          java.net.StandardProtocolFamily#INET6 StandardProtocolFamily.INET6}
        ///          but IPv6 is not enabled on the platform. </exception>
        /// <exception cref="IOException">
        ///          If an I/O error occurs
        ///
        /// @since   1.7 </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static DatagramChannel open(java.net.ProtocolFamily family) throws java.io.IOException
        public static DatagramChannel Open(ProtocolFamily family)
        {
            return(SelectorProvider.Provider().OpenDatagramChannel(family));
        }
Example #17
0
 public DatagramChannel openDatagramChannel(ProtocolFamily arg0)
 {
     return Instance.CallMethod<DatagramChannel>("openDatagramChannel", "(Ljava/net/ProtocolFamily;)Ljava/nio/channels/DatagramChannel;", arg0);
 }
Example #18
0
        /// <summary>
        /// Opens a datagram channel.
        /// </summary>
        /// <param name="family">
        ///          The protocol family
        /// </param>
        /// <returns>  A new datagram channel
        /// </returns>
        /// <exception cref="UnsupportedOperationException">
        ///          If the specified protocol family is not supported </exception>
        /// <exception cref="IOException">
        ///          If an I/O error occurs
        ///
        /// @since 1.7 </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public abstract DatagramChannel openDatagramChannel(java.net.ProtocolFamily family) throws java.io.IOException;
        public abstract DatagramChannel OpenDatagramChannel(ProtocolFamily family);
Example #19
0
        //[ImplementsFunction("stream_socket_pair", FunctionImplOptions.NotSupported)]
		public static PhpArray CreatePair(ProtocolFamily protocolFamily, SocketType type, ProtocolType protocol)
		{
			PhpException.FunctionNotSupported();
			return null;
		}
Example #20
0
 /// <summary>
 /// </summary>
 /// <param name="supportedFamily">The supported family.</param>
 /// <param name="buf">The buf.</param>
 /// <param name="user">The user.</param>
 /// <returns></returns>
 public OutPacket ParseOut(ProtocolFamily supportedFamily, ByteBuffer buf, QQClient client)
 {
     IParser parser = FindParser(supportedFamily, buf);
     if (parser == null)
     {
         return null;
     }
     return ParseOut(parser, buf, parser.GetLength(buf), client);
 }
Example #21
0
 //[ImplementsFunction("stream_socket_pair", FunctionImplOptions.NotSupported)]
 public static PhpArray CreatePair(ProtocolFamily protocolFamily, SocketType type, ProtocolType protocol)
 {
     PhpException.FunctionNotSupported();
     return(null);
 }
Example #22
0
 /// <summary> 把position设置到下一个包的起始位置处。一般当某段数据没有parser
 /// * 可以时,调用此方法跳过这段数据
 /// </summary>
 /// <param name="supportedFamily">The supported family.</param>
 /// <param name="buf">The buf.</param>
 /// <returns>true表示重定位成功,false表示失败或者推迟重定位</returns>
 public bool Relocate(ProtocolFamily supportedFamily, ByteBuffer buf)
 {
     int offset = buf.Position;
     if (parsers[supportedFamily] != null)
     {
         int relocated = parsers[supportedFamily].Relocate(buf);
         if (relocated > offset)
         {
             buf.Position = relocated;
             return true;
         }
         else
             return false;
     }
     return false;
 }
Example #23
0
 /// <summary>
 /// 查找一个能解析buf中内容的parser
 /// </summary>
 /// <param name="supportedFamily">The supported family.</param>
 /// <param name="buf">The buf.</param>
 /// <returns></returns>
 private IParser FindParser(ProtocolFamily supportedFamily, ByteBuffer buf)
 {
     IParser parser = parsers[supportedFamily];
     if (parser != null)
     {
         if (parser.Accept(buf))
         {
             return parser;
         }
     }
     return null;
 }
Example #24
0
 internal static extern IntPtr gethostbyaddr(
     [In] ref int addr,
     [In] int len,
     [In] ProtocolFamily type
     );
Example #25
0
 /// <summary>
 /// Flushes the IP path table on the local computer.
 /// </summary>
 /// <param name="family">The address family to flush.</param>
 public static bool FlushRouteTable(ProtocolFamily family)
 {
     return(Win32.FlushIpPathTable((ushort)family) == 0);
 }