ClientCollectors/ARODataCollector/external/libpcap-1.1.1/pcap-linux.c
static int
pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata)
{
	
	captureMode = CAP_LINUX_STANDARD;
	
	u_char			*bp;
	int			offset;
#ifdef HAVE_PF_PACKET_SOCKETS
	struct sockaddr_ll	from;
	struct sll_header	*hdrp;
#else
	struct sockaddr		from;
#endif
#if defined(HAVE_PACKET_AUXDATA) && defined(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI)
	struct iovec		iov;
	struct msghdr		msg;
	struct cmsghdr		*cmsg;
	union {
		struct cmsghdr	cmsg;
		char		buf[CMSG_SPACE(sizeof(struct tpacket_auxdata))];
	} cmsg_buf;
#else /* defined(HAVE_PACKET_AUXDATA) && defined(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI) */
	socklen_t		fromlen;
#endif /* defined(HAVE_PACKET_AUXDATA) && defined(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI) */
	int			packet_len, caplen;
	struct pcap_pkthdr	pcap_header;
	
	/************************ CODE CHANGED **************************/
	int dir, bCooked;
	/*	
	fd_set rfds;
	struct timeval tv;
	int retval;	
	FD_ZERO(&rfds);	
	tv.tv_sec = 1;
	tv.tv_usec = 500000;
	static int bPrevPacket = 0;
	*/
	/************************ CODE CHANGED **************************/
	

#ifdef HAVE_PF_PACKET_SOCKETS
	/*
	 * If this is a cooked device, leave extra room for a
	 * fake packet header.
	 */
	if (handle->md.cooked)
		offset = SLL_HDR_LEN;
	else
		offset = 0;
#else
	/*
	 * This system doesn't have PF_PACKET sockets, so it doesn't
	 * support cooked devices.
	 */
	offset = 0;
#endif

	bp = handle->buffer + handle->offset;

#if defined(HAVE_PACKET_AUXDATA) && defined(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI)
	msg.msg_name		= &from;
	msg.msg_namelen		= sizeof(from);
	msg.msg_iov		= &iov;
	msg.msg_iovlen		= 1;
	msg.msg_control		= &cmsg_buf;
	msg.msg_controllen	= sizeof(cmsg_buf);
	msg.msg_flags		= 0;

	iov.iov_len		= handle->bufsize - offset;
	iov.iov_base		= bp + offset;
#endif /* defined(HAVE_PACKET_AUXDATA) && defined(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI) */

	do {
			
		/************************ CODE CHANGED **************************/
		if (exitFlag == 3) {
		//if (handle->break_loop) {
			handle->break_loop = 0;
			return PCAP_ERROR_BREAK;
		}
		/************************ CODE CHANGED **************************/


#if defined(HAVE_PACKET_AUXDATA) && defined(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI)
		packet_len = recvmsg(handle->fd, &msg, MSG_TRUNC);
#else /* defined(HAVE_PACKET_AUXDATA) && defined(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI) */
		fromlen = sizeof(from);
		
		/************************ CODE CHANGED **************************/
		/*
		FD_SET(handle->fd, &rfds);
		retval = select(handle->fd + 1, &rfds, NULL, NULL, &tv);				
		if (retval == 0) {
			if (bPrevPacket) {
				printf("Timeout...\n");
			}
			
			bPrevPacket = 0;
			return 0;
		} else if (retval == -1) {
			printf("Error: Select() fails\n");		
			return PCAP_ERROR;
		}	else {
			bPrevPacket = 1;
			printf("* Packet *\n");
		}	
		*/			
		/************************ CODE CHANGED **************************/
		
		packet_len = recvfrom(
			handle->fd, bp + offset,
			handle->bufsize - offset, MSG_TRUNC,
			(struct sockaddr *) &from, &fromlen);
#endif /* defined(HAVE_PACKET_AUXDATA) && defined(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI) */
	} while (packet_len == -1 && errno == EINTR);

	/* Check if an error occured */

	if (packet_len == -1) {
		switch (errno) {

		case EAGAIN:
			return 0;	/* no packet there */

		case ENETDOWN:
			/*
			 * The device on which we're capturing went away.
			 *
			 * XXX - we should really return
			 * PCAP_ERROR_IFACE_NOT_UP, but pcap_dispatch()
			 * etc. aren't defined to return that.
			 */
			snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
				"The interface went down");
			return PCAP_ERROR;

		default:
			snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
				 "recvfrom: %s", pcap_strerror(errno));
			return PCAP_ERROR;
		}
	}

