Home | History | Annotate | Download | only in lib

Lines Matching refs:rth

38 void rtnl_close(struct rtnl_handle *rth)
40 if (rth->fd >= 0) {
41 close(rth->fd);
42 rth->fd = -1;
46 int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions,
52 memset(rth, 0, sizeof(*rth));
54 rth->proto = protocol;
55 rth->fd = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, protocol);
56 if (rth->fd < 0) {
61 if (setsockopt(rth->fd,SOL_SOCKET,SO_SNDBUF,&sndbuf,sizeof(sndbuf)) < 0) {
66 if (setsockopt(rth->fd,SOL_SOCKET,SO_RCVBUF,&rcvbuf,sizeof(rcvbuf)) < 0) {
71 memset(&rth->local, 0, sizeof(rth->local));
72 rth->local.nl_family = AF_NETLINK;
73 rth->local.nl_groups = subscriptions;
75 if (bind(rth->fd, (struct sockaddr*)&rth->local, sizeof(rth->local)) < 0) {
79 addr_len = sizeof(rth->local);
80 if (getsockname(rth->fd, (struct sockaddr*)&rth->local, &addr_len) < 0) {
84 if (addr_len != sizeof(rth->local)) {
88 if (rth->local.nl_family != AF_NETLINK) {
89 fprintf(stderr, "Wrong address family %d\n", rth->local.nl_family);
92 rth->seq = time(NULL);
96 int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions)
98 return rtnl_open_byproto(rth, subscriptions, NETLINK_ROUTE);
101 int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type)
103 return rtnl_wilddump_req_filter(rth, family, type, RTEXT_FILTER_VF);
106 int rtnl_wilddump_req_filter(struct rtnl_handle *rth, int family, int type,
122 req.nlh.nlmsg_seq = rth->dump = ++rth->seq;
129 return send(rth->fd, (void*)&req, sizeof(req), 0);
132 int rtnl_send(struct rtnl_handle *rth, const void *buf, int len)
134 return send(rth->fd, buf, len, 0);
137 int rtnl_send_check(struct rtnl_handle *rth, const void *buf, int len)
143 status = send(rth->fd, buf, len, 0);
148 status = recv(rth->fd, resp, sizeof(resp), MSG_DONTWAIT|MSG_PEEK);
170 int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len)
189 nlh.nlmsg_seq = rth->dump = ++rth->seq;
191 return sendmsg(rth->fd, &msg, 0);
194 int rtnl_dump_request_n(struct rtnl_handle *rth, struct nlmsghdr *n)
210 n->nlmsg_seq = rth->dump = ++rth->seq;
212 return sendmsg(rth->fd, &msg, 0);
215 int rtnl_dump_filter_l(struct rtnl_handle *rth,
237 status = recvmsg(rth->fd, &msg, 0);
252 if (rth->dump_fp)
253 fwrite(buf, 1, NLMSG_ALIGN(status), rth->dump_fp);
265 h->nlmsg_pid != rth->local.nl_pid ||
266 h->nlmsg_seq != rth->dump)
283 if (rth->proto == NETLINK_SOCK_DIAG &&
293 if (!rth->dump_fp) {
322 int rtnl_dump_filter_nc(struct rtnl_handle *rth,
331 return rtnl_dump_filter_l(rth, a);
454 int rtnl_listen_all_nsid(struct rtnl_handle *rth)
458 if (setsockopt(rth->fd, SOL_NETLINK, NETLINK_LISTEN_ALL_NSID, &on,
463 rth->flags |= RTNL_HANDLE_F_LISTEN_ALL_NSID;