当前位置: 首页>>代码示例>>C++>>正文


C++ pcap_inject函数代码示例

本文整理汇总了C++中pcap_inject函数的典型用法代码示例。如果您正苦于以下问题:C++ pcap_inject函数的具体用法?C++ pcap_inject怎么用?C++ pcap_inject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了pcap_inject函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: pcapint_write_packet

static int pcapint_write_packet(libtrace_out_t *libtrace,
                                libtrace_packet_t *packet)
{
    int err;

    if (trace_get_link_type(packet) == TRACE_TYPE_NONDATA)
        return 0;

    if (!OUTPUT.trace.pcap) {
        OUTPUT.trace.pcap = (pcap_t *)pcap_open_live(
                                libtrace->uridata,65536,0,0,NULL);
    }
#ifdef HAVE_PCAP_INJECT
    err=pcap_inject(OUTPUT.trace.pcap,
                    packet->payload,
                    trace_get_capture_length(packet));
    if (err!=(int)trace_get_capture_length(packet))
        err=-1;
#else
#ifdef HAVE_PCAP_SENDPACKET
    err=pcap_sendpacket(OUTPUT.trace.pcap,
                        packet->payload,
                        trace_get_capture_length(packet));
#else
    trace_set_err(packet->trace,TRACE_ERR_UNSUPPORTED,"writing is not supported on this platform");
    return -1;
#endif
#endif
    return err;
}
开发者ID:superpig0501,项目名称:libtrace,代码行数:30,代码来源:format_pcap.c

示例2: authenticate

/* Authenticate ourselves with the AP */
void authenticate()
{
    const void *radio_tap = NULL, *dot11_frame = NULL, *management_frame = NULL, *packet = NULL;
    size_t radio_tap_len = 0, dot11_frame_len = 0, management_frame_len = 0, packet_len = 0;

    radio_tap = build_radio_tap_header(&radio_tap_len);
    dot11_frame = build_dot11_frame_header(FC_AUTHENTICATE, &dot11_frame_len);
    management_frame = build_authentication_management_frame(&management_frame_len);
    packet_len = radio_tap_len + dot11_frame_len + management_frame_len;

    if(radio_tap && dot11_frame && management_frame)
    {
        packet = malloc(packet_len);
        if(packet)
        {
            memset((void *) packet, 0, packet_len);

            memcpy((void *) packet, radio_tap, radio_tap_len);
            memcpy((void *) ((char *) packet+radio_tap_len), dot11_frame, dot11_frame_len);
            memcpy((void *) ((char *) packet+radio_tap_len+dot11_frame_len), management_frame, management_frame_len);

            pcap_inject(get_handle(), packet, packet_len);

            free((void *) packet);
        }
    }

    if(radio_tap) free((void *) radio_tap);
    if(dot11_frame) free((void *) dot11_frame);
    if(management_frame) free((void *) management_frame);

    return;
}
开发者ID:Egyptghost1,项目名称:reaver-wps-fork-t6x,代码行数:34,代码来源:80211.c

示例3: packet_socket_writev

int packet_socket_writev(struct packet_socket *psock,
			 const struct iovec *iov, int iovcnt)
{
	/* Copy the ethernet header and IP datagram into a single buffer,
	 * since that's all the pcap API supports. TODO: optimize this.
	 */

	u8 *buf = NULL, *p = NULL;
	int len = 0, i = 0;

	/* Calculate how much space we need. */
	for (i = 0; i < iovcnt; ++i)
		len += iov[i].iov_len;

	buf = malloc(len);

	/* Copy into the linear buffer. */
	p = buf;
	for (i = 0; i < iovcnt; ++i) {
		memcpy(p, iov[i].iov_base, iov[i].iov_len);
		p += iov[i].iov_len;
	}

	DEBUGP("calling pcap_inject with %d bytes\n", len);

	if (pcap_inject(psock->pcap_out, buf, len) != len)
		die_pcap_perror(psock->pcap_out, "pcap_inject");

	free(buf);
	return STATUS_OK;
}
开发者ID:BillTheBest,项目名称:packetdrill,代码行数:31,代码来源:packet_socket_pcap.c

示例4: process_packet