#ifdef HAVE_PF_PACKET_SOCKETS
	dir = 0;
	if (!handle->md.sock_packet) {
		/*
		 * Unfortunately, there is a window between socket() and
		 * bind() where the kernel may queue packets from any
		 * interface.  If we're bound to a particular interface,
		 * discard packets not from that interface.
		 *
		 * (If socket filters are supported, we could do the
		 * same thing we do when changing the filter; however,
		 * that won't handle packet sockets without socket
		 * filter support, and it's a bit more complicated.
		 * It would save some instructions per packet, however.)
		 */
		if (handle->md.ifindex != -1 &&
		    from.sll_ifindex != handle->md.ifindex)
			return 0;

		/*
		 * Do checks based on packet direction.
		 * We can only do this if we're using PF_PACKET; the
		 * address returned for SOCK_PACKET is a "sockaddr_pkt"
		 * which lacks the relevant packet type information.
		 */
		if (from.sll_pkttype == PACKET_OUTGOING) {
			/*
			 * Outgoing packet.
			 * If this is from the loopback device, reject it;
			 * we'll see the packet as an incoming packet as well,
			 * and we don't want to see it twice.
			 */
			if (from.sll_ifindex == handle->md.lo_ifindex)
				return 0;

			/*
			 * If the user only wants incoming packets, reject it.
			 */
			if (handle->direction == PCAP_D_IN)
				return 0;
				
			//printf("Outgoing (UL) packet\n");	
			dir = 1;
			
		} else {
			/*
			 * Incoming packet.
			 * If the user only wants outgoing packets, reject it.
			 */
			if (handle->direction == PCAP_D_OUT)
				return 0;
				
			//printf("Incoming (DL) packet\n");
			dir = 2;
		}
	}
#endif

	bCooked = 0;

#ifdef HAVE_PF_PACKET_SOCKETS
	/*
	 * If this is a cooked device, fill in the fake packet header.
	 */
	if (handle->md.cooked) {
		/*
		 * Add the length of the fake header to the length
		 * of packet data we read.
		 */
		packet_len += SLL_HDR_LEN;

		hdrp = (struct sll_header *)bp;
		hdrp->sll_pkttype = map_packet_type_to_sll_type(from.sll_pkttype);
		hdrp->sll_hatype = htons(from.sll_hatype);
		hdrp->sll_halen = htons(from.sll_halen);
		memcpy(hdrp->sll_addr, from.sll_addr,
		    (from.sll_halen > SLL_ADDRLEN) ?
		      SLL_ADDRLEN :
		      from.sll_halen);
		hdrp->sll_protocol = from.sll_protocol;
		
		bCooked = 1;		
	}

#if defined(HAVE_PACKET_AUXDATA) && defined(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI)
	for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
		struct tpacket_auxdata *aux;
		unsigned int len;
		struct vlan_tag *tag;

		if (cmsg->cmsg_len < CMSG_LEN(sizeof(struct tpacket_auxdata)) ||
		    cmsg->cmsg_level != SOL_PACKET ||
		    cmsg->cmsg_type != PACKET_AUXDATA)
			continue;

		aux = (struct tpacket_auxdata *)CMSG_DATA(cmsg);
		if (aux->tp_vlan_tci == 0)
			continue;

		len = packet_len > iov.iov_len ? iov.iov_len : packet_len;
		if (len < 2 * ETH_ALEN)
			break;

		bp -= VLAN_TAG_LEN;
		memmove(bp, bp + VLAN_TAG_LEN, 2 * ETH_ALEN);

		tag = (struct vlan_tag *)(bp + 2 * ETH_ALEN);
		tag->vlan_tpid = htons(ETH_P_8021Q);
		tag->vlan_tci = htons(aux->tp_vlan_tci);

		packet_len += VLAN_TAG_LEN;
	}
