commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 02/04: blocks: fixed issue #853: set MTU on


From: git
Subject: [Commit-gnuradio] [gnuradio] 02/04: blocks: fixed issue #853: set MTU on tun/tap network interface in TUNTAP PDU block xtor
Date: Sun, 17 Jan 2016 18:30:52 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch master
in repository gnuradio.

commit a736f885aef1f40d163a55185533c851c3a33a6e
Author: Sean Nowlan <address@hidden>
Date:   Wed Jan 13 16:54:43 2016 -0500

    blocks: fixed issue #853: set MTU on tun/tap network interface in TUNTAP 
PDU block xtor
---
 gr-blocks/lib/tuntap_pdu_impl.cc | 33 +++++++++++++++++++++++++++++++++
 gr-blocks/lib/tuntap_pdu_impl.h  |  1 +
 2 files changed, 34 insertions(+)

diff --git a/gr-blocks/lib/tuntap_pdu_impl.cc b/gr-blocks/lib/tuntap_pdu_impl.cc
index 45995e4..391b339 100644
--- a/gr-blocks/lib/tuntap_pdu_impl.cc
+++ b/gr-blocks/lib/tuntap_pdu_impl.cc
@@ -76,6 +76,14 @@ namespace gr {
       if (d_fd <= 0)
         throw std::runtime_error("gr::tuntap_pdu::make: tun_alloc failed (are 
you running as root?)");
 
+      int err = set_mtu(dev_cstr, MTU);
+      if(err < 0)
+        std::cerr << boost::format(
+          "gr::tuntap_pdu: failed to set MTU to %d.\n"
+          "You should use ifconfig to set the MTU. E.g.,\n"
+          "  $ sudo ifconfig %s mtu %d\n"
+          ) % MTU % dev % MTU << std::endl;
+
       std::cout << boost::format(
        "Allocated virtual ethernet interface: %s\n"
         "You must now use ifconfig to set its IP address. E.g.,\n"
@@ -140,6 +148,31 @@ namespace gr {
        */
       return fd;
     }
+
+    int
+    tuntap_pdu_impl::set_mtu(const char *dev, int MTU)
+    {
+      struct ifreq ifr;
+      int sfd, err;
+
+      /* MTU must be set by passing a socket fd to ioctl;
+       * create an arbitrary socket for this purpose
+       */
+      if ((sfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+          return sfd;
+
+      /* preparation of the struct ifr, of type "struct ifreq" */
+      memset(&ifr, 0, sizeof(ifr));
+      strncpy(ifr.ifr_name, dev, IFNAMSIZ);
+      ifr.ifr_addr.sa_family = AF_INET; /* address family */
+      ifr.ifr_mtu = MTU;
+
+      /* try to set MTU */
+      if ((err = ioctl(sfd, SIOCSIFMTU, (void *) &ifr)) < 0)
+        return err;
+
+      return MTU;
+    }
 #endif
 
   } /* namespace blocks */
diff --git a/gr-blocks/lib/tuntap_pdu_impl.h b/gr-blocks/lib/tuntap_pdu_impl.h
index 360f954..3a53e3a 100644
--- a/gr-blocks/lib/tuntap_pdu_impl.h
+++ b/gr-blocks/lib/tuntap_pdu_impl.h
@@ -40,6 +40,7 @@ namespace gr {
       std::string d_dev;
       bool d_istunflag;
       int tun_alloc(char *dev, int flags);
+      int set_mtu(const char *dev, int MTU);
 
     public:
       tuntap_pdu_impl(std::string dev, int MTU, bool istunflag);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]