public static PcapPacketInfo Parse(ICaptureDevice dev, RawCapture packet, PcapPacketParserOption option) { var analyze_param = new PacketAnalyzeParam(dev, packet); /* パケット解析 */ Analyze(analyze_param); return(CreatePacketInfo(packet, analyze_param, option)); }
public static PacketObject Convert(ICaptureDevice dev, RawCapture packet, PcapPacketParserOption option) { if (packet == null) { return(null); } var info = Parse(dev, packet, option); return(new PacketObject( "WinPcap", PacketFacility.Device, "", PacketPriority.Standard, PacketAttribute.Data, info.DateTime, "", info.Direction, info.Source, info.Destination, 0x00, null, info.Data)); }
private static PcapPacketInfo CreatePacketInfo(RawCapture packet, PacketAnalyzeParam param, PcapPacketParserOption option) { var packet_info = new PcapPacketInfo(); packet_info.DateTime = packet.Timeval.Date; packet_info.Direction = (param.IsSend) ? (PacketDirection.Send) : (PacketDirection.Recv); packet_info.Information = param.Protocol; switch (option.SourceInfo) { case SourceInfoType.MacAddress: if (param.SourceHwAddress != null) { packet_info.Source = param.SourceHwAddress.ToString(); } break; case SourceInfoType.IpAddressAndPortNo: if (param.SourceAddress != null) { packet_info.Source = string.Format("{0}:{1}", param.SourceAddress.ToString(), param.SourcePort); } break; case SourceInfoType.IpAddress: if (param.SourceAddress != null) { packet_info.Source = param.SourceAddress.ToString(); } break; case SourceInfoType.PortNo: if (param.SourceAddress != null) { packet_info.Source = string.Format(":{0}", param.SourcePort.ToString()); } break; } switch (option.DestinationInfo) { case DestinationInfoType.MacAddress: if (param.DestinationHwAddress != null) { packet_info.Destination = param.DestinationHwAddress.ToString(); } break; case DestinationInfoType.IpAddressAndPortNo: if (param.DestinationAddress != null) { packet_info.Destination = string.Format("{0}:{1}", param.DestinationAddress.ToString(), param.DestinationPort); } break; case DestinationInfoType.IpAddress: if (param.DestinationAddress != null) { packet_info.Destination = param.DestinationAddress.ToString(); } break; case DestinationInfoType.PortNo: if (param.DestinationAddress != null) { packet_info.Destination = string.Format(":{0}", param.DestinationPort.ToString()); } break; } switch (option.DataContents) { case DataContentsType.Payload: packet_info.Data = param.PayloadFrame; break; case DataContentsType.Raw: default: packet_info.Data = param.DataLinkFrame; break; } if (packet_info.Data == null) { packet_info.Data = new byte[] { }; } return(packet_info); }