#endif /* defined(HAVE_PACKET_AUXDATA) && defined(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI) */
#endif /* HAVE_PF_PACKET_SOCKETS */

	caplen = packet_len;
	if (caplen > handle->snapshot)
		caplen = handle->snapshot;

	/* Run the packet filter if not using kernel filter */
	/************************ CODE CHANGED **************************/
	/*
	if (!handle->md.use_bpf && handle->fcode.bf_insns) {
		if (bpf_filter(handle->fcode.bf_insns, bp,
		                packet_len, caplen) == 0)
		{			
			return 0; //rejected by filter
		}
	}
	*/
	/************************ CODE CHANGED **************************/

	/* Fill in our own header data */

	if (ioctl(handle->fd, SIOCGSTAMP, &pcap_header.ts) == -1) {
		snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
			 "SIOCGSTAMP: %s", pcap_strerror(errno));
		return PCAP_ERROR;
	}
	pcap_header.caplen	= caplen;
	pcap_header.len		= packet_len;

	/*
	 * Count the packet.
	 */
	handle->md.packets_read++;
	
	/************************ CODE CHANGED **************************/
	int appid = UpdatePacket(&pcap_header.ts, bp,currentdevice,dir, bCooked);
	fprintf(ofsAppID, "%d\n", appid);

	/* Call the user supplied callback function */
	callback(userdata, &pcap_header, bp);	
	/************************ CODE CHANGED **************************/

	return 1;
}
/*
 *  Read a packet from the socket calling the handler provided by
 *  the user. Returns the number of packets received or -1 if an
 *  error occured.
 */
Read a packet from the socket calling the handler provided by
the user. Returns the number of packets received or -1 if an
error occured.
Read a packet from the socket calling the handler provided by the user . Returns the number of packets received or - 1 if an error occured .
static int
pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata)
{
	captureMode = CAP_LINUX_STANDARD;
	u_char			*bp;
	int			offset;
#ifdef HAVE_PF_PACKET_SOCKETS
	struct sockaddr_ll	from;
	struct sll_header	*hdrp;
#else
	struct sockaddr		from;
#endif
#if defined(HAVE_PACKET_AUXDATA) && defined(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI)
	struct iovec		iov;
	struct msghdr		msg;
	struct cmsghdr		*cmsg;
	union {
		struct cmsghdr	cmsg;
		char		buf[CMSG_SPACE(sizeof(struct tpacket_auxdata))];
	} cmsg_buf;
#else 
	socklen_t		fromlen;
#endif 
	int			packet_len, caplen;
	struct pcap_pkthdr	pcap_header;
	int dir, bCooked;
#ifdef HAVE_PF_PACKET_SOCKETS
	if (handle->md.cooked)
		offset = SLL_HDR_LEN;
	else
		offset = 0;
#else
	offset = 0;
#endif
	bp = handle->buffer + handle->offset;
#if defined(HAVE_PACKET_AUXDATA) && defined(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI)
	msg.msg_name		= &from;
	msg.msg_namelen		= sizeof(from);
	msg.msg_iov		= &iov;
	msg.msg_iovlen		= 1;
	msg.msg_control		= &cmsg_buf;
	msg.msg_controllen	= sizeof(cmsg_buf);
	msg.msg_flags		= 0;
	iov.iov_len		= handle->bufsize - offset;
	iov.iov_base		= bp + offset;
#endif 
	do {
		if (exitFlag == 3) {
			handle->break_loop = 0;
			return PCAP_ERROR_BREAK;
		}
#if defined(HAVE_PACKET_AUXDATA) && defined(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI)
		packet_len = recvmsg(handle->fd, &msg, MSG_TRUNC);
#else 
		fromlen = sizeof(from);
		packet_len = recvfrom(
			handle->fd, bp + offset,
			handle->bufsize - offset, MSG_TRUNC,
			(struct sockaddr *) &from, &fromlen);
#endif 
	} while (packet_len == -1 && errno == EINTR);
	if (packet_len == -1) {
		switch (errno) {
		case EAGAIN:
			return 0;	
		case ENETDOWN:
			snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
				"The interface went down");
			return PCAP_ERROR;
		default:
			snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
				 "recvfrom: %s", pcap_strerror(errno));
			return PCAP_ERROR;
		}
	}
