Logo Search packages:      
Sourcecode: libnl2 version File versions  Download package

Core


Detailed Description

1) Connecting the socket
 // Bind and connect the socket to a protocol, NETLINK_ROUTE in this example.
 nl_connect(sk, NETLINK_ROUTE);
2) Sending data
 // The most rudimentary method is to use nl_sendto() simply pushing
 // a piece of data to the other netlink peer. This method is not
 // recommended.
 const char buf[] = { 0x01, 0x02, 0x03, 0x04 };
 nl_sendto(sk, buf, sizeof(buf));

 // A more comfortable interface is nl_send() taking a pointer to
 // a netlink message.
 struct nl_msg *msg = my_msg_builder();
 nl_send(sk, nlmsg_hdr(msg));

 // nl_sendmsg() provides additional control over the sendmsg() message
 // header in order to allow more specific addressing of multiple peers etc.
 struct msghdr hdr = { ... };
 nl_sendmsg(sk, nlmsg_hdr(msg), &hdr);

 // You're probably too lazy to fill out the netlink pid, sequence number
 // and message flags all the time. nl_send_auto_complete() automatically
 // extends your message header as needed with an appropriate sequence
 // number, the netlink pid stored in the netlink socket and the message
 // flags NLM_F_REQUEST and NLM_F_ACK (if not disabled in the socket)
 nl_send_auto_complete(sk, nlmsg_hdr(msg));

 // Simple protocols don't require the complex message construction interface
 // and may favour nl_send_simple() to easly send a bunch of payload
 // encapsulated in a netlink message header.
 nl_send_simple(sk, MY_MSG_TYPE, 0, buf, sizeof(buf));
3) Receiving data
 // nl_recv() receives a single message allocating a buffer for the message
 // content and gives back the pointer to you.
 struct sockaddr_nl peer;
 unsigned char *msg;
 nl_recv(sk, &peer, &msg);

 // nl_recvmsgs() receives a bunch of messages until the callback system
 // orders it to state, usually after receving a compolete multi part
 // message series.
 nl_recvmsgs(sk, my_callback_configuration);

 // nl_recvmsgs_default() acts just like nl_recvmsg() but uses the callback
 // configuration stored in the socket.
 nl_recvmsgs_default(sk);

 // In case you want to wait for the ACK to be recieved that you requested
 // with your latest message, you can call nl_wait_for_ack()
 nl_wait_for_ack(sk);
4) Closing
 // Close the socket first to release kernel memory
 nl_close(sk);


Modules

 Abstract Address
 Caching
 Abstract Data
 Callbacks/Customization
 Messages
 Socket
 Utilities

Receive

static int ack_wait_handler (struct nl_msg *msg, void *arg)
int nl_recv (struct nl_sock *sk, struct sockaddr_nl *nla, unsigned char **buf, struct ucred **creds)
int nl_recvmsgs (struct nl_sock *sk, struct nl_cb *cb)
int nl_recvmsgs_default (struct nl_sock *sk)
int nl_wait_for_ack (struct nl_sock *sk)
static int recvmsgs (struct nl_sock *sk, struct nl_cb *cb)
#define NL_CB_CALL(cb, type, msg)

Connection Management

void nl_close (struct nl_sock *sk)
int nl_connect (struct nl_sock *sk, int protocol)

Send

int nl_send (struct nl_sock *sk, struct nl_msg *msg)
int nl_send_auto_complete (struct nl_sock *sk, struct nl_msg *msg)
int nl_send_simple (struct nl_sock *sk, int type, int flags, void *buf, size_t size)
int nl_sendmsg (struct nl_sock *sk, struct nl_msg *msg, struct msghdr *hdr)
int nl_sendto (struct nl_sock *sk, void *buf, size_t size)


Generated by  Doxygen 1.6.0   Back to index