netlink-1.1.1.0: Netlink communication for Haskell

Maintainerongy
Stabilitytesting
PortabilityLinux
Safe HaskellNone
LanguageHaskell2010

System.Linux.Netlink

Description

This is the base module for the netlink package. It contains functions and datatype used by every netlink module. All definitions are (supposed to be) generic enough to be used by implementations of more specific netlink interfaces.

Synopsis

Documentation

data Header Source #

Data type for the netlink header

Constructors

Header 

Fields

Instances

type Attributes = Map Int ByteString Source #

Type used for netlink attributes

data Packet a Source #

The generic netlink message type

Constructors

Packet 

Fields

ErrorMsg 

Fields

DoneMsg 

Fields

Instances

Show NL80211Packet # 
Show RoutePacket # 
Eq a => Eq (Packet a) Source # 

Methods

(==) :: Packet a -> Packet a -> Bool #

(/=) :: Packet a -> Packet a -> Bool #

Show a => Show (Packet a) Source # 

Methods

showsPrec :: Int -> Packet a -> ShowS #

show :: Packet a -> String #

showList :: [Packet a] -> ShowS #

Show a => Show (GenlPacket a) #

Show Instance for GenlPacket

class Convertable a where Source #

Typeclase used by the system. Basically Storable for Get and Put

getGet Returns a Get function for the convertable.

The MessageType is passed so that the function can parse different data structures based on the message type.

Minimal complete definition

getGet, getPut

Methods

getGet Source #

Arguments

:: MessageType 
-> Get a

get a Get function for the static data

getPut Source #

Arguments

:: a 
-> Put

get a Put function for the static data

Instances

Convertable NoData Source # 

Methods

getGet :: MessageType -> Get NoData Source #

getPut :: NoData -> Put Source #

Convertable GenlHeader Source #

The Convertable instance for GenlHeader

Methods

getGet :: MessageType -> Get GenlHeader Source #

getPut :: GenlHeader -> Put Source #

Convertable Message Source # 

Methods

getGet :: MessageType -> Get Message Source #

getPut :: Message -> Put Source #

Convertable a => Convertable (GenlData a) Source #

The Convertable instance for GenlData

Methods

getGet :: MessageType -> Get (GenlData a) Source #

getPut :: GenlData a -> Put Source #

data NoData Source #

Datatype to be used when there is no additional static header

Constructors

NoData 

Instances

Eq NoData Source # 

Methods

(==) :: NoData -> NoData -> Bool #

(/=) :: NoData -> NoData -> Bool #

Show NoData Source # 
Convertable NoData Source # 

Methods

getGet :: MessageType -> Get NoData Source #

getPut :: NoData -> Put Source #

Show (GenlData NoData) #

Show instance of GenlData for NoData

data NetlinkSocket Source #

Typesafe wrapper around a CInt (fd)

getPacket Source #

Arguments

:: ByteString

The buffer to read from

-> Get a

The function to read a single message

-> Either String [a]

Either an error message or a list of messages read

Read packets from the buffer

getAttributes :: Get Attributes Source #

Get Attributes

getHeader :: Get (Int, Header) Source #

Get the netlink Header

putHeader Source #

Arguments

:: Int

The length of the message

-> Header

The header itself

-> Put 

Put the netlink Header

putPacket :: (Convertable a, Eq a, Show a) => Packet a -> [ByteString] Source #

Put a Packet so it can e sent

getPackets :: (Convertable a, Eq a, Show a) => ByteString -> Either String [Packet a] Source #

Read all Packets from a buffer

The packets may have additional static data defined by the protocol.

makeSocket :: IO NetlinkSocket Source #

Open and return a NetlinkSocket, for legacy reasons this opens a route socket

makeSocketGeneric Source #

Arguments

:: Int

The netlink family to use

-> IO NetlinkSocket 

Open a NetlinkSocket. This is the generic function

getNetlinkFd :: NetlinkSocket -> Fd Source #

Get the raw Fd used for netlink communcation (this can be plugged into eventing)

closeSocket :: NetlinkSocket -> IO () Source #

Close a NetlinkSocket when it is no longer used

joinMulticastGroup Source #

Arguments

:: NetlinkSocket

The socket to join with

-> Word32

The id of the group to join, values of System.Linux.Netlink.Constants.eRTNLGRP_*

-> IO () 

Join a netlink multicast group

leaveMulticastGroup Source #

Arguments

:: NetlinkSocket

The socket to leave

-> Word32

The id of the group to leave, values of System.Linux.Netlink.Constants.eRTNLGRP_*

-> IO () 

Leave a netlink multicast group

query :: (Convertable a, Eq a, Show a) => NetlinkSocket -> Packet a -> IO [Packet a] Source #

Query data over netlink.

This sends a Packet over netlink and returns the answer. This blocks in a safe foregin function until the other side replies.

queryOne :: (Convertable a, Eq a, Show a) => NetlinkSocket -> Packet a -> IO (Packet a) Source #

The same as query but requires the answer to be a single message

recvOne :: (Convertable a, Eq a, Show a) => NetlinkSocket -> IO [Packet a] Source #

Calls recvmsg once and returns all received messages

This should only be used outside of the package when reading multicast messages.

The prototype of this function is unintuitive, but this cannot be avoided without buffering in userspace with the netlink api.

showNLAttrs :: Attributes -> String Source #

Convert generic NLAttrs into a string (# and hexdump)

showAttrs Source #

Arguments

:: (Int -> String)

A function from element id to its name

-> Attributes

The attributes

-> String

A string with Element name and hexdump of element

Helper function to convert attributes into a string

showAttr :: (Int -> String) -> (Int, ByteString) -> String Source #

Helper function to generically show a single attribute

showPacket :: Show a => Packet a -> String Source #

Helperfunction for show instance of Packet and further specializations