void process_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet) {

	int size = (int) header->len;
	int seq = -1;
	int i;
	int ret;
	if (verify_packet_chk((u_char*)packet, size, ROUTE_ON_RELIABLE) == 0) {
		struct rlhdr* rlh = (struct rlhdr*)(packet + ETH_HLEN + sizeof(struct rthdr));
		seq = ntohs(rlh->seq);
		fprintf(stdout, "Received sequence %d\n", seq);
		checkArray[seq] = 1;
		for (i = 0; i < TEST_SEQ_CNT; i++) {
			if (checkArray[i] != 1) {
				return;
			}
		}
		printf("ALL test segments received.\n");
		int pktlen = generate_openflow_test_packet(packetOut, 128, 9999, source, dest);
		if ((ret = pcap_inject(handle_sniffed, packetOut, pktlen)) < 0){
			fprintf(stderr, "Fail to inject packet\n");
			// exit(1);
		}
		exit(1);
	}
	//print_data(stdout, (u_char*)packet, size);
}
开发者ID:zhan849,项目名称:cs558,代码行数:26,代码来源:pcap_receiver.c

示例5: forward_from_hijacker

/**
 * Forward data from hijacker
 *
 */
static ssize_t forward_from_hijacker ( struct hijack *hijack, int fd ) {
    char buf[SNAPLEN];
    ssize_t len;

    /* Read packet from hijacker */
    len = read ( fd, buf, sizeof ( buf ) );
    if ( len < 0 ) {
        logmsg ( LOG_ERR, "read from hijacker failed: %s\n",
                 strerror ( errno ) );
        return -1;
    }
    if ( len == 0 )
        return 0;

    /* Set up filter if not already in place */
    if ( ! hijack->filtered ) {
        if ( hijack_filter ( hijack, buf, len ) == 0 )
            hijack->filtered = 1;
    }

    /* Transmit packet to network */
    if ( pcap_inject ( hijack->pcap, buf, len ) != len ) {
        logmsg ( LOG_ERR, "write to hijacked port failed: %s\n",
                 pcap_geterr ( hijack->pcap ) );
        return -1;
    }

    hijack->tx_count++;
    return len;
};
开发者ID:B-Rich,项目名称:serialice,代码行数:34,代码来源:hijack.c

示例6: captop_handler

    void
    captop_handler(u_char *user, const struct pcap_pkthdr *h, const u_char *payload)
    {
        auto that = reinterpret_cast<capthread *>(user);

        if (unlikely(global::stop.load(std::memory_order_relaxed)))
            return;

        if (likely(that != nullptr))
        {
            if (that->in)
            {
                that->atomic_stat.in_count.fetch_add(1, std::memory_order_relaxed);
                that->atomic_stat.in_band.fetch_add(h->len, std::memory_order_relaxed);
            }

            if (that->out)
            {
                int ret = pcap_inject(that->out, payload, h->caplen);
                if (ret != -1)
                {
                    that->atomic_stat.out_count.fetch_add(1, std::memory_order_relaxed);
                    that->atomic_stat.out_band.fetch_add(h->len, std::memory_order_relaxed);
                }
                else {
                    that->atomic_stat.fail.fetch_add(1, std::memory_order_relaxed);
                }
            }

            if (unlikely(that->dumper != nullptr))
                pcap_dump(reinterpret_cast<u_char *>(that->dumper), h, payload);
        }
    }
开发者ID:awgn,项目名称:captop,代码行数:33,代码来源:handler.cpp

示例7: deauthenticate

/* Deauthenticate ourselves from the AP */
void deauthenticate()
{
    const void *radio_tap = NULL, *dot11_frame = NULL, *packet = NULL;
    size_t radio_tap_len = 0, dot11_frame_len = 0, packet_len = 0;

    radio_tap = build_radio_tap_header(&radio_tap_len);
    dot11_frame = build_dot11_frame_header(FC_DEAUTHENTICATE, &dot11_frame_len);
    packet_len = radio_tap_len + dot11_frame_len + DEAUTH_REASON_CODE_SIZE;

    if(radio_tap && dot11_frame)
    {
        packet = malloc(packet_len);
        if(packet)
        {
            memset((void *) packet, 0, packet_len);

            memcpy((void *) packet, radio_tap, radio_tap_len);
            memcpy((void *) ((char *) packet+radio_tap_len), dot11_frame, dot11_frame_len);
            memcpy((void *) ((char *) packet+radio_tap_len+dot11_frame_len), DEAUTH_REASON_CODE, DEAUTH_REASON_CODE_SIZE);

            pcap_inject(get_handle(), packet, packet_len);

            free((void *) packet);
        }
    }

    if(radio_tap) free((void *) radio_tap);
    if(dot11_frame) free((void *) dot11_frame);

    return;
}
开发者ID:Egyptghost1,项目名称:reaver-wps-fork-t6x,代码行数:32,代码来源:80211.c

