Hello,

Patch 5


# HG changeset patch
# User MJP
# Date 1452861496 -3600
#      Fri Jan 15 13:38:16 2016 +0100
# Node ID fd7f48f3955596de5fe098de0f4208106578c9db
# Parent  52f96bbfc0cb83010e78d49b63a185555bdc00a7
Add: Introduce common tools to get and set the rdomain of an interface.

diff -r 52f96bbfc0cb -r fd7f48f39555 usr.sbin/npppd/common/net_utils.c
--- usr.sbin/npppd/common/net_utils.c   Sun Jan 10 15:40:46 2016 +0100
+++ usr.sbin/npppd/common/net_utils.c   Fri Jan 15 13:38:16 2016 +0100
@@ -26,6 +26,7 @@
 /* $Id: net_utils.c,v 1.4 2012/05/08 13:18:37 yasuoka Exp $ */
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/ioctl.h>
 #include <netinet/in.h>
 #include <net/if.h>
 #include <ifaddrs.h>
@@ -206,3 +207,47 @@
     }
     return -1;
 }
+
+/** Get the rdomain of a network interface */
+int
+ifname_get_rdomain(char *ifname, int *rdomain)
+{
+       int s;
+       struct ifreq ifr;
+
+       *rdomain = 0;
+       memset(&ifr, 0, sizeof(ifr));
+       if (ifname)
+               strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+
+       s = socket(AF_INET, SOCK_DGRAM, 0);
+       if (s < 0)
+               return 1;
+       if (ioctl(s, SIOCGIFRDOMAIN, &ifr) != -1)
+               *rdomain = ifr.ifr_rdomainid;
+       if (s >= 0)
+               close(s);
+
+       return 0;
+}
+
+/** Set the rdomain of a network interface */
+int
+ifname_set_rdomain(char *ifname, int rdomain)
+{
+       int s, result = 0;
+       struct ifreq ifr;
+
+       memset(&ifr, 0, sizeof(ifr));
+       if (ifname)
+               strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+       ifr.ifr_rdomainid = rdomain;
+
+       s = socket(AF_INET, SOCK_DGRAM, 0);
+       if (s < 0 || ioctl(s, SIOCSIFRDOMAIN, &ifr) != 0)
+               result = 1;
+       if (s >= 0)
+               close(s);
+
+       return result;
+}
diff -r 52f96bbfc0cb -r fd7f48f39555 usr.sbin/npppd/common/net_utils.h
--- usr.sbin/npppd/common/net_utils.h   Sun Jan 10 15:40:46 2016 +0100
+++ usr.sbin/npppd/common/net_utils.h   Fri Jan 15 13:38:16 2016 +0100
@@ -33,6 +33,8 @@
 int         addrport_parse(const char *, int, struct addrinfo **);
 const char *addrport_tostring(struct sockaddr *, socklen_t, char *, int);
 int         netmask2prefixlen(uint32_t);
+int         ifname_get_rdomain(char *, int *);
+int         ifname_set_rdomain(char *, int);
 
 
 #ifdef __cplusplus

Reply via email to