aboutsummaryrefslogtreecommitdiff
path: root/toys/pending/route.c
diff options
context:
space:
mode:
authorEric Molitor <emolitor@molitor.org>2020-05-17 11:09:27 +0100
committerRob Landley <rob@landley.net>2020-05-17 06:14:39 -0500
commite49b008c6169ae7eaf1c765e2a729095b9b59d19 (patch)
tree9b1b3ced76b3c7d0e93167a996b372343b302f6e /toys/pending/route.c
parent37ba2ec8b1a36ba1cb0e3c806b3a25c4d9bd58ab (diff)
downloadtoybox-e49b008c6169ae7eaf1c765e2a729095b9b59d19.tar.gz
Add xsend, xrecv and send_nlrtmsg
Diffstat (limited to 'toys/pending/route.c')
-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)
{