示例8: tunemu_write

int tunemu_write(int ppp_sockfd, char *buffer, int length)
{
    allocate_data_buffer(length + 4);

    data_buffer[0] = 0x02;
    data_buffer[1] = 0x00;
    data_buffer[2] = 0x00;
    data_buffer[3] = 0x00;

    memcpy(data_buffer + 4, buffer, length);

    if (pcap == NULL)
    {
        tun_error("pcap not open");
        return -1;
    }

    length = pcap_inject(pcap, data_buffer, length + 4);
    if (length < 0)
    {
        tun_error("injecting packet: %s", pcap_geterr(pcap));
        return length;
    }
    tun_noerror();

    length -= 4;
    if (length < 0)
        return 0;

    return length;
}
开发者ID:HannesHofer,项目名称:hans,代码行数:31,代码来源:tunemu.c

示例9: wifi_inject

int wifi_inject(char *frameToSend,int frameLength)
{
	static int count =1 ;

	PRINT_DEBUG("wifi_inject has been called");
	// Add the mac header then send it
		unsigned char *frame;
		frame =   (unsigned char *)malloc(frameLength + SIZE_ETHERNET); //todo:check if this cannot be allocated once to 1500B


		// src = 00:1c:bf:87:1a:fd
		//dest Alex = 0x00,0x1c,0xbf,0x86,0xd2,0xda

		char dest[]={0x00,0x1c,0xbf,0x87,0x1a,0xfd};
		char src[]={0x00,0x1c,0xbf,0x87,0x1a,0xfd};
		memcpy(((struct sniff_ethernet *)frame)->ether_dhost,dest,ETHER_ADDR_LEN);
		memcpy(((struct sniff_ethernet *)frame)->ether_shost,src,ETHER_ADDR_LEN);
		((struct sniff_ethernet *)frame)->ether_type=htons(0x0800);
		memcpy(frame+SIZE_ETHERNET,frameToSend,frameLength);





		if (pcap_inject ( inject_handle, frame,frameLength + SIZE_ETHERNET) == -1)
			PRINT_DEBUG("Failed to inject the packet");
		PRINT_DEBUG("\n Message #%d has been injected",count);
		count++;
		//free(frameToSend);
		return(1);

}
开发者ID:TrainingProject,项目名称:FINS-Framework,代码行数:32,代码来源:wifimod.c

示例10: pcap_send

int pcap_send(struct pcap_conn *conn, char *buf, int size)
{
	int ret;
	if (!conn || !conn->desc || !buf || size <= 0)
		return -EINVAL;
	ret = pcap_inject(conn->desc, buf, size);
	return ret;
}
开发者ID:guolinp,项目名称:euler,代码行数:8,代码来源:pcap_comm.c

示例11: memset