#ifdef HAVE_PF_PACKET_SOCKETS
	dir = 0;
	if (!handle->md.sock_packet) {
		if (handle->md.ifindex != -1 &&
		    from.sll_ifindex != handle->md.ifindex)
			return 0;
		if (from.sll_pkttype == PACKET_OUTGOING) {
			if (from.sll_ifindex == handle->md.lo_ifindex)
				return 0;
			if (handle->direction == PCAP_D_IN)
				return 0;
			dir = 1;
		} else {
			if (handle->direction == PCAP_D_OUT)
				return 0;
			dir = 2;
		}
	}
#endif
	bCooked = 0;
#ifdef HAVE_PF_PACKET_SOCKETS
	if (handle->md.cooked) {
		packet_len += SLL_HDR_LEN;
		hdrp = (struct sll_header *)bp;
		hdrp->sll_pkttype = map_packet_type_to_sll_type(from.sll_pkttype);
		hdrp->sll_hatype = htons(from.sll_hatype);
		hdrp->sll_halen = htons(from.sll_halen);
		memcpy(hdrp->sll_addr, from.sll_addr,
		    (from.sll_halen > SLL_ADDRLEN) ?
		      SLL_ADDRLEN :
		      from.sll_halen);
		hdrp->sll_protocol = from.sll_protocol;
		bCooked = 1;		
	}
#if defined(HAVE_PACKET_AUXDATA) && defined(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI)
	for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
		struct tpacket_auxdata *aux;
		unsigned int len;
		struct vlan_tag *tag;
		if (cmsg->cmsg_len < CMSG_LEN(sizeof(struct tpacket_auxdata)) ||
		    cmsg->cmsg_level != SOL_PACKET ||
		    cmsg->cmsg_type != PACKET_AUXDATA)
			continue;
		aux = (struct tpacket_auxdata *)CMSG_DATA(cmsg);
		if (aux->tp_vlan_tci == 0)
			continue;
		len = packet_len > iov.iov_len ? iov.iov_len : packet_len;
		if (len < 2 * ETH_ALEN)
			break;
		bp -= VLAN_TAG_LEN;
		memmove(bp, bp + VLAN_TAG_LEN, 2 * ETH_ALEN);
		tag = (struct vlan_tag *)(bp + 2 * ETH_ALEN);
		tag->vlan_tpid = htons(ETH_P_8021Q);
		tag->vlan_tci = htons(aux->tp_vlan_tci);
		packet_len += VLAN_TAG_LEN;
	}
