summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author崔一鸣 <[email protected]>2018-10-30 16:33:57 +0800
committer崔一鸣 <[email protected]>2018-10-30 16:33:57 +0800
commitb0bc3f96358f1807c056d8ed0558c341f65df822 (patch)
tree2e76a996ef49d1ae648db9df01d14a9572d80ec4
Init commit
-rw-r--r--README.md1
-rw-r--r--access/src/main.cpp0
-rw-r--r--access/src/tun.cpp108
-rw-r--r--common/inc/flwd_utils.h0
-rw-r--r--common/src/flwd_utils.cpp0
-rw-r--r--vendor/maat-v2.3.3.tar.gzbin0 -> 1920396 bytes
6 files changed, 109 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..46f5257
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+* IP复用接入服务器
diff --git a/access/src/main.cpp b/access/src/main.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/access/src/main.cpp
diff --git a/access/src/tun.cpp b/access/src/tun.cpp
new file mode 100644
index 0000000..80e0063
--- /dev/null
+++ b/access/src/tun.cpp
@@ -0,0 +1,108 @@
+#include <stdio.h>
+#include <string.h>
+
+#include <linux/if_tun.h>
+#include <netinet/in.h>
+#include<fcntl.h>
+
+#include<linux/udp.h>
+
+#include"tun.h"
+#include"client_stat.h"
+
+extern struct global_stat_t global_stat;
+
+/**************************************************************************
+ * tun_alloc: create a tun fd,and set tun param . *
+ * return : a tun fd *
+ **************************************************************************/
+int tun_alloc(char *dev)
+{
+ struct ifreq ifr;
+ int fd, err;
+
+ if ((fd = open("/dev/net/tun", O_RDWR)) < 0)
+ {
+ printf("open function errno %d is %s\n",errno,strerror(errno));
+ assert(0);
+ }
+
+ memset(&ifr, 0, sizeof(ifr));
+ ifr.ifr_flags = IFF_TUN | IFF_NO_PI;//不包含tun包信息
+
+ if (*dev)
+ {
+ strncpy(ifr.ifr_name, dev, IFNAMSIZ);
+ }
+
+ if ((err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0)
+ {
+ printf("ioctl function err is %d,errno %d is %s\n",err,errno,strerror(errno));
+ close(fd);
+ assert(0);
+ }
+ strcpy(dev, ifr.ifr_name);
+
+ return fd;
+}
+
+/**************************************************************************
+ * read_from_tun: read data from tun , and puts them into buffer. *
+ * return : read bytes *
+ **************************************************************************/
+int read_from_tun(int tun_fd, char *recv_ip_pkts,size_t ip_pkt_len)
+ {
+ int recv_ip_len = 0;
+ recv_ip_len = read(tun_fd, recv_ip_pkts, ip_pkt_len);
+ if(recv_ip_len < 0)
+ {
+ close(tun_fd);
+ printf("read function errno %d is %s\n",errno, strerror(errno));
+ assert(0);
+ }
+ else
+ {
+ global_stat.recv_ip_bytes += recv_ip_len;
+ global_stat.recv_ip_pkts ++;
+ return recv_ip_len;
+ }
+
+
+
+ }
+
+
+ /**************************************************************************
+ * write_to_tun: write data to tun *
+ * return:write bytes *
+ **************************************************************************/
+int write_to_tun(int tun_fd, char *send_ip_pkts, int send_ip_len)
+ {
+ assert(send_ip_pkts !=NULL);
+ assert(send_ip_len > 0);
+
+ int cur_snd_ip_len = 0 ;
+
+ cur_snd_ip_len = write(tun_fd, send_ip_pkts, send_ip_len);
+ if(cur_snd_ip_len < 0)
+ {
+ printf(" send ip pkts errno = %d, content is %s\n",errno, strerror(errno));
+ assert(0);
+ }
+ else
+ {
+ if(cur_snd_ip_len < send_ip_len)
+ {
+ close(tun_fd);
+ printf("the ip data can not send completely!\n");
+ assert(0);
+ }
+ else
+ {
+ global_stat.send_ip_bytes += cur_snd_ip_len;
+ global_stat.send_ip_pkts ++;
+ return cur_snd_ip_len;
+ }
+
+ }
+ }
diff --git a/common/inc/flwd_utils.h b/common/inc/flwd_utils.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/common/inc/flwd_utils.h
diff --git a/common/src/flwd_utils.cpp b/common/src/flwd_utils.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/common/src/flwd_utils.cpp
diff --git a/vendor/maat-v2.3.3.tar.gz b/vendor/maat-v2.3.3.tar.gz
new file mode 100644
index 0000000..f499688
--- /dev/null
+++ b/vendor/maat-v2.3.3.tar.gz
Binary files differ