-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Types for working with Linux packet sockets -- -- network-packet-linux makes it possible to use the network -- package with Linux packet sockets. Packet sockets are described in -- packet (7). -- --
-- main :: IO () -- main = do -- -- Open a raw packet socket, receiving all protocols -- sock <- socket AF_PACKET Raw (toProtocolNumber ETH_P_ALL) -- -- -- Get the index of the eth0 interface, or fall back to "any interface" (0) if "eth0" doesn't exist -- ifIndex <- fromMaybe 0 <$> ifNameToIndex "eth0" -- -- -- Bind the socket to the interface index found above -- bind sock (mkBindSockAddrLl AF_PACKET ETH_P_ALL ifIndex) -- -- -- Print the length of the next 10 packets received on the interface: -- replicateM_ 10 $ do -- msg <- recv sock 4096 -- putStrLn $ "Received " ++ (show . BS.length) msg ++ " bytes" -- -- -- Close the socket -- close sock ---- -- See packet (7) for more information about packet sockets. module Network.Socket.Linux -- | A type representing the sockaddr_ll struct defined in -- <linux/if_ether.h>. -- -- This can be used by functions in Network.Socket.Address in -- order to interact with packet sockets - see packet (7) for -- details. Note that passing this type to connect or -- accept is an error. data SockAddrLl -- | Get the type of a received packet sllPktType :: SockAddrLl -> PacketType -- | Get the PhysicalAddress corresponding to the the -- sll_halen and sll_addr fields of a -- sockaddr_ll physicalAddress :: SockAddrLl -> PhysicalAddress -- | Create a SockAddrLl for binding a packet socket to an interface. mkBindSockAddrLl :: Family -> ProtocolId -> IfIndex -> SockAddrLl -- | Create a SockAddrLl for sending data to a specific address. mkSendSockAddrLl :: Family -> ProtocolId -> IfIndex -> PhysicalAddress -> SockAddrLl -- | The index of a network interface type IfIndex = Int -- | A physical address consisting of up to eight bytes. -- -- This type encapsulates the sll_halen and sll_addr -- fields of sockaddr_ll (as defined in -- <linux/if_packet.h>). data PhysicalAddress -- | Up to eight bytes, for use with a PhysicalAddress type PhysicalAddressBytes = (Word8, Word8, Word8, Word8, Word8, Word8, Word8, Word8) -- | Get the length of the given PhysicalAddress. addressLength :: PhysicalAddress -> SllHaLen -- | Get the address bytes for the given PhysicalAddress address :: PhysicalAddress -> PhysicalAddressBytes -- | Create a new PhysicalAddress with the given length and bytes. -- Note that addressLength must be between 0 and 8 mkPhysicalAddress :: Int -> PhysicalAddressBytes -> Maybe PhysicalAddress -- | Create a new PhysicalAddress to represent the the given MAC -- address. macAddress :: (Word8, Word8, Word8, Word8, Word8, Word8) -> PhysicalAddress -- | Ethernet Protocol IDs. -- -- These are IEEE 802.3 protocol numbers (as defined in -- <linux/if_ether.h>), for use in SockAddrLl -- addresses when working with packet sockets. -- -- Some of the defined patterns may be unsupported on some systems: see -- isSupportedProtocolId. data ProtocolId pattern GeneralProtocolId :: CUShort -> ProtocolId -- | Unsupported protocol id, equal to any other protocol ids that are not -- supported on the system. pattern UnsupportedProtocolId :: ProtocolId -- | Ethernet Loopback packet pattern ETH_P_LOOP :: ProtocolId -- | Xerox PUP packet pattern ETH_P_PUP :: ProtocolId -- | Xerox PUP Addr Trans packet pattern ETH_P_PUPAT :: ProtocolId -- | Internet Protocol packet pattern ETH_P_IP :: ProtocolId -- | CCITT X.25 pattern ETH_P_X25 :: ProtocolId -- | Address Resolution packet pattern ETH_P_ARP :: ProtocolId -- | G8BPQ AX.25 Ethernet Packet [ NOT AN OFFICIALLY REGISTERED ID ] pattern ETH_P_BPQ :: ProtocolId -- | Xerox IEEE802.3 PUP packet pattern ETH_P_IEEEPUP :: ProtocolId -- | Xerox IEEE802.3 PUP Addr Trans packet pattern ETH_P_IEEEPUPAT :: ProtocolId -- | DEC Assigned proto pattern ETH_P_DEC :: ProtocolId -- | DEC DNA Dump/Load pattern ETH_P_DNA_DL :: ProtocolId -- | DEC DNA Remote Console pattern ETH_P_DNA_RC :: ProtocolId -- | DEC DNA Routing pattern ETH_P_DNA_RT :: ProtocolId -- | DEC LAT pattern ETH_P_LAT :: ProtocolId -- | DEC Diagnostics pattern ETH_P_DIAG :: ProtocolId -- | DEC Customer use pattern ETH_P_CUST :: ProtocolId -- | DEC Systems Comms Arch pattern ETH_P_SCA :: ProtocolId -- | Trans Ether Bridging pattern ETH_P_TEB :: ProtocolId -- | Reverse Addr Res packet pattern ETH_P_RARP :: ProtocolId -- | Appletalk DDP pattern ETH_P_ATALK :: ProtocolId -- | Appletalk AARP pattern ETH_P_AARP :: ProtocolId -- | 802.1Q VLAN Extended Header pattern ETH_P_8021Q :: ProtocolId -- | IPX over DIX pattern ETH_P_IPX :: ProtocolId -- | IPv6 over bluebook pattern ETH_P_IPV6 :: ProtocolId -- | IEEE Pause frames. See 802.3 31B pattern ETH_P_PAUSE :: ProtocolId -- | Slow Protocol. See 802.3ad 43B pattern ETH_P_SLOW :: ProtocolId -- | Web-cache coordination protocol pattern ETH_P_WCCP :: ProtocolId -- | PPPoE discovery messages pattern ETH_P_PPP_DISC :: ProtocolId -- | PPPoE session messages pattern ETH_P_PPP_SES :: ProtocolId -- | MPLS Unicast traffic pattern ETH_P_MPLS_UC :: ProtocolId -- | MPLS Multicast traffic pattern ETH_P_MPLS_MC :: ProtocolId -- | MultiProtocol Over ATM pattern ETH_P_ATMMPOA :: ProtocolId -- | Frame-based ATM Transport pattern ETH_P_ATMFATE :: ProtocolId -- | Port Access Entity (IEEE 802.1X) pattern ETH_P_PAE :: ProtocolId -- | ATA over Ethernet pattern ETH_P_AOE :: ProtocolId -- | TIPC pattern ETH_P_TIPC :: ProtocolId -- | IEEE 1588 Timesync pattern ETH_P_1588 :: ProtocolId -- | Fibre Channel over Ethernet pattern ETH_P_FCOE :: ProtocolId -- | FCoE Initialization Protocol pattern ETH_P_FIP :: ProtocolId -- | Ethertype DSA [ NOT AN OFFICIALLY REGISTERED ID ] pattern ETH_P_EDSA :: ProtocolId -- | Dummy type for 802.3 frames pattern ETH_P_802_3 :: ProtocolId -- | Dummy protocol id for AX.25 pattern ETH_P_AX25 :: ProtocolId -- | Every packet (be careful!!!) pattern ETH_P_ALL :: ProtocolId -- | 802.2 frames pattern ETH_P_802_2 :: ProtocolId -- | Internal only pattern ETH_P_SNAP :: ProtocolId -- | DEC DDCMP: Internal only pattern ETH_P_DDCMP :: ProtocolId -- | Dummy type for WAN PPP frames pattern ETH_P_WAN_PPP :: ProtocolId -- | Dummy type for PPP MP frames pattern ETH_P_PPP_MP :: ProtocolId -- | Localtalk pseudo type pattern ETH_P_LOCALTALK :: ProtocolId -- | Controller Area Network pattern ETH_P_CAN :: ProtocolId -- | Dummy type for Atalk over PPP pattern ETH_P_PPPTALK :: ProtocolId -- | 802.2 frames pattern ETH_P_TR_802_2 :: ProtocolId -- | Mobitex (kaz@cafe.net) pattern ETH_P_MOBITEX :: ProtocolId -- | Card specific control frames pattern ETH_P_CONTROL :: ProtocolId -- | Linux-IrDA pattern ETH_P_IRDA :: ProtocolId -- | Acorn Econet pattern ETH_P_ECONET :: ProtocolId -- | HDLC frames pattern ETH_P_HDLC :: ProtocolId -- | 1A for ArcNet :-) pattern ETH_P_ARCNET :: ProtocolId -- | Distributed Switch Arch. pattern ETH_P_DSA :: ProtocolId -- | Trailer switch tagging pattern ETH_P_TRAILER :: ProtocolId -- | Nokia Phonet frames pattern ETH_P_PHONET :: ProtocolId -- | IEEE802.15.4 frame pattern ETH_P_IEEE802154 :: ProtocolId -- | Does one of the ETH_ constants correspond to a known Ethernet -- protocol id on this system? -- -- Just like for isSupportedFamily, GeneralProtocolId -- values not equal to any of the named ETH_xxxxx patterns or -- UnsupportedProtocolId will return True even when not -- known on this system. isSupportedProtocolId :: ProtocolId -> Bool -- | Convert ProtocolId to network byte order, for use with -- socket toProtocolNumber :: ProtocolId -> ProtocolNumber -- | Packet Types. -- -- Linux packet types as defined in <linux/if_packet.h>, -- for use in SockAddrLl addresses when working with packet sockets. -- -- Some of the defined patterns may be unsupported on some systems: see -- isSupportedPacketType. data PacketType pattern GeneralPacketType :: CUChar -> PacketType -- | Unsupported packet id, equal to any other packet ids that are not -- supported on the system. pattern UnsupportedPacketType :: PacketType -- | To us pattern PACKET_HOST :: PacketType -- | To all pattern PACKET_BROADCAST :: PacketType -- | To group pattern PACKET_MULTICAST :: PacketType -- | To someone else pattern PACKET_OTHERHOST :: PacketType -- | Outgoing of any type pattern PACKET_OUTGOING :: PacketType -- | Does one of the PACKET_ constants correspond to a known -- packet type on this system? -- -- Like for isSupportedFamily, GeneralPacketType values not -- equal to any of the named PACKET_ patterns or -- UnsupportedPacketType will return True even when not -- known on this system. isSupportedPacketType :: PacketType -> Bool