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 패킷 파싱 에러"); } }
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(); }
/// <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; }
/// <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)); }
/// <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)); }
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); } }
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; } }
/// <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); }
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); }
/// <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 }
/// <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); }
/// <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); }
/// <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)); }
public DatagramChannel openDatagramChannel(ProtocolFamily arg0) { return Instance.CallMethod<DatagramChannel>("openDatagramChannel", "(Ljava/net/ProtocolFamily;)Ljava/nio/channels/DatagramChannel;", arg0); }
/// <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);
//[ImplementsFunction("stream_socket_pair", FunctionImplOptions.NotSupported)] public static PhpArray CreatePair(ProtocolFamily protocolFamily, SocketType type, ProtocolType protocol) { PhpException.FunctionNotSupported(); return null; }
/// <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); }
//[ImplementsFunction("stream_socket_pair", FunctionImplOptions.NotSupported)] public static PhpArray CreatePair(ProtocolFamily protocolFamily, SocketType type, ProtocolType protocol) { PhpException.FunctionNotSupported(); return(null); }
/// <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; }
/// <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; }
internal static extern IntPtr gethostbyaddr( [In] ref int addr, [In] int len, [In] ProtocolFamily type );
/// <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); }