Back to index

numactl  2.0.8~rc4
Defines | Functions
rtnetlink.c File Reference
#include <sys/socket.h>
#include <linux/rtnetlink.h>
#include <linux/netlink.h>
#include <netinet/in.h>
#include <errno.h>
#include <unistd.h>
#include "rtnetlink.h"

Go to the source code of this file.


#define hidden   __attribute__((visibility("hidden")))


hidden void * rta_put (struct nlmsghdr *m, int type, int len)
hidden struct rtattr * rta_get (struct nlmsghdr *m, struct rtattr *p, int offset)
hidden int rta_put_address (struct nlmsghdr *msg, int type, struct sockaddr *adr)
hidden int rtnetlink_request (struct nlmsghdr *msg, int buflen, struct sockaddr_nl *adr)

Define Documentation

#define hidden   __attribute__((visibility("hidden")))

Definition at line 8 of file rtnetlink.c.

Function Documentation

hidden struct rtattr* rta_get ( struct nlmsghdr *  m,
struct rtattr *  p,
int  offset 
) [read]

Definition at line 23 of file rtnetlink.c.

       struct rtattr *rta;

       if (p) {
              rta = RTA_NEXT(p, m->nlmsg_len);
              if (!RTA_OK(rta, m->nlmsg_len))
                     return NULL;
       } else {
              rta = (void *)m + NLMSG_ALIGN(offset);
       return rta;

Here is the caller graph for this function:

hidden void* rta_put ( struct nlmsghdr *  m,
int  type,
int  len 

Definition at line 12 of file rtnetlink.c.

       struct rtattr *rta = (void *)m + NLMSG_ALIGN(m->nlmsg_len);
       int rtalen = RTA_LENGTH(len);

       rta->rta_type = type;
       rta->rta_len = rtalen;
       m->nlmsg_len = NLMSG_ALIGN(m->nlmsg_len) + RTA_ALIGN(rtalen);
       return RTA_DATA(rta);

Here is the caller graph for this function:

hidden int rta_put_address ( struct nlmsghdr *  msg,
int  type,
struct sockaddr *  adr 

Definition at line 38 of file rtnetlink.c.

       switch (adr->sa_family) {
       case AF_INET: {
              struct in_addr *i = rta_put(msg, type, 4);
              *i = ((struct sockaddr_in *)adr)->sin_addr;
       case AF_INET6: {
              struct in6_addr *i6 = rta_put(msg, type, 16);
              *i6 = ((struct sockaddr_in6 *)adr)->sin6_addr;
              return -1;
       return 0;

Here is the call graph for this function:

Here is the caller graph for this function:

hidden int rtnetlink_request ( struct nlmsghdr *  msg,
int  buflen,
struct sockaddr_nl *  adr 

Definition at line 59 of file rtnetlink.c.

       int rsk;
       int n;
       int e;

       /* Use a private socket to avoid having to keep state
          for a sequence number. */
       rsk = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
       if (rsk < 0)
              return -1;
       n = sendto(rsk, msg, msg->nlmsg_len, 0, (struct sockaddr *)adr,
                 sizeof(struct sockaddr_nl));
       if (n >= 0) {
              socklen_t adrlen = sizeof(struct sockaddr_nl);
              n = recvfrom(rsk, msg, buflen, 0, (struct sockaddr *)adr,
       e = errno;
       errno = e;
       if (n < 0)
              return -1;
       /* Assume we only get a single reply back. This is (hopefully?)
          safe because it's a single use socket. */
       if (msg->nlmsg_type == NLMSG_ERROR) {
              struct nlmsgerr *err = NLMSG_DATA(msg);
              errno = -err->error;
              return -1;
       return 0;

Here is the caller graph for this function: