mirror of
https://github.com/wangyu-/UDPspeeder.git
synced 2025-01-31 20:29:37 +08:00
new function tcp csum
This commit is contained in:
parent
bd323be9c4
commit
19e718f0a3
33
common.cpp
33
common.cpp
@ -260,6 +260,39 @@ unsigned short csum(const unsigned short *ptr,int nbytes) {
|
|||||||
|
|
||||||
return(answer);
|
return(answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unsigned short tcp_csum(const pseudo_header & ph,const unsigned short *ptr,int nbytes) {//works both for big and little endian
|
||||||
|
|
||||||
|
register long sum;
|
||||||
|
unsigned short oddbyte;
|
||||||
|
register short answer;
|
||||||
|
|
||||||
|
sum=0;
|
||||||
|
unsigned short * tmp= (unsigned short *)&ph;
|
||||||
|
for(int i=0;i<6;i++)
|
||||||
|
{
|
||||||
|
sum+=*tmp++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
while(nbytes>1) {
|
||||||
|
sum+=*ptr++;
|
||||||
|
nbytes-=2;
|
||||||
|
}
|
||||||
|
if(nbytes==1) {
|
||||||
|
oddbyte=0;
|
||||||
|
*((u_char*)&oddbyte)=*(u_char*)ptr;
|
||||||
|
sum+=oddbyte;
|
||||||
|
}
|
||||||
|
|
||||||
|
sum = (sum>>16)+(sum & 0xffff);
|
||||||
|
sum = sum + (sum>>16);
|
||||||
|
answer=(short)~sum;
|
||||||
|
|
||||||
|
return(answer);
|
||||||
|
}
|
||||||
|
|
||||||
int set_buf_size(int fd,int socket_buf_size,int force_socket_buf)
|
int set_buf_size(int fd,int socket_buf_size,int force_socket_buf)
|
||||||
{
|
{
|
||||||
if(force_socket_buf)
|
if(force_socket_buf)
|
||||||
|
8
common.h
8
common.h
@ -176,6 +176,13 @@ struct fd_info_t
|
|||||||
ip_port_t ip_port;
|
ip_port_t ip_port;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct pseudo_header {
|
||||||
|
u_int32_t source_address;
|
||||||
|
u_int32_t dest_address;
|
||||||
|
u_int8_t placeholder;
|
||||||
|
u_int8_t protocol;
|
||||||
|
u_int16_t tcp_length;
|
||||||
|
};
|
||||||
|
|
||||||
u64_t get_current_time();
|
u64_t get_current_time();
|
||||||
u64_t get_current_time_us();
|
u64_t get_current_time_us();
|
||||||
@ -209,6 +216,7 @@ void setnonblocking(int sock);
|
|||||||
int set_buf_size(int fd,int socket_buf_size,int force_socket_buf=0);
|
int set_buf_size(int fd,int socket_buf_size,int force_socket_buf=0);
|
||||||
|
|
||||||
unsigned short csum(const unsigned short *ptr,int nbytes);
|
unsigned short csum(const unsigned short *ptr,int nbytes);
|
||||||
|
unsigned short tcp_csum(const pseudo_header & ph,const unsigned short *ptr,int nbytes);
|
||||||
|
|
||||||
void signal_handler(int sig);
|
void signal_handler(int sig);
|
||||||
int numbers_to_char(id_t id1,id_t id2,id_t id3,char * &data,int &len);
|
int numbers_to_char(id_t id1,id_t id2,id_t id3,char * &data,int &len);
|
||||||
|
18
misc.cpp
18
misc.cpp
@ -48,7 +48,9 @@ char tun_dev[100]="";
|
|||||||
|
|
||||||
int keep_reconnect=0;
|
int keep_reconnect=0;
|
||||||
|
|
||||||
|
int tun_mtu=1500;
|
||||||
|
|
||||||
|
int mssfix=1;
|
||||||
|
|
||||||
|
|
||||||
int from_normal_to_fec(conn_info_t & conn_info,char *data,int len,int & out_n,char **&out_arr,int *&out_len,my_time_t *&out_delay)
|
int from_normal_to_fec(conn_info_t & conn_info,char *data,int len,int & out_n,char **&out_arr,int *&out_len,my_time_t *&out_delay)
|
||||||
@ -571,6 +573,8 @@ void process_arg(int argc, char *argv[])
|
|||||||
{"fifo", required_argument, 0, 1},
|
{"fifo", required_argument, 0, 1},
|
||||||
{"sub-net", required_argument, 0, 1},
|
{"sub-net", required_argument, 0, 1},
|
||||||
{"tun-dev", required_argument, 0, 1},
|
{"tun-dev", required_argument, 0, 1},
|
||||||
|
{"tun-mtu", required_argument, 0, 1},
|
||||||
|
{"disable-mssfix", no_argument, 0, 1},
|
||||||
{"keep-reconnect", no_argument, 0, 1},
|
{"keep-reconnect", no_argument, 0, 1},
|
||||||
{NULL, 0, 0, 0}
|
{NULL, 0, 0, 0}
|
||||||
};
|
};
|
||||||
@ -885,15 +889,23 @@ void process_arg(int argc, char *argv[])
|
|||||||
|
|
||||||
}
|
}
|
||||||
else if(strcmp(long_options[option_index].name,"tun-dev")==0)
|
else if(strcmp(long_options[option_index].name,"tun-dev")==0)
|
||||||
{
|
|
||||||
if(optarg!=0)
|
|
||||||
{
|
{
|
||||||
sscanf(optarg,"%s",tun_dev);
|
sscanf(optarg,"%s",tun_dev);
|
||||||
mylog(log_info,"tun_dev=%s\n",tun_dev);
|
mylog(log_info,"tun_dev=%s\n",tun_dev);
|
||||||
}
|
|
||||||
mylog(log_info,"running at tun-dev mode\n");
|
mylog(log_info,"running at tun-dev mode\n");
|
||||||
working_mode=tun_dev_mode;
|
working_mode=tun_dev_mode;
|
||||||
}
|
}
|
||||||
|
else if(strcmp(long_options[option_index].name,"tun-mtu")==0)
|
||||||
|
{
|
||||||
|
sscanf(optarg,"%d",&tun_mtu);
|
||||||
|
mylog(log_warn,"changed tun_mtu,tun_mtu=%d\n",tun_mtu);
|
||||||
|
}
|
||||||
|
else if(strcmp(long_options[option_index].name,"disable-mssfix")==0)
|
||||||
|
{
|
||||||
|
mssfix=0;
|
||||||
|
mylog(log_warn,"mssfix disabled\n");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mylog(log_fatal,"unknown option\n");
|
mylog(log_fatal,"unknown option\n");
|
||||||
|
4
misc.h
4
misc.h
@ -48,6 +48,10 @@ extern int delay_capacity;
|
|||||||
|
|
||||||
extern int keep_reconnect;
|
extern int keep_reconnect;
|
||||||
|
|
||||||
|
extern int tun_mtu;
|
||||||
|
|
||||||
|
extern int mssfix;
|
||||||
|
|
||||||
|
|
||||||
int from_normal_to_fec(conn_info_t & conn_info,char *data,int len,int & out_n,char **&out_arr,int *&out_len,my_time_t *&out_delay);
|
int from_normal_to_fec(conn_info_t & conn_info,char *data,int len,int & out_n,char **&out_arr,int *&out_len,my_time_t *&out_delay);
|
||||||
int from_fec_to_normal(conn_info_t & conn_info,char *data,int len,int & out_n,char **&out_arr,int *&out_len,my_time_t *&out_delay);
|
int from_fec_to_normal(conn_info_t & conn_info,char *data,int len,int & out_n,char **&out_arr,int *&out_len,my_time_t *&out_delay);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user