bool MF_Segmentor::sendAck(MF_ChunkInfo *ci, MF_DeviceInfo *di) {
	MF_Log::mf_log(MF_DEBUG, "MF_Segmentor:sendAck send ack packet for given chunk");
	u_char buffer[65536];// large enough for any size of bitmap
	memset((void *) buffer, 0xff, 65536);
	struct hop_data *hop;
	unsigned int pktCount = ci->getChunkPktCnt();
	struct csyn_ack *ack;
	ack = (struct csyn_ack *) MF_PacketSupport::getHopHeaderPtr(buffer);
	ack->type = htonl(CSYN_ACK_PKT);
	ack->hop_ID = htonl((unsigned int) (ci->getHopID()));
	ack->chk_pkt_count = htonl(pktCount);

	unsigned int i = 0;
	unsigned int j = 0;
	int ret;

	if (ci->isDelivered()) {// last ack get lost
		for (i = 0; i < (pktCount - 1) / 8 + 1; i++) {
			ack->bitmap[i] = 0xff;
		}
	} else {
		vector <u_char *> *pList = ci->getPacketList();
		for (i = 0; i < pktCount; i++) {
			hop = (struct hop_data *) MF_PacketSupport::getHopHeaderPtr((*pList)[i]);
			if (hop->pld_size == 0) { //did not get the packet yet
				*(ack->bitmap + (i / 8)) &= (0xfe << (i % 8));
				j++;
			}
		}
	}
	unsigned int z;
	//TODO remove the harcoded value
	char tempBitmap[512];
	for (z = 0; (z < (pktCount - 1) / 8 + 1) && z<512; z++) {
		sprintf(tempBitmap + z, "%x",ack->bitmap[z]);
	}
	MF_Log::mf_log(MF_DEBUG, "MF_Segmentor:sendAck sent bitmap: %s", tempBitmap);

	MF_IPProto::fillHeader(buffer, ETH_HEADER_SIZE, CSYN_SIZE + ((pktCount - 1) / 8 + 1), di->getSIP().c_str(), di->getAPIP().c_str());
	MF_EtherProto::fillHeader(buffer, 0, di->getSMAC().c_str(), di->getAPMAC().c_str());

	if ((ret = pcap_inject(mPcapHandle, (void *) buffer, ETH_HEADER_SIZE + IP_HEADER_SIZE + CSYN_SIZE + ((pktCount - 1) / 8 + 1))) < 0) {
		MF_Log::mf_log(MF_ERROR, "MF_Segmentor:sendAck pcap_inject() error, errno=%d", errno);
		return false;
	}
	MF_Log::mf_log(MF_DEBUG, "MF_Segmentor:sendAck Sent CSYN-ACK hop_ID=%d, recvd/lost/total %d/%d/%d if = %s", ntohl(ack->hop_ID), pktCount-j, j, pktCount, di->getName().c_str());

	//OML
#ifdef __OML__
	di->increaseOutBytesByInt(ETH_HEADER_SIZE + IP_HEADER_SIZE + CSYN_SIZE + ((pktCount - 1) / 8 + 1));
	di->increaseOutPackets();
#endif

	if (j == 0) { //get all the packets
		return true;
	}
	return false;
}
开发者ID:crockct,项目名称:GNRS-DOS,代码行数:58,代码来源:mfsegmentor.cpp

示例12: l2_packet_send

int l2_packet_send(struct l2_packet_data *l2, const u8 *dst_addr, u16 proto,
		   const u8 *buf, size_t len)
{
	if (!l2->l2_hdr) {
		int ret;
		struct l2_ethhdr *eth = os_malloc(sizeof(*eth) + len);
		if (eth == NULL)
			return -1;
		os_memcpy(eth->h_dest, dst_addr, ETH_ALEN);
		os_memcpy(eth->h_source, l2->own_addr, ETH_ALEN);
		eth->h_proto = htons(proto);
		os_memcpy(eth + 1, buf, len);
		ret = pcap_inject(l2->pcap, (u8 *) eth, len + sizeof(*eth));
		os_free(eth);
		return ret;
	} else
		return pcap_inject(l2->pcap, buf, len);
}
开发者ID:kusumi,项目名称:DragonFlyBSD,代码行数:18,代码来源:l2_packet.c

示例13: packetrelay

int packetrelay(pcap_t *pcd, char *dev, u_char *packet, u_char *g_ip, u_char *t_ip, u_char *s_mac, u_char *t_mac, u_char *g_mac){
    struct ether_header *etheh;
    struct ip *iph;
    u_char tip[IPSIZE], sip[IPSIZE];
    u_char *cp = packet;
    etheh = (struct ether_header *)cp;
    if(etheh == NULL)
        return 0;
    cp += sizeof(struct ether_header);
    if(etheh->ether_type == ntohs(ETHERTYPE_IP)){
        iph = (struct ip*)cp;

        inet_ntop(AF_INET, &iph->ip_dst, tip, sizeof(tip));
        inet_ntop(AF_INET, &iph->ip_src, sip, sizeof(sip));
        if(!strcmp(sip, t_ip)){
            memcpy(etheh->ether_dhost, g_mac, MACASIZE);
            memcpy(etheh->ether_shost, s_mac, MACASIZE);
            pcap_inject(pcd, packet, sizeof(struct ether_header) + ntohs(iph->ip_len));
        }
        else if(!strcmp(tip, t_ip) && !memcmp(etheh->ether_shost, g_mac, MACASIZE)){
            memcpy(etheh->ether_shost, s_mac, MACASIZE);
            memcpy(etheh->ether_dhost, t_mac, MACASIZE);
            pcap_inject(pcd, packet, sizeof(struct ether_header) + ntohs(iph->ip_len));
        }
    }
    else if (etheh->ether_type == ntohs(ETHERTYPE_ARP)){
        struct ether_arp *arph;
        cp = (struct ether_arp*)cp;
        inet_ntop(AF_INET, &arph->arp_tpa, tip, sizeof(tip));
        inet_ntop(AF_INET, &arph->arp_spa, sip, sizeof(sip));
        if((!strcmp(sip, t_ip) && !strcmp(tip, g_ip)) || (!strcmp(sip, g_ip) && !strcmp(tip, t_ip))){
            if((sendarprep(pcd ,dev, packet, g_ip, s_mac, t_ip, t_mac)) ==-1) {
                pcap_perror(pcd,0);
                pcap_close(pcd);
                exit(1);
            };
            if((sendarprep(pcd, dev, packet, t_ip, s_mac, g_ip, g_mac)) ==-1) {
                pcap_perror(pcd,0);
                pcap_close(pcd);
                exit(1);
            };
        }
    }
}
开发者ID:Ri0S,项目名称:arp_poison,代码行数:44,代码来源:packetcntl.c