#endif 
#endif 
	caplen = packet_len;
	if (caplen > handle->snapshot)
		caplen = handle->snapshot;
	if (ioctl(handle->fd, SIOCGSTAMP, &pcap_header.ts) == -1) {
		snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
			 "SIOCGSTAMP: %s", pcap_strerror(errno));
		return PCAP_ERROR;
	}
	pcap_header.caplen	= caplen;
	pcap_header.len		= packet_len;
	handle->md.packets_read++;
	int appid = UpdatePacket(&pcap_header.ts, bp,currentdevice,dir, bCooked);
	fprintf(ofsAppID, "%d\n", appid);
	callback(userdata, &pcap_header, bp);	
	return 1;
}
static int pcap_read_packet ( pcap_t * handle , pcap_handler callback , u_char * userdata ) { captureMode = CAP_LINUX_STANDARD ; u_char * bp ; int offset ; #ifdef HAVE_PF_PACKET_SOCKETS struct sockaddr_ll from ; struct sll_header * hdrp ; #else struct sockaddr from ; #endif #if defined ( HAVE_PACKET_AUXDATA ) && defined ( HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI ) struct iovec iov ; struct msghdr msg ; struct cmsghdr * cmsg ; union { struct cmsghdr cmsg ; char buf [ CMSG_SPACE ( sizeof ( struct tpacket_auxdata ) ) ] ; } cmsg_buf ; #else socklen_t fromlen ; #endif int packet_len , caplen ; struct pcap_pkthdr pcap_header ; int dir , bCooked ; #ifdef HAVE_PF_PACKET_SOCKETS if ( handle -> md . cooked ) offset = SLL_HDR_LEN ; else offset = 0 ; #else offset = 0 ; #endif bp = handle -> buffer + handle -> offset ; #if defined ( HAVE_PACKET_AUXDATA ) && defined ( HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI ) msg . msg_name = & from ; msg . msg_namelen = sizeof ( from ) ; msg . msg_iov = & iov ; msg . msg_iovlen = 1 ; msg . msg_control = & cmsg_buf ; msg . msg_controllen = sizeof ( cmsg_buf ) ; msg . msg_flags = 0 ; iov . iov_len = handle -> bufsize - offset ; iov . iov_base = bp + offset ; #endif do { if ( exitFlag == 3 ) { handle -> break_loop = 0 ; return PCAP_ERROR_BREAK ; } #if defined ( HAVE_PACKET_AUXDATA ) && defined ( HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI ) packet_len = recvmsg ( handle -> fd , & msg , MSG_TRUNC ) ; #else fromlen = sizeof ( from ) ; packet_len = recvfrom ( handle -> fd , bp + offset , handle -> bufsize - offset , MSG_TRUNC , ( struct sockaddr * ) & from , & fromlen ) ; #endif } while ( packet_len == -1 && errno == EINTR ) ; if ( packet_len == -1 ) { switch ( errno ) { case EAGAIN : return 0 ; case ENETDOWN : snprintf ( handle -> errbuf , PCAP_ERRBUF_SIZE , " " ) ; return PCAP_ERROR ; default : snprintf ( handle -> errbuf , PCAP_ERRBUF_SIZE , " " , pcap_strerror ( errno ) ) ; return PCAP_ERROR ; } } #ifdef HAVE_PF_PACKET_SOCKETS dir = 0 ; if ( ! handle -> md . sock_packet ) { if ( handle -> md . ifindex != -1 && from . sll_ifindex != handle -> md . ifindex ) return 0 ; if ( from . sll_pkttype == PACKET_OUTGOING ) { if ( from . sll_ifindex == handle -> md . lo_ifindex ) return 0 ; if ( handle -> direction == PCAP_D_IN ) return 0 ; dir = 1 ; } else { if ( handle -> direction == PCAP_D_OUT ) return 0 ; dir = 2 ; } } #endif bCooked = 0 ; #ifdef HAVE_PF_PACKET_SOCKETS if ( handle -> md . cooked ) { packet_len += SLL_HDR_LEN ; hdrp = ( struct sll_header * ) bp ; hdrp -> sll_pkttype = map_packet_type_to_sll_type ( from . sll_pkttype ) ; hdrp -> sll_hatype = htons ( from . sll_hatype ) ; hdrp -> sll_halen = htons ( from . sll_halen ) ; memcpy ( hdrp -> sll_addr , from . sll_addr , ( from . sll_halen > SLL_ADDRLEN ) ? SLL_ADDRLEN : from . sll_halen ) ; hdrp -> sll_protocol = from . sll_protocol ; bCooked = 1 ; } #if defined ( HAVE_PACKET_AUXDATA ) && defined ( HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI ) for ( cmsg = CMSG_FIRSTHDR ( & msg ) ; cmsg ; cmsg = CMSG_NXTHDR ( & msg , cmsg ) ) { struct tpacket_auxdata * aux ; unsigned int len ; struct vlan_tag * tag ; if ( cmsg -> cmsg_len < CMSG_LEN ( sizeof ( struct tpacket_auxdata ) ) || cmsg -> cmsg_level != SOL_PACKET || cmsg -> cmsg_type != PACKET_AUXDATA ) continue ; aux = ( struct tpacket_auxdata * ) CMSG_DATA ( cmsg ) ; if ( aux -> tp_vlan_tci == 0 ) continue ; len = packet_len > iov . iov_len ? iov . iov_len : packet_len ; if ( len < 2 * ETH_ALEN ) break ; bp -= VLAN_TAG_LEN ; memmove ( bp , bp + VLAN_TAG_LEN , 2 * ETH_ALEN ) ; tag = ( struct vlan_tag * ) ( bp + 2 * ETH_ALEN ) ; tag -> vlan_tpid = htons ( ETH_P_8021Q ) ; tag -> vlan_tci = htons ( aux -> tp_vlan_tci ) ; packet_len += VLAN_TAG_LEN ; } #endif #endif caplen = packet_len ; if ( caplen > handle -> snapshot ) caplen = handle -> snapshot ; if ( ioctl ( handle -> fd , SIOCGSTAMP , & pcap_header . ts ) == -1 ) { snprintf ( handle -> errbuf , PCAP_ERRBUF_SIZE , " " , pcap_strerror ( errno ) ) ; return PCAP_ERROR ; } pcap_header . caplen = caplen ; pcap_header . len = packet_len ; handle -> md . packets_read ++ ; int appid = UpdatePacket ( & pcap_header . ts , bp , currentdevice , dir , bCooked ) ; fprintf ( ofsAppID , " \n " , appid ) ; callback ( userdata , & pcap_header , bp ) ; return 1 ; }
Read a packet from the socket calling the handler provided by
  the user.
Read a packet from the socket calling the handler provided by the user .
/* defined(HAVE_PACKET_AUXDATA) && defined(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI) */ /* defined(HAVE_PACKET_AUXDATA) && defined(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI) */ /************************ CODE CHANGED **************************/ /*	
	fd_set rfds;
	struct timeval tv;
	int retval;	
	FD_ZERO(&rfds);	
	tv.tv_sec = 1;
	tv.tv_usec = 500000;
	static int bPrevPacket = 0;
	*/ /************************ CODE CHANGED **************************/ /*
	 * If this is a cooked device, leave extra room for a
	 * fake packet header.
	 */ /*
	 * This system doesn't have PF_PACKET sockets, so it doesn't
	 * support cooked devices.
	 */ /* defined(HAVE_PACKET_AUXDATA) && defined(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI) */ /************************ CODE CHANGED **************************/ //if (handle->break_loop) {
 /************************ CODE CHANGED **************************/ /* defined(HAVE_PACKET_AUXDATA) && defined(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI) */ /************************ CODE CHANGED **************************/ /*
		FD_SET(handle->fd, &rfds);
		retval = select(handle->fd + 1, &rfds, NULL, NULL, &tv);				
		if (retval == 0) {
			if (bPrevPacket) {
				printf("Timeout...\n");
			}
			
			bPrevPacket = 0;
			return 0;
		} else if (retval == -1) {
			printf("Error: Select() fails\n");		
			return PCAP_ERROR;
		}	else {
			bPrevPacket = 1;
			printf("* Packet *\n");
		}	
		*/ /************************ CODE CHANGED **************************/ /* defined(HAVE_PACKET_AUXDATA) && defined(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI) */ /* Check if an error occured */ /* no packet there */ /*
			 * The device on which we're capturing went away.
			 *
			 * XXX - we should really return
			 * PCAP_ERROR_IFACE_NOT_UP, but pcap_dispatch()
			 * etc. aren't defined to return that.
			 */ /*
		 * Unfortunately, there is a window between socket() and
		 * bind() where the kernel may queue packets from any
		 * interface.  If we're bound to a particular interface,
		 * discard packets not from that interface.
		 *
		 * (If socket filters are supported, we could do the
		 * same thing we do when changing the filter; however,
		 * that won't handle packet sockets without socket
		 * filter support, and it's a bit more complicated.
		 * It would save some instructions per packet, however.)
		 */ /*
		 * Do checks based on packet direction.
		 * We can only do this if we're using PF_PACKET; the
		 * address returned for SOCK_PACKET is a "sockaddr_pkt"
		 * which lacks the relevant packet type information.
		 */ /*
			 * Outgoing packet.
			 * If this is from the loopback device, reject it;
			 * we'll see the packet as an incoming packet as well,
			 * and we don't want to see it twice.
			 */ /*
			 * If the user only wants incoming packets, reject it.
			 */ //printf("Outgoing (UL) packet\n");	
 /*
			 * Incoming packet.
			 * If the user only wants outgoing packets, reject it.
			 */ //printf("Incoming (DL) packet\n");
 /*
	 * If this is a cooked device, fill in the fake packet header.
	 */ /*
		 * Add the length of the fake header to the length
		 * of packet data we read.
		 */ /* defined(HAVE_PACKET_AUXDATA) && defined(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI) */ /* HAVE_PF_PACKET_SOCKETS */ /* Run the packet filter if not using kernel filter */ /************************ CODE CHANGED **************************/ /*
	if (!handle->md.use_bpf && handle->fcode.bf_insns) {
		if (bpf_filter(handle->fcode.bf_insns, bp,
		                packet_len, caplen) == 0)
		{			
			return 0; //rejected by filter
		}
	}
	*/ /************************ CODE CHANGED **************************/ /* Fill in our own header data */ /*
	 * Count the packet.
	 */ /************************ CODE CHANGED **************************/ /* Call the user supplied callback function */ /************************ CODE CHANGED **************************/