mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-02-08 08:09:34 +08:00
endianness macro, fix mac warning
This commit is contained in:
parent
0b44f74d9b
commit
2ab846a9ca
15
common.cpp
15
common.cpp
@ -93,20 +93,19 @@ inline int is_big_endian()
|
|||||||
}
|
}
|
||||||
u64_t ntoh64(u64_t a)
|
u64_t ntoh64(u64_t a)
|
||||||
{
|
{
|
||||||
static int big_endian=is_big_endian();
|
#ifdef UDP2RAW_BIG_ENDIAN
|
||||||
if(!big_endian)
|
|
||||||
{
|
|
||||||
u32_t h=get_u64_h(a);
|
u32_t h=get_u64_h(a);
|
||||||
u32_t l=get_u64_l(a);
|
u32_t l=get_u64_l(a);
|
||||||
return pack_u64(ntohl(l),ntohl(h));
|
return pack_u64(ntohl(l),ntohl(h));
|
||||||
//return bswap_64( a);
|
//return bswap_64( a);
|
||||||
}
|
#else
|
||||||
else return a;
|
return a;
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
u64_t hton64(u64_t a)
|
u64_t hton64(u64_t a)
|
||||||
{
|
{
|
||||||
return ntoh64(u64_t a);
|
return ntoh64(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setnonblocking(int sock) {
|
void setnonblocking(int sock) {
|
||||||
@ -131,9 +130,9 @@ void setnonblocking(int sock) {
|
|||||||
Generic checksum calculation function
|
Generic checksum calculation function
|
||||||
*/
|
*/
|
||||||
unsigned short csum(const unsigned short *ptr,int nbytes) {//works both for big and little endian
|
unsigned short csum(const unsigned short *ptr,int nbytes) {//works both for big and little endian
|
||||||
register long sum;
|
long sum;
|
||||||
unsigned short oddbyte;
|
unsigned short oddbyte;
|
||||||
register short answer;
|
short answer;
|
||||||
|
|
||||||
sum=0;
|
sum=0;
|
||||||
while(nbytes>1) {
|
while(nbytes>1) {
|
||||||
|
19
common.h
19
common.h
@ -61,6 +61,25 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
#if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN || \
|
||||||
|
defined(__BIG_ENDIAN__) || \
|
||||||
|
defined(__ARMEB__) || \
|
||||||
|
defined(__THUMBEB__) || \
|
||||||
|
defined(__AARCH64EB__) || \
|
||||||
|
defined(_MIBSEB) || defined(__MIBSEB) || defined(__MIBSEB__)
|
||||||
|
#define UDP2RAW_BIG_ENDIAN 1
|
||||||
|
#elif defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN || \
|
||||||
|
defined(__LITTLE_ENDIAN__) || \
|
||||||
|
defined(__ARMEL__) || \
|
||||||
|
defined(__THUMBEL__) || \
|
||||||
|
defined(__AARCH64EL__) || \
|
||||||
|
defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__)
|
||||||
|
#define UDP2RAW_LITTLE_ENDIAN 1
|
||||||
|
// It's a little-endian target architecture
|
||||||
|
#else
|
||||||
|
#error "I don't know what architecture this is!"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
typedef unsigned long long u64_t; //this works on most platform,avoid using the PRId64
|
typedef unsigned long long u64_t; //this works on most platform,avoid using the PRId64
|
||||||
typedef long long i64_t;
|
typedef long long i64_t;
|
||||||
|
9
makefile
9
makefile
@ -10,10 +10,10 @@ 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.c 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.c lib/aes_faster_c/wrapper.c
|
SOURCES= $(COMMON) lib/aes_faster_c/aes.cpp lib/aes_faster_c/wrapper.cpp
|
||||||
SOURCES_TINY_AES= $(COMMON) lib/aes.c
|
SOURCES_TINY_AES= $(COMMON) lib/aes.cpp
|
||||||
SOURCES_AES_ACC=$(COMMON) $(wildcard lib/aes_acc/aes*.c)
|
SOURCES_AES_ACC=$(COMMON) $(wildcard lib/aes_acc/aes*.c)
|
||||||
|
|
||||||
NAME=udp2raw
|
NAME=udp2raw
|
||||||
@ -23,6 +23,9 @@ TAR=${NAME}_binaries.tar.gz `echo ${TARGETS}|sed -r 's/([^ ]+)/udp2raw_\1/g'` ve
|
|||||||
all:git_version
|
all:git_version
|
||||||
rm -f ${NAME}
|
rm -f ${NAME}
|
||||||
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -ggdb -static -O3
|
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -ggdb -static -O3
|
||||||
|
mac:git_version
|
||||||
|
rm -f ${NAME}
|
||||||
|
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -ggdb -O2
|
||||||
fast: git_version
|
fast: git_version
|
||||||
rm -f ${NAME}
|
rm -f ${NAME}
|
||||||
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -ggdb
|
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -ggdb
|
||||||
|
@ -2060,7 +2060,7 @@ int try_to_list_and_bind(int &fd,u32_t local_ip_uint32,int port) //try to bind
|
|||||||
temp_bind_addr.sin_port = htons(port);
|
temp_bind_addr.sin_port = htons(port);
|
||||||
temp_bind_addr.sin_addr.s_addr = local_ip_uint32;
|
temp_bind_addr.sin_addr.s_addr = local_ip_uint32;
|
||||||
|
|
||||||
if (bind(fd, (struct sockaddr*)&temp_bind_addr, sizeof(temp_bind_addr)) !=0)
|
if (::bind(fd, (struct sockaddr*)&temp_bind_addr, sizeof(temp_bind_addr)) !=0)
|
||||||
{
|
{
|
||||||
mylog(log_debug,"bind fail\n");
|
mylog(log_debug,"bind fail\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
53
network.h
53
network.h
@ -50,15 +50,13 @@ struct icmphdr
|
|||||||
|
|
||||||
struct my_iphdr
|
struct my_iphdr
|
||||||
{
|
{
|
||||||
//#if __BYTE_ORDER == __LITTLE_ENDIAN
|
#ifdef UDP2RAW_LITTLE_ENDIAN
|
||||||
unsigned int ihl:4;
|
unsigned int ihl:4;
|
||||||
unsigned int version:4;
|
unsigned int version:4;
|
||||||
//#elif __BYTE_ORDER == __BIG_ENDIAN
|
#else
|
||||||
// unsigned int version:4;
|
unsigned int version:4;
|
||||||
// unsigned int ihl:4;
|
unsigned int ihl:4;
|
||||||
//#else
|
#endif
|
||||||
//# error "Please fix <bits/endian.h>"
|
|
||||||
//#endif
|
|
||||||
u_int8_t tos;
|
u_int8_t tos;
|
||||||
u_int16_t tot_len;
|
u_int16_t tot_len;
|
||||||
u_int16_t id;
|
u_int16_t id;
|
||||||
@ -74,7 +72,7 @@ struct my_iphdr
|
|||||||
|
|
||||||
struct my_udphdr
|
struct my_udphdr
|
||||||
{
|
{
|
||||||
__extension__ union
|
/*__extension__*/ union
|
||||||
{
|
{
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
@ -96,7 +94,7 @@ struct my_udphdr
|
|||||||
|
|
||||||
struct my_tcphdr
|
struct my_tcphdr
|
||||||
{
|
{
|
||||||
__extension__ union
|
/*__extension__*/ union
|
||||||
{
|
{
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
@ -104,14 +102,13 @@ struct my_tcphdr
|
|||||||
u_int16_t th_dport; /* destination port */
|
u_int16_t th_dport; /* destination port */
|
||||||
u_int32_t th_seq; /* sequence number */
|
u_int32_t th_seq; /* sequence number */
|
||||||
u_int32_t th_ack; /* acknowledgement number */
|
u_int32_t th_ack; /* acknowledgement number */
|
||||||
//# if __BYTE_ORDER == __LITTLE_ENDIAN
|
# ifdef UDP2RAW_LITTLE_ENDIAN
|
||||||
u_int8_t th_x2:4; /* (unused) */
|
u_int8_t th_x2:4; /* (unused) */
|
||||||
|
u_int8_t tc_off:4; /* data offset */
|
||||||
|
# else
|
||||||
u_int8_t th_off:4; /* data offset */
|
u_int8_t th_off:4; /* data offset */
|
||||||
//# endif
|
u_int8_t th_x2:4; /* (unused) */
|
||||||
//# if __BYTE_ORDER == __BIG_ENDIAN
|
# endif
|
||||||
// u_int8_t th_off:4; /* data offset */
|
|
||||||
// u_int8_t th_x2:4; /* (unused) */
|
|
||||||
//# endif
|
|
||||||
u_int8_t th_flags;
|
u_int8_t th_flags;
|
||||||
# define TH_FIN 0x01
|
# define TH_FIN 0x01
|
||||||
# define TH_SYN 0x02
|
# define TH_SYN 0x02
|
||||||
@ -129,7 +126,7 @@ struct my_tcphdr
|
|||||||
u_int16_t dest;
|
u_int16_t dest;
|
||||||
u_int32_t seq;
|
u_int32_t seq;
|
||||||
u_int32_t ack_seq;
|
u_int32_t ack_seq;
|
||||||
//# if __BYTE_ORDER == __LITTLE_ENDIAN
|
# ifdef UDP2RAW_LITTLE_ENDIAN
|
||||||
u_int16_t res1:4;
|
u_int16_t res1:4;
|
||||||
u_int16_t doff:4;
|
u_int16_t doff:4;
|
||||||
u_int16_t fin:1;
|
u_int16_t fin:1;
|
||||||
@ -139,19 +136,17 @@ struct my_tcphdr
|
|||||||
u_int16_t ack:1;
|
u_int16_t ack:1;
|
||||||
u_int16_t urg:1;
|
u_int16_t urg:1;
|
||||||
u_int16_t res2:2;
|
u_int16_t res2:2;
|
||||||
//# elif __BYTE_ORDER == __BIG_ENDIAN
|
# else
|
||||||
// u_int16_t doff:4;
|
u_int16_t doff:4;
|
||||||
// u_int16_t res1:4;
|
u_int16_t res1:4;
|
||||||
// u_int16_t res2:2;
|
u_int16_t res2:2;
|
||||||
// u_int16_t urg:1;
|
u_int16_t urg:1;
|
||||||
// u_int16_t ack:1;
|
u_int16_t ack:1;
|
||||||
// u_int16_t psh:1;
|
u_int16_t psh:1;
|
||||||
// u_int16_t rst:1;
|
u_int16_t rst:1;
|
||||||
// u_int16_t syn:1;
|
u_int16_t syn:1;
|
||||||
// u_int16_t fin:1;
|
u_int16_t fin:1;
|
||||||
//# else
|
# endif
|
||||||
//# error "Adjust your <bits/endian.h> defines"
|
|
||||||
//# endif
|
|
||||||
u_int16_t window;
|
u_int16_t window;
|
||||||
u_int16_t check;
|
u_int16_t check;
|
||||||
u_int16_t urg_ptr;
|
u_int16_t urg_ptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user