示例14: dt_simulate_send

int dt_simulate_send(pcap_t *p, const void *buf, size_t size) {
  int bytesSend;

  /* send packet */
  bytesSend = pcap_inject(p, buf, size);
  if (bytesSend != size) {
    fprintf(stderr, "WARNING: pcap_inject\n");
  }
  return bytesSend;
}
开发者ID:federicomariti,项目名称:deviceTester,代码行数:10,代码来源:deviceTester_impl.c

示例15: inject_command

void inject_command(pcap_t *fp, gcry_cipher_hd_t * hd,char * dst_mac, char * command, int len, unsigned long * seqnum){
        char pkt[1000];
        u_char buf[1024];
        u_char iv[GCRY_IVLEN]={0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11};
        len+=SEQ_LEN;
        char pkt_len[6];


        char type[] =  {    0x00,0x00,0x0d,0x00,0x04,0x80,0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,
			    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x64,0x00,0x11,0x00,0x00,0x05,
		             'I', 'N', 'T', 'C', 'P',0x01,0x04,0x82,0x84,0x8b,0x96,0x03,0x01,0x0c,0x04,0x06,0x01,0x02,0x00,0x00,0x00,0x00,0x05,0x04,0x00,0x01,0x00,0x00,0xdd,0x18,0x00,0x50,0xf2,0x01,0x01,
			    0x00,0x00,0x50,0xf2,0x04,0x01,0x00,0x00,0x50,0xf2,0x04,0x01,0x00,0x00,0x50,0xf2,0x02,0x00,0x00}; 



        u_int tlen=len+MAC_LEN+CHECKSUM_LEN+GCRY_IVLEN;
        random_vector(iv,GCRY_IVLEN);
        memcpy(&pkt[0],dst_mac,MAC_LEN);
        memcpy(&pkt[MAC_LEN],iv,GCRY_IVLEN);
        gcry_cipher_setiv(*hd,iv, GCRY_IVLEN);


        char cmdseq[1000];
        memcpy(cmdseq,command,len);
        u_int ac=0;
        (*seqnum)++;
        if(*seqnum>0xFFFFFFFF){*seqnum=0x01;}
        for(ac=0;ac<SEQ_LEN;ac++){
                cmdseq[len-1-ac]=(char)((*seqnum)>>(ac*8));
        }

        gcry_cipher_encrypt(*hd, &pkt[GCRY_IVLEN+MAC_LEN],len , cmdseq, len);

        u_int chk=checksum(pkt,tlen);
        u_char chkarr[CHECKSUM_LEN];
        chkarr[0]=(chk>>8);
        chkarr[1]=chk&0x00FF;

        memcpy(&pkt[GCRY_IVLEN+MAC_LEN+len], chkarr,CHECKSUM_LEN);
        memcpy(buf, type, sizeof(type));
        memcpy(buf+sizeof(type), pkt, tlen);

	#ifndef MANDO_ABORDO
        print_vector(pkt,tlen);
        #endif

        for(ac=0;ac<BEACONS_PER_REQUEST;ac++){
	    int inj=pcap_inject(fp,buf, sizeof(type)+sizeof(pkt_len)+tlen);
	    #ifndef MANDO_ABORDO
		printf("\r\n INJ %i",inj);
	    #endif	
            
        }
        
}
开发者ID:RootedWarfare,项目名称:Atropos-Flight-Control,代码行数:55,代码来源:udp_emisora.c


注:本文中的pcap_inject函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。