wangyu 8 年之前
父节点
当前提交
9f10fd4766
共有 5 个文件被更改,包括 32 次插入36 次删除
  1. 1 1
      common.cpp
  2. 6 20
      common.h
  3. 2 2
      encrypt.cpp
  4. 16 6
      encrypt.h
  5. 7 7
      main.cpp

+ 1 - 1
common.cpp

@@ -10,7 +10,7 @@
 
 
 raw_mode_t raw_mode=mode_faketcp;
-map<int, string> raw_mode_tostring = {{mode_faketcp, "faketcp"}, {mode_udp, "udp"}, {mode_icmp, "icmp"}};
+unordered_map<int, const char*> raw_mode_tostring = {{mode_faketcp, "faketcp"}, {mode_udp, "udp"}, {mode_icmp, "icmp"}};
 int socket_buf_size=1024*1024;
 static int random_number_fd=-1;
 

+ 6 - 20
common.h

@@ -9,24 +9,15 @@
 #define COMMON_H_
 
 
+
 #include<stdio.h>
 #include<string.h>
-#include<sys/socket.h>
-#include<arpa/inet.h>
 #include<stdlib.h>
 #include<getopt.h>
-#include <unistd.h>
+#include<unistd.h>
 #include<errno.h>
-
-#include <fcntl.h>
-
 #include <sys/epoll.h>
 #include <sys/wait.h>
-
-#include<map>
-#include<string>
-#include<vector>
-
 #include <sys/socket.h>    //for socket ofcourse
 #include <sys/types.h>
 #include <stdlib.h> //for exit(0);
@@ -38,20 +29,13 @@
 #include <arpa/inet.h>
 #include <fcntl.h>
 #include <byteswap.h>
-#include <sys/socket.h>
-#include <sys/types.h>
 #include <arpa/inet.h>
 #include <linux/if_ether.h>
 #include <linux/filter.h>
-
 #include <sys/time.h>
 #include <time.h>
-
 #include <sys/timerfd.h>
-#include <set>
-#include <encrypt.h>
 #include <inttypes.h>
-
 #include <sys/ioctl.h>
 #include <netinet/in.h>
 #include <net/if.h>
@@ -59,8 +43,10 @@
 #include <stdarg.h>
 #include <assert.h>
 
-#include <unordered_map>
 
+
+
+#include<unordered_map>
 using  namespace std;
 
 const int max_data_len=65535;
@@ -99,7 +85,7 @@ enum raw_mode_t{mode_faketcp=1,mode_udp,mode_icmp,mode_end};
 extern raw_mode_t raw_mode;
 enum program_mode_t {unset_mode=0,client_mode,server_mode};
 extern program_mode_t program_mode;
-extern map<int, string> raw_mode_tostring ;
+extern unordered_map<int, const char*> raw_mode_tostring ;
 extern int socket_buf_size;
 
 typedef uint32_t id_t;

+ 2 - 2
encrypt.cpp

@@ -13,8 +13,8 @@
 static int8_t zero_iv[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,   0,0,0,0};//this prog use zero iv,you should make sure first block of data contains a random/nonce data
 
 
-map<int, string> auth_mode_tostring = {{auth_none, "none"}, {auth_md5, "md5"}, {auth_crc32, "crc32"},{auth_sum,"sum"}};
-map<int, string> cipher_mode_tostring={{cipher_none,"none"},{cipher_aes128cbc,"aes128cbc"},{cipher_xor,"xor"}};
+unordered_map<int, const char *> auth_mode_tostring = {{auth_none, "none"}, {auth_md5, "md5"}, {auth_crc32, "crc32"},{auth_sum,"sum"}};
+unordered_map<int, const char *> cipher_mode_tostring={{cipher_none,"none"},{cipher_aes128cbc,"aes128cbc"},{cipher_xor,"xor"}};
 
 auth_mode_t auth_mode=auth_sum;
 cipher_mode_t cipher_mode=cipher_xor;

+ 16 - 6
encrypt.h

