""" Base protocol dissector interface and common structures """ from abc import ABC, abstractmethod from dataclasses import dataclass from enum import IntEnum from typing import Dict, List, Optional, Any try: from scapy.all import Packet except ImportError: print("Error: scapy library required. Install with: pip install scapy") import sys sys.exit(1) class ProtocolType(IntEnum): """Protocol type identifiers""" UNKNOWN = 0 CHAPTER10 = 1 PTP = 2 IENA = 3 @dataclass class DissectionResult: """Container for dissection results""" protocol: ProtocolType fields: Dict[str, Any] payload: Optional[bytes] = None errors: List[str] = None def __post_init__(self): if self.errors is None: self.errors = [] class ProtocolDissector(ABC): """Abstract base class for protocol dissectors""" @abstractmethod def can_dissect(self, packet: Packet) -> bool: """Check if this dissector can handle the given packet""" pass @abstractmethod def dissect(self, packet: Packet) -> Optional[DissectionResult]: """Dissect the packet and return structured data""" pass def get_protocol_type(self) -> ProtocolType: """Get the protocol type this dissector handles""" return ProtocolType.UNKNOWN