disable header check

This commit is contained in:
lxsang 2020-11-26 20:07:01 +01:00
parent a8979c48dc
commit 831eacf889
3 changed files with 10 additions and 0 deletions

Binary file not shown.

View File

@ -101,11 +101,13 @@ int open_unix_socket(char* path)
int msg_read(int fd, tunnel_msg_t* msg) int msg_read(int fd, tunnel_msg_t* msg)
{ {
#ifdef VERIFY_HEADER
if(msg_check_number(fd, MSG_MAGIC_BEGIN) == -1) if(msg_check_number(fd, MSG_MAGIC_BEGIN) == -1)
{ {
M_ERROR(MODULE_NAME, "Unable to check begin magic number"); M_ERROR(MODULE_NAME, "Unable to check begin magic number");
return -1; return -1;
} }
#endif
if(read(fd,&msg->header.type,sizeof(msg->header.type)) == -1) if(read(fd,&msg->header.type,sizeof(msg->header.type)) == -1)
{ {
M_ERROR(MODULE_NAME, "Unable to read msg type: %s", strerror(errno)); M_ERROR(MODULE_NAME, "Unable to read msg type: %s", strerror(errno));
@ -131,6 +133,7 @@ int msg_read(int fd, tunnel_msg_t* msg)
M_ERROR(MODULE_NAME, "Unable to read msg payload data"); M_ERROR(MODULE_NAME, "Unable to read msg payload data");
return -1; return -1;
} }
#ifdef VERIFY_HEADER
if(msg_check_number(fd, MSG_MAGIC_END) == -1) if(msg_check_number(fd, MSG_MAGIC_END) == -1)
{ {
if(msg->data) if(msg->data)
@ -140,11 +143,13 @@ int msg_read(int fd, tunnel_msg_t* msg)
M_ERROR(MODULE_NAME, "Unable to check end magic number"); M_ERROR(MODULE_NAME, "Unable to check end magic number");
return -1; return -1;
} }
#endif
return 0; return 0;
} }
int msg_write(int fd, tunnel_msg_t* msg) int msg_write(int fd, tunnel_msg_t* msg)
{ {
#ifdef VERIFY_HEADER
// write begin magic number // write begin magic number
int number = MSG_MAGIC_BEGIN; int number = MSG_MAGIC_BEGIN;
if(write(fd,&number, sizeof(number)) == -1) if(write(fd,&number, sizeof(number)) == -1)
@ -152,6 +157,7 @@ int msg_write(int fd, tunnel_msg_t* msg)
M_ERROR(MODULE_NAME, "Unable to write begin magic number: %s", strerror(errno)); M_ERROR(MODULE_NAME, "Unable to write begin magic number: %s", strerror(errno));
return -1; return -1;
} }
#endif
// write type // write type
if(write(fd,&msg->header.type, sizeof(msg->header.type)) == -1) if(write(fd,&msg->header.type, sizeof(msg->header.type)) == -1)
{ {
@ -186,11 +192,13 @@ int msg_write(int fd, tunnel_msg_t* msg)
return -1; return -1;
} }
} }
#ifdef VERIFY_HEADER
number = MSG_MAGIC_END; number = MSG_MAGIC_END;
if(write(fd,&number, sizeof(number)) == -1) if(write(fd,&number, sizeof(number)) == -1)
{ {
M_ERROR(MODULE_NAME, "Unable to write end magic number: %s", strerror(errno)); M_ERROR(MODULE_NAME, "Unable to write end magic number: %s", strerror(errno));
return -1; return -1;
} }
#endif
return 0; return 0;
} }

View File

@ -6,8 +6,10 @@
#define MAX_CHANNEL_PATH 108 #define MAX_CHANNEL_PATH 108
#define MAX_CHANNEL_NAME 64 #define MAX_CHANNEL_NAME 64
#ifdef VERIFY_HEADER
#define MSG_MAGIC_BEGIN 0x414e5444 //ANTD #define MSG_MAGIC_BEGIN 0x414e5444 //ANTD
#define MSG_MAGIC_END 0x44544e41 //DTNA #define MSG_MAGIC_END 0x44544e41 //DTNA
#endif
#define CHANNEL_OK (uint8_t)0x0 #define CHANNEL_OK (uint8_t)0x0
#define CHANNEL_ERROR (uint8_t)0x1 #define CHANNEL_ERROR (uint8_t)0x1