@@ -1,11 +1,15 @@
 #ifndef _ENCRYPTION_H_
 #define _ENCRYPTION_H_
-#include "aes.h"
-#include "md5.h"
 
+
+
+//#include "aes.h"
+//#include "md5.h"
 #include "common.h"
 
-using namespace std;
+
+//using namespace std;
+
 int my_encrypt(const char *data,char *output,int &len,char * key);
 int my_decrypt(const char *data,char *output,int &len,char * key);
 
@@ -17,13 +21,19 @@ unsigned short csum(const unsigned short *ptr,int nbytes) ;
 
 
 enum auth_mode_t {auth_none=0,auth_md5,auth_crc32,auth_sum,auth_end};
-extern map<int, string> auth_mode_tostring;
+
 
 enum cipher_mode_t {cipher_none=0,cipher_aes128cbc,cipher_xor,cipher_end};
-extern map<int, string> cipher_mode_tostring;
+
 
 extern auth_mode_t auth_mode;
 extern cipher_mode_t cipher_mode;
-//const map<int, string> auth_mode_tostring2 = {{auth_none, "none"}, {auth_md5, "md5"}, {auth_crc32, "crc32"},{auth_sum,"sum"}};
+
+struct a
+{
+	char * buf[buf_len];
+};
+extern unordered_map<int, const char *> auth_mode_tostring;
+extern unordered_map<int, const char *> cipher_mode_tostring;
 
 #endif

+ 7 - 7
main.cpp

@@ -1,7 +1,7 @@
 #include "common.h"
 #include "network.h"
 #include "log.h"
-
+#include "md5.h"
 
 char local_address[100]="0.0.0.0", remote_address[100]="255.255.255.255",source_address[100]="0.0.0.0";
 uint32_t local_address_uint32,remote_address_uint32,source_address_uint32;
@@ -2698,7 +2698,7 @@ void process_arg(int argc, char *argv[])
 			{
 				for(i=0;i<mode_end;i++)
 				{
-					if(strcmp(optarg,raw_mode_tostring[i].c_str())==0)
+					if(strcmp(optarg,raw_mode_tostring[i])==0)
 					{
 						raw_mode=(raw_mode_t)i;
 						break;
@@ -2714,7 +2714,7 @@ void process_arg(int argc, char *argv[])
 			{
 				for(i=0;i<auth_end;i++)
 				{
-					if(strcmp(optarg,auth_mode_tostring[i].c_str())==0)
+					if(strcmp(optarg,auth_mode_tostring[i])==0)
 					{
 						auth_mode=(auth_mode_t)i;
 						break;
@@ -2730,7 +2730,7 @@ void process_arg(int argc, char *argv[])
 			{
 				for(i=0;i<cipher_end;i++)
 				{
-					if(strcmp(optarg,cipher_mode_tostring[i].c_str())==0)
+					if(strcmp(optarg,cipher_mode_tostring[i])==0)
 					{
 						cipher_mode=(cipher_mode_t)i;
 						break;
@@ -2808,9 +2808,9 @@ void process_arg(int argc, char *argv[])
 	 mylog(log_info,"important variables: ", argc);
 
 	 log_bare(log_info,"log_level=%d:%s ",log_level,log_text[log_level]);
-	 log_bare(log_info,"raw_mode=%s ",raw_mode_tostring[raw_mode].c_str());
-	 log_bare(log_info,"cipher_mode=%s ",cipher_mode_tostring[cipher_mode].c_str());
-	 log_bare(log_info,"auth_mode=%s ",auth_mode_tostring[auth_mode].c_str());
+	 log_bare(log_info,"raw_mode=%s ",raw_mode_tostring[raw_mode]);
+	 log_bare(log_info,"cipher_mode=%s ",cipher_mode_tostring[cipher_mode]);
+	 log_bare(log_info,"auth_mode=%s ",auth_mode_tostring[auth_mode]);
 
 	 log_bare(log_info,"key=%s ",key_string);