public static SessionPacket GetSessionPacket(byte[] buffer, int offset) { SessionPacketTypeName type = (SessionPacketTypeName)ByteReader.ReadByte(buffer, offset); switch (type) { case SessionPacketTypeName.SessionMessage: return(new SessionMessagePacket(buffer, offset)); case SessionPacketTypeName.SessionRequest: return(new SessionRequestPacket(buffer, offset)); case SessionPacketTypeName.PositiveSessionResponse: return(new PositiveSessionResponsePacket(buffer, offset)); case SessionPacketTypeName.NegativeSessionResponse: return(new NegativeSessionResponsePacket(buffer, offset)); case SessionPacketTypeName.RetargetSessionResponse: return(new SessionRetargetResponsePacket(buffer, offset)); case SessionPacketTypeName.SessionKeepAlive: return(new SessionKeepAlivePacket(buffer, offset)); default: throw new InvalidDataException("Invalid NetBIOS session packet type: 0x" + ((byte)type).ToString("X2")); } }
public static SessionPacket GetSessionPacket(byte[] buffer) { SessionPacketTypeName type = (SessionPacketTypeName)ByteReader.ReadByte(buffer, 0); switch (type) { case SessionPacketTypeName.SessionMessage: return(new SessionMessagePacket(buffer)); case SessionPacketTypeName.SessionRequest: return(new SessionRequestPacket(buffer)); case SessionPacketTypeName.PositiveSessionResponse: return(new PositiveSessionResponsePacket(buffer)); case SessionPacketTypeName.NegativeSessionResponse: return(new NegativeSessionResponsePacket(buffer)); case SessionPacketTypeName.RetargetSessionResponse: return(new SessionRetargetResponsePacket(buffer)); case SessionPacketTypeName.SessionKeepAlive: return(new SessionKeepAlivePacket(buffer)); default: throw new InvalidRequestException("Invalid NetBIOS Session Packet"); } }
public SessionPacket(byte[] buffer, int offset) { Type = (SessionPacketTypeName)ByteReader.ReadByte(buffer, offset + 0); Flags = ByteReader.ReadByte(buffer, offset + 1); TrailerLength = (Flags & 0x01) << 16 | BigEndianConverter.ToUInt16(buffer, offset + 2); Trailer = ByteReader.ReadBytes(buffer, offset + 4, TrailerLength); }
public SessionPacket(byte[] buffer) { Type = (SessionPacketTypeName)ByteReader.ReadByte(buffer, 0); Flags = ByteReader.ReadByte(buffer, 1); Length = (Flags & 0x01) << 16 | BigEndianConverter.ToUInt16(buffer, 2); this.Trailer = ByteReader.ReadBytes(buffer, 4, Length); }
public static SessionPacket GetSessionPacket(byte[] buffer, int offset) { SessionPacketTypeName type = (SessionPacketTypeName)ByteReader.ReadByte(buffer, offset); return(type switch { SessionPacketTypeName.SessionMessage => new SessionMessagePacket(buffer, offset), SessionPacketTypeName.SessionRequest => new SessionRequestPacket(buffer, offset), SessionPacketTypeName.PositiveSessionResponse => new PositiveSessionResponsePacket(buffer, offset), SessionPacketTypeName.NegativeSessionResponse => new NegativeSessionResponsePacket(buffer, offset), SessionPacketTypeName.RetargetSessionResponse => new SessionRetargetResponsePacket(buffer, offset), SessionPacketTypeName.SessionKeepAlive => new SessionKeepAlivePacket(buffer, offset), _ => throw new InvalidDataException("Invalid NetBIOS session packet type: 0x" + ((byte)type).ToString("X2")) });