mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-02-08 08:09:34 +08:00
windows works
This commit is contained in:
parent
a75afc94bb
commit
970cd8bac5
6
common.h
6
common.h
@ -47,7 +47,13 @@
|
|||||||
//#include <linux/if_packet.h>
|
//#include <linux/if_packet.h>
|
||||||
//#include <byteswap.h>
|
//#include <byteswap.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
|
#ifndef __CYGWIN__
|
||||||
#include <pcap.h>
|
#include <pcap.h>
|
||||||
|
#else
|
||||||
|
#include <pcap_wrapper.h>
|
||||||
|
#define NO_LIBNET
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef NO_LIBNET
|
#ifndef NO_LIBNET
|
||||||
#include <libnet.h>
|
#include <libnet.h>
|
||||||
|
20
main.cpp
20
main.cpp
@ -972,6 +972,26 @@ void sigint_cb(struct ev_loop *l, ev_signal *w, int revents)
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
init_pcap();
|
||||||
|
int i=0;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
|
||||||
|
pcap_if_t *interfaces,*d;
|
||||||
|
if(pcap_findalldevs(&interfaces,errbuf)==-1)
|
||||||
|
{
|
||||||
|
printf("\nerror in pcap findall devs");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(pcap_if_t *d=interfaces; d!=NULL; d=d->next) {
|
||||||
|
printf("%s:", d->name);
|
||||||
|
for(pcap_addr_t *a=d->addresses; a!=NULL; a=a->next) {
|
||||||
|
if(a->addr->sa_family == AF_INET)
|
||||||
|
printf(" %s", inet_ntoa(((struct sockaddr_in*)a->addr)->sin_addr));
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
//libnet_t *l; /* the libnet context */
|
//libnet_t *l; /* the libnet context */
|
||||||
//char errbuf[LIBNET_ERRBUF_SIZE];
|
//char errbuf[LIBNET_ERRBUF_SIZE];
|
||||||
|
|
||||||
|
64
makefile
64
makefile
@ -10,7 +10,12 @@ 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++
|
#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}
|
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
|
||||||
|
|
||||||
|
PCAP="-lpcap"
|
||||||
|
|
||||||
|
LIBNET=-D_DEFAULT_SOURCE `libnet-config --defines` `libnet-config --libs`
|
||||||
|
|
||||||
|
|
||||||
SOURCES= $(COMMON) lib/aes_faster_c/aes.cpp lib/aes_faster_c/wrapper.cpp
|
SOURCES= $(COMMON) lib/aes_faster_c/aes.cpp lib/aes_faster_c/wrapper.cpp
|
||||||
SOURCES_TINY_AES= $(COMMON) lib/aes.cpp
|
SOURCES_TINY_AES= $(COMMON) lib/aes.cpp
|
||||||
@ -21,8 +26,12 @@ TARGETS=amd64 arm amd64_hw_aes arm_asm_aes mips24kc_be mips24kc_be_asm_aes x86 x
|
|||||||
TAR=${NAME}_binaries.tar.gz `echo ${TARGETS}|sed -r 's/([^ ]+)/udp2raw_\1/g'` version.txt
|
TAR=${NAME}_binaries.tar.gz `echo ${TARGETS}|sed -r 's/([^ ]+)/udp2raw_\1/g'` version.txt
|
||||||
|
|
||||||
all:git_version
|
all:git_version
|
||||||
|
echo "do not use 'make all', instead, use 'make linux' 'make mac' 'make freebsd' 'make cygwin' "
|
||||||
|
|
||||||
|
cygwin:git_version
|
||||||
rm -f ${NAME}
|
rm -f ${NAME}
|
||||||
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -ggdb -static -O2
|
${cc_local} -o ${NAME} -I. ${SOURCES} pcap_wrapper.cpp ${FLAGS} -lrt -ggdb -static -O2 -D_GNU_SOURCE
|
||||||
|
|
||||||
mac:git_version
|
mac:git_version
|
||||||
rm -f ${NAME}
|
rm -f ${NAME}
|
||||||
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -ggdb -O2
|
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -ggdb -O2
|
||||||
@ -36,57 +45,10 @@ debug2: git_version
|
|||||||
rm -f ${NAME}
|
rm -f ${NAME}
|
||||||
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -Wformat-nonliteral -ggdb
|
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -Wformat-nonliteral -ggdb
|
||||||
|
|
||||||
dynamic: git_version
|
#dynamic: git_version
|
||||||
${cc_local} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -O3
|
# ${cc_local} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -O3
|
||||||
|
|
||||||
mips24kc_be: git_version
|
|
||||||
${cc_mips24kc_be} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -lgcc_eh -static -O3
|
|
||||||
mips24kc_be_asm_aes: git_version
|
|
||||||
${cc_mips24kc_be} -o ${NAME}_$@ -I. ${SOURCES_AES_ACC} ${FLAGS} -lrt -lgcc_eh -static -O3 lib/aes_acc/asm/mips_be.S
|
|
||||||
|
|
||||||
mips24kc_le: git_version
|
|
||||||
${cc_mips24kc_le} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -lgcc_eh -static -O3
|
|
||||||
mips24kc_le_asm_aes: git_version
|
|
||||||
${cc_mips24kc_le} -o ${NAME}_$@ -I. ${SOURCES_AES_ACC} ${FLAGS} -lrt -lgcc_eh -static -O3 lib/aes_acc/asm/mips.S
|
|
||||||
|
|
||||||
#bcm2708:
|
|
||||||
# ${cc_bcm2708} -o ${NAME}_bcm2708 -I. ${SOURCES} ${FLAGS} -lrt -static -O3
|
|
||||||
amd64:git_version
|
|
||||||
${cc_local} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -O3
|
|
||||||
|
|
||||||
amd64_perf:git_version
|
|
||||||
${cc_local} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -O0 -fno-omit-frame-pointer -g
|
|
||||||
|
|
||||||
amd64_hw_aes:git_version
|
|
||||||
${cc_local} -o ${NAME}_$@ -I. ${SOURCES_AES_ACC} ${FLAGS} -lrt -static -O3 lib/aes_acc/asm/x64.S
|
|
||||||
x86:git_version
|
|
||||||
${cc_local} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -O3 -m32
|
|
||||||
x86_asm_aes:git_version
|
|
||||||
${cc_local} -o ${NAME}_$@ -I. ${SOURCES_AES_ACC} ${FLAGS} -lrt -static -O3 -m32 lib/aes_acc/asm/x86.S
|
|
||||||
arm:git_version
|
|
||||||
${cc_arm} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -O3
|
|
||||||
|
|
||||||
arm_perf:git_version
|
|
||||||
${cc_arm} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -mapcs-frame -fno-omit-frame-pointer -g -O0 -lgcc_eh
|
|
||||||
|
|
||||||
arm_asm_aes:git_version
|
|
||||||
${cc_arm} -o ${NAME}_$@ -I. ${SOURCES_AES_ACC} ${FLAGS} -lrt -static -O3 lib/aes_acc/asm/arm.S
|
|
||||||
|
|
||||||
cross:git_version
|
|
||||||
${cc_cross} -o ${NAME}_cross -I. ${SOURCES} ${FLAGS} -lrt -O3
|
|
||||||
|
|
||||||
cross2:git_version
|
|
||||||
${cc_cross} -o ${NAME}_cross -I. ${SOURCES} ${FLAGS} -lrt -static -lgcc_eh -O3
|
|
||||||
|
|
||||||
cross3:git_version
|
|
||||||
${cc_cross} -o ${NAME}_cross -I. ${SOURCES} ${FLAGS} -lrt -static -O3
|
|
||||||
|
|
||||||
release: ${TARGETS}
|
|
||||||
cp git_version.h version.txt
|
|
||||||
tar -zcvf ${TAR}
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f ${TAR}
|
|
||||||
rm -f udp2raw udp2raw_cross udp2raw_cmake udp2raw_dynamic
|
rm -f udp2raw udp2raw_cross udp2raw_cmake udp2raw_dynamic
|
||||||
rm -f git_version.h
|
rm -f git_version.h
|
||||||
|
|
||||||
|
11
network.cpp
11
network.cpp
@ -214,8 +214,16 @@ void my_packet_handler(
|
|||||||
const u_char *pkt_data
|
const u_char *pkt_data
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
/*printf("<%d %d>\n",(int)packet_header->caplen,(int)packet_header->len );
|
||||||
|
for(int i=0;i<sizeof(pcap_pkthdr);i++)
|
||||||
|
{
|
||||||
|
char *p=(char *) packet_header;
|
||||||
|
printf("<%x>",int( p[i] ));
|
||||||
|
}
|
||||||
|
printf("\n");*/
|
||||||
assert(packet_header->caplen <= packet_header->len);
|
assert(packet_header->caplen <= packet_header->len);
|
||||||
assert(packet_header->caplen <= max_data_len);
|
assert(packet_header->caplen <= max_data_len);
|
||||||
|
//if(packet_header->caplen > max_data_len) return ;
|
||||||
if(packet_header->caplen<packet_header->len) return;
|
if(packet_header->caplen<packet_header->len) return;
|
||||||
|
|
||||||
if((int)packet_header->caplen<pcap_link_header_len) return;
|
if((int)packet_header->caplen<pcap_link_header_len) return;
|
||||||
@ -828,7 +836,8 @@ int send_raw_ip(raw_info_t &raw_info,const char * payload,int payloadlen)
|
|||||||
iph->id = htons (g_ip_id_counter++); //Id of this packet
|
iph->id = htons (g_ip_id_counter++); //Id of this packet
|
||||||
}
|
}
|
||||||
else*/
|
else*/
|
||||||
iph->id = htons (g_ip_id_counter++); //Id of this packet
|
iph->id = htons (g_ip_id_counter); //Id of this packet
|
||||||
|
g_ip_id_counter++;
|
||||||
//iph->id = 0; //Id of this packet ,kernel will auto fill this if id is zero ,or really?????// todo //seems like there is a problem
|
//iph->id = 0; //Id of this packet ,kernel will auto fill this if id is zero ,or really?????// todo //seems like there is a problem
|
||||||
|
|
||||||
iph->frag_off = htons(0x4000); //DF set,others are zero
|
iph->frag_off = htons(0x4000); //DF set,others are zero
|
||||||
|
Loading…
x
Reference in New Issue
Block a user