mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-02-07 23:59:36 +08:00
libnet roughly works
This commit is contained in:
parent
8a1d5b58b1
commit
83e13ebc5f
48
main.cpp
48
main.cpp
@ -766,19 +766,51 @@ int client_event_loop()
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sigpipe_cb(struct ev_loop *l, ev_signal *w, int revents)
|
||||
{
|
||||
mylog(log_info, "got sigpipe, ignored");
|
||||
}
|
||||
|
||||
void sigterm_cb(struct ev_loop *l, ev_signal *w, int revents)
|
||||
{
|
||||
mylog(log_info, "got sigterm, exit");
|
||||
myexit(0);
|
||||
}
|
||||
|
||||
void sigint_cb(struct ev_loop *l, ev_signal *w, int revents)
|
||||
{
|
||||
mylog(log_info, "got sigint, exit");
|
||||
myexit(0);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
libnet_t *l; /* the libnet context */
|
||||
char errbuf[LIBNET_ERRBUF_SIZE];
|
||||
//libnet_t *l; /* the libnet context */
|
||||
//char errbuf[LIBNET_ERRBUF_SIZE];
|
||||
|
||||
l = libnet_init(LIBNET_RAW4, NULL, errbuf);
|
||||
//l = libnet_init(LIBNET_RAW4, NULL, errbuf);
|
||||
|
||||
dup2(1, 2);//redirect stderr to stdout
|
||||
signal(SIGINT, signal_handler);
|
||||
signal(SIGHUP, signal_handler);
|
||||
signal(SIGKILL, signal_handler);
|
||||
signal(SIGTERM, signal_handler);
|
||||
signal(SIGQUIT, signal_handler);
|
||||
//signal(SIGINT, signal_handler);
|
||||
//signal(SIGHUP, signal_handler);
|
||||
//signal(SIGKILL, signal_handler);
|
||||
//signal(SIGTERM, signal_handler);
|
||||
//signal(SIGQUIT, signal_handler);
|
||||
|
||||
struct ev_loop* loop=ev_default_loop(0);
|
||||
ev_signal signal_watcher_sigpipe;
|
||||
ev_signal_init(&signal_watcher_sigpipe, sigpipe_cb, SIGPIPE);
|
||||
ev_signal_start(loop, &signal_watcher_sigpipe);
|
||||
|
||||
ev_signal signal_watcher_sigterm;
|
||||
ev_signal_init(&signal_watcher_sigterm, sigterm_cb, SIGTERM);
|
||||
ev_signal_start(loop, &signal_watcher_sigterm);
|
||||
|
||||
ev_signal signal_watcher_sigint;
|
||||
ev_signal_init(&signal_watcher_sigint, sigint_cb, SIGINT);
|
||||
ev_signal_start(loop, &signal_watcher_sigint);
|
||||
|
||||
|
||||
pre_process_arg(argc,argv);
|
||||
|
||||
|
23
network.cpp
23
network.cpp
@ -40,6 +40,8 @@ const u32_t receive_window_lower_bound=40960;
|
||||
const u32_t receive_window_random_range=512;
|
||||
const unsigned char wscale=0x05;
|
||||
|
||||
libnet_t *libnet_handle;
|
||||
|
||||
struct sock_filter code_tcp_old[] = {
|
||||
{ 0x28, 0, 0, 0x0000000c },//0
|
||||
{ 0x15, 0, 10, 0x00000800 },//1
|
||||
@ -174,6 +176,11 @@ packet_info_t::packet_info_t()
|
||||
|
||||
int init_raw_socket()
|
||||
{
|
||||
char errbuf[LIBNET_ERRBUF_SIZE];
|
||||
|
||||
libnet_handle = libnet_init(LIBNET_RAW4, dev, errbuf);
|
||||
|
||||
assert(libnet_handle!=0);
|
||||
|
||||
g_ip_id_counter=get_true_random_number()%65535;
|
||||
if(lower_level==0)
|
||||
@ -612,6 +619,20 @@ int send_raw_ip(raw_info_t &raw_info,const char * payload,int payloadlen)
|
||||
iph->check=0;
|
||||
|
||||
int ret;
|
||||
|
||||
ret=libnet_build_ipv4(ip_tot_len, iph->tos, ntohs(iph->id), ntohs(iph->frag_off),
|
||||
iph->ttl , send_info.protocol, iph->check , iph->saddr, iph->daddr,
|
||||
(const unsigned char *)payload, payloadlen, libnet_handle, 0);
|
||||
assert(ret!=-1);
|
||||
|
||||
ret= libnet_write(libnet_handle);
|
||||
|
||||
assert(ret!=-1);
|
||||
|
||||
libnet_clear_packet(libnet_handle);
|
||||
|
||||
|
||||
/*
|
||||
if(lower_level==0)
|
||||
{
|
||||
struct sockaddr_in sin={0};
|
||||
@ -639,7 +660,7 @@ int send_raw_ip(raw_info_t &raw_info,const char * payload,int payloadlen)
|
||||
else
|
||||
{
|
||||
//mylog(log_info,"sendto succ\n");
|
||||
}
|
||||
}*/
|
||||
return 0;
|
||||
}
|
||||
int peek_raw(packet_info_t &peek_info)
|
||||
|
Loading…
x
Reference in New Issue
Block a user