mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-02-07 23:59:36 +08:00
allow to compile without libnet
This commit is contained in:
parent
33d96331fe
commit
976e0495e5
4
common.h
4
common.h
@ -48,8 +48,10 @@
|
||||
//#include <byteswap.h>
|
||||
#include <pthread.h>
|
||||
#include <pcap.h>
|
||||
#include <libnet.h>
|
||||
|
||||
#ifndef NO_LIBNET
|
||||
#include <libnet.h>
|
||||
#endif
|
||||
|
||||
#include <my_ev.h>
|
||||
|
||||
|
2
makefile
2
makefile
@ -10,7 +10,7 @@ cc_arm= /toolchains/arm-2014.05/bin/arm-none-linux-gnueabi-g++
|
||||
#cc_bcm2708=/home/wangyu/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++
|
||||
FLAGS= -std=c++11 -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers ${OPT}
|
||||
|
||||
COMMON=main.cpp lib/md5.cpp encrypt.cpp log.cpp network.cpp common.cpp connection.cpp misc.cpp fd_manager.cpp -lpthread my_ev.cpp -isystem libev -lpcap -D_DEFAULT_SOURCE `libnet-config --defines` `libnet-config --libs`
|
||||
COMMON=main.cpp lib/md5.cpp encrypt.cpp log.cpp network.cpp common.cpp connection.cpp misc.cpp fd_manager.cpp -lpthread my_ev.cpp -isystem libev -lpcap -D_DEFAULT_SOURCE #`libnet-config --defines` `libnet-config --libs`
|
||||
|
||||
SOURCES= $(COMMON) lib/aes_faster_c/aes.cpp lib/aes_faster_c/wrapper.cpp
|
||||
SOURCES_TINY_AES= $(COMMON) lib/aes.cpp
|
||||
|
5
misc.cpp
5
misc.cpp
@ -121,9 +121,12 @@ void print_help()
|
||||
printf("udp2raw-tunnel\n");
|
||||
printf("git version:%s ",git_version_buf);
|
||||
printf("build date:%s %s\n",__DATE__,__TIME__);
|
||||
|
||||
printf("repository: https://github.com/wangyu-/udp2raw-tunnel\n");
|
||||
printf("\n");
|
||||
#ifdef NO_LIBNET
|
||||
printf("libnet is disabled at compile time\n");
|
||||
printf("\n");
|
||||
#endif
|
||||
printf("usage:\n");
|
||||
printf(" run as client : ./this_program -c -l local_listen_ip:local_port -r server_address:server_port [options]\n");
|
||||
printf(" run as server : ./this_program -s -l server_listen_ip:server_port -r remote_address:remote_port [options]\n");
|
||||
|
21
network.cpp
21
network.cpp
@ -40,7 +40,17 @@ const u32_t receive_window_lower_bound=40960;
|
||||
const u32_t receive_window_random_range=512;
|
||||
const unsigned char wscale=0x05;
|
||||
|
||||
#ifndef NO_LIBNET
|
||||
libnet_t *libnet_handle;
|
||||
libnet_ptag_t g_ptag=0;
|
||||
int send_with_pcap=0;
|
||||
#else
|
||||
int send_with_pcap=1;
|
||||
#endif
|
||||
|
||||
int pcap_header_captured=0;
|
||||
int pcap_header_buf[buf_len];
|
||||
|
||||
pcap_t *pcap_handle;
|
||||
int pcap_link_header_len=-1;
|
||||
//int pcap_cnt=0;
|
||||
@ -59,13 +69,11 @@ char g_packet_buf[buf_len]; //dirty code, fix it later
|
||||
int g_packet_buf_len=1;
|
||||
int g_packet_buf_cnt=0;
|
||||
|
||||
libnet_ptag_t g_ptag=0;
|
||||
|
||||
|
||||
struct bpf_program g_filter;
|
||||
|
||||
int send_with_pcap=0;
|
||||
int pcap_header_captured=0;
|
||||
int pcap_header_buf[buf_len];
|
||||
|
||||
|
||||
int use_tcp_dummy_socket=0;
|
||||
/*
|
||||
@ -267,6 +275,8 @@ extern void async_cb(struct ev_loop *loop, struct ev_async *watcher, int revents
|
||||
|
||||
int init_raw_socket()
|
||||
{
|
||||
|
||||
#ifndef NO_LIBNET
|
||||
char libnet_errbuf[LIBNET_ERRBUF_SIZE];
|
||||
|
||||
libnet_handle = libnet_init(LIBNET_RAW4, dev, libnet_errbuf);
|
||||
@ -278,6 +288,7 @@ int init_raw_socket()
|
||||
}
|
||||
g_ptag=0;
|
||||
libnet_clear_packet(libnet_handle);
|
||||
#endif
|
||||
|
||||
char pcap_errbuf[PCAP_ERRBUF_SIZE];
|
||||
|
||||
@ -844,6 +855,7 @@ int send_raw_ip(raw_info_t &raw_info,const char * payload,int payloadlen)
|
||||
|
||||
if(! send_with_pcap)
|
||||
{
|
||||
#ifndef NO_LIBNET
|
||||
g_ptag=libnet_build_ipv4(ip_tot_len, iph->tos, ntohs(iph->id), ntohs(iph->frag_off),
|
||||
iph->ttl , iph->protocol , iph->check , iph->saddr, iph->daddr,
|
||||
(const unsigned char *)payload, payloadlen, libnet_handle, g_ptag);
|
||||
@ -854,6 +866,7 @@ int send_raw_ip(raw_info_t &raw_info,const char * payload,int payloadlen)
|
||||
ret= libnet_write(libnet_handle);
|
||||
|
||||
assert(ret!=-1);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user