aboutsummaryrefslogtreecommitdiff
path: root/toys/pending
diff options
context:
space:
mode:
Diffstat (limited to 'toys/pending')
-rw-r--r--toys/pending/route.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/toys/pending/route.c b/toys/pending/route.c
index b4e7ea0d..562e5ecd 100644
--- a/toys/pending/route.c
+++ b/toys/pending/route.c
@@ -49,6 +49,7 @@ config ROUTE
#define FOR_route
#include "toys.h"
#include <net/route.h>
+#include <linux/rtnetlink.h>
GLOBALS(
char *family;
@@ -74,6 +75,37 @@ static struct _arglist arglist2[] = {
{ NULL, 0 }
};
+void xsend(int sockfd, void *buf, size_t len)
+{
+ if (send(sockfd, buf, len, 0) != len) exit(EXIT_FAILURE);
+}
+
+int xrecv(int sockfd, void *buf, size_t len)
+{
+ int msg_len = recv(sockfd, buf, len, 0);
+ if (msg_len < 0) exit(EXIT_FAILURE);
+
+ return msg_len;
+}
+
+void send_nlrtmsg(int fd, int type, int flags, struct rtmsg *rt)
+{
+ struct {
+ struct nlmsghdr nl;
+ struct rtmsg rt;
+ } req;
+
+ memset(&req, 0, sizeof(req));
+ req.nl.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
+ req.nl.nlmsg_type = type;
+ req.nl.nlmsg_flags = flags;
+ req.nl.nlmsg_pid = getpid();
+ req.nl.nlmsg_seq = 1;
+ req.rt = *rt;
+
+ xsend(fd, &req, sizeof(req));
+}
+
// to get the host name from the given ip.
static int get_hostname(char *ipstr, struct sockaddr_in *sockin)
{