ClientCollectors/ARODataCollector/external/libpcap-1.1.1/gencode.c
static struct slist *
gen_load_802_11_header_len(struct slist *s, struct slist *snext)
{
	struct slist *s2;
	struct slist *sjset_data_frame_1;
	struct slist *sjset_data_frame_2;
	struct slist *sjset_qos;
	struct slist *sjset_radiotap_flags;
	struct slist *sjset_radiotap_tsft;
	struct slist *sjset_tsft_datapad, *sjset_notsft_datapad;
	struct slist *s_roundup;

	if (reg_off_macpl == -1) {
		/*
		 * No register has been assigned to the offset of
		 * the MAC-layer payload, which means nobody needs
		 * it; don't bother computing it - just return
		 * what we already have.
		 */
		return (s);
	}

	/*
	 * This code is not compatible with the optimizer, as
	 * we are generating jmp instructions within a normal
	 * slist of instructions
	 */
	no_optimize = 1;
	
	/*
	 * If "s" is non-null, it has code to arrange that the X register
	 * contains the length of the prefix preceding the link-layer
	 * header.
	 *
	 * Otherwise, the length of the prefix preceding the link-layer
	 * header is "off_ll".
	 */
	if (s == NULL) {
		/*
		 * There is no variable-length header preceding the
		 * link-layer header.
		 *
		 * Load the length of the fixed-length prefix preceding
		 * the link-layer header (if any) into the X register,
		 * and store it in the reg_off_macpl register.
		 * That length is off_ll.
		 */
		s = new_stmt(BPF_LDX|BPF_IMM);
		s->s.k = off_ll;
	}

	/*
	 * The X register contains the offset of the beginning of the
	 * link-layer header; add 24, which is the minimum length
	 * of the MAC header for a data frame, to that, and store it
	 * in reg_off_macpl, and then load the Frame Control field,
	 * which is at the offset in the X register, with an indexed load.
	 */
	s2 = new_stmt(BPF_MISC|BPF_TXA);
	sappend(s, s2);
	s2 = new_stmt(BPF_ALU|BPF_ADD|BPF_K);
	s2->s.k = 24;
	sappend(s, s2);
	s2 = new_stmt(BPF_ST);
	s2->s.k = reg_off_macpl;
	sappend(s, s2);

	s2 = new_stmt(BPF_LD|BPF_IND|BPF_B);
	s2->s.k = 0;
	sappend(s, s2);

	/*
	 * Check the Frame Control field to see if this is a data frame;
	 * a data frame has the 0x08 bit (b3) in that field set and the
	 * 0x04 bit (b2) clear.
	 */
	sjset_data_frame_1 = new_stmt(JMP(BPF_JSET));
	sjset_data_frame_1->s.k = 0x08;
	sappend(s, sjset_data_frame_1);
		
	/*
	 * If b3 is set, test b2, otherwise go to the first statement of
	 * the rest of the program.
	 */
	sjset_data_frame_1->s.jt = sjset_data_frame_2 = new_stmt(JMP(BPF_JSET));
	sjset_data_frame_2->s.k = 0x04;
	sappend(s, sjset_data_frame_2);
	sjset_data_frame_1->s.jf = snext;

	/*
	 * If b2 is not set, this is a data frame; test the QoS bit.
	 * Otherwise, go to the first statement of the rest of the
	 * program.
	 */
	sjset_data_frame_2->s.jt = snext;
	sjset_data_frame_2->s.jf = sjset_qos = new_stmt(JMP(BPF_JSET));
	sjset_qos->s.k = 0x80;	/* QoS bit */
	sappend(s, sjset_qos);
		
	/*
	 * If it's set, add 2 to reg_off_macpl, to skip the QoS
	 * field.
	 * Otherwise, go to the first statement of the rest of the
	 * program.
	 */
	sjset_qos->s.jt = s2 = new_stmt(BPF_LD|BPF_MEM);
	s2->s.k = reg_off_macpl;
	sappend(s, s2);
	s2 = new_stmt(BPF_ALU|BPF_ADD|BPF_IMM);
	s2->s.k = 2;
	sappend(s, s2);
	s2 = new_stmt(BPF_ST);
	s2->s.k = reg_off_macpl;
	sappend(s, s2);

	/*
	 * If we have a radiotap header, look at it to see whether
	 * there's Atheros padding between the MAC-layer header
	 * and the payload.
	 *
	 * Note: all of the fields in the radiotap header are
	 * little-endian, so we byte-swap all of the values
	 * we test against, as they will be loaded as big-endian
	 * values.
	 */
	if (linktype == DLT_IEEE802_11_RADIO) {
		/*
		 * Is the IEEE80211_RADIOTAP_FLAGS bit (0x0000002) set
		 * in the presence flag?
		 */
		sjset_qos->s.jf = s2 = new_stmt(BPF_LD|BPF_ABS|BPF_W);
		s2->s.k = 4;
		sappend(s, s2);

		sjset_radiotap_flags = new_stmt(JMP(BPF_JSET));
		sjset_radiotap_flags->s.k = SWAPLONG(0x00000002);
		sappend(s, sjset_radiotap_flags);

		/*
		 * If not, skip all of this.
		 */
		sjset_radiotap_flags->s.jf = snext;

		/*
		 * Otherwise, is the IEEE80211_RADIOTAP_TSFT bit set?
		 */
		sjset_radiotap_tsft = sjset_radiotap_flags->s.jt =
		    new_stmt(JMP(BPF_JSET));
		sjset_radiotap_tsft->s.k = SWAPLONG(0x00000001);
		sappend(s, sjset_radiotap_tsft);

		/*
		 * If IEEE80211_RADIOTAP_TSFT is set, the flags field is
		 * at an offset of 16 from the beginning of the raw packet
		 * data (8 bytes for the radiotap header and 8 bytes for
		 * the TSFT field).
		 *
		 * Test whether the IEEE80211_RADIOTAP_F_DATAPAD bit (0x20)
		 * is set.
		 */
		sjset_radiotap_tsft->s.jt = s2 = new_stmt(BPF_LD|BPF_ABS|BPF_B);
		s2->s.k = 16;
		sappend(s, s2);

		sjset_tsft_datapad = new_stmt(JMP(BPF_JSET));
		sjset_tsft_datapad->s.k = 0x20;
		sappend(s, sjset_tsft_datapad);

		/*
		 * If IEEE80211_RADIOTAP_TSFT is not set, the flags field is
		 * at an offset of 8 from the beginning of the raw packet
		 * data (8 bytes for the radiotap header).
		 *
		 * Test whether the IEEE80211_RADIOTAP_F_DATAPAD bit (0x20)
		 * is set.
		 */
		sjset_radiotap_tsft->s.jf = s2 = new_stmt(BPF_LD|BPF_ABS|BPF_B);
		s2->s.k = 8;
		sappend(s, s2);

		sjset_notsft_datapad = new_stmt(JMP(BPF_JSET));
		sjset_notsft_datapad->s.k = 0x20;
		sappend(s, sjset_notsft_datapad);

		/*
		 * In either case, if IEEE80211_RADIOTAP_F_DATAPAD is
		 * set, round the length of the 802.11 header to
		 * a multiple of 4.  Do that by adding 3 and then
		 * dividing by and multiplying by 4, which we do by
		 * ANDing with ~3.
		 */
		s_roundup = new_stmt(BPF_LD|BPF_MEM);
		s_roundup->s.k = reg_off_macpl;
		sappend(s, s_roundup);
		s2 = new_stmt(BPF_ALU|BPF_ADD|BPF_IMM);
		s2->s.k = 3;
		sappend(s, s2);
		s2 = new_stmt(BPF_ALU|BPF_AND|BPF_IMM);
		s2->s.k = ~3;
		sappend(s, s2);
		s2 = new_stmt(BPF_ST);
		s2->s.k = reg_off_macpl;
		sappend(s, s2);

		sjset_tsft_datapad->s.jt = s_roundup;
		sjset_tsft_datapad->s.jf = snext;
		sjset_notsft_datapad->s.jt = s_roundup;
		sjset_notsft_datapad->s.jf = snext;
	} else
		sjset_qos->s.jf = snext;

	return s;
}
/*
 * Load a value relative to the beginning of the link-layer header after the 802.11
 * header, i.e. LLC_SNAP.
 * The link-layer header doesn't necessarily begin at the beginning
 * of the packet data; there might be a variable-length prefix containing
 * radio information.
 */
Load a value relative to the beginning of the link-layer header after the 802.11
header, i.e.
Load a value relative to the beginning of the link - layer header after the 802 . 11 header i . e .
static struct slist *
gen_load_802_11_header_len(struct slist *s, struct slist *snext)
{
	struct slist *s2;
	struct slist *sjset_data_frame_1;
	struct slist *sjset_data_frame_2;
	struct slist *sjset_qos;
	struct slist *sjset_radiotap_flags;
	struct slist *sjset_radiotap_tsft;
	struct slist *sjset_tsft_datapad, *sjset_notsft_datapad;
	struct slist *s_roundup;
	if (reg_off_macpl == -1) {
		return (s);
	}
	no_optimize = 1;
	if (s == NULL) {
		s = new_stmt(BPF_LDX|BPF_IMM);
		s->s.k = off_ll;
	}
	s2 = new_stmt(BPF_MISC|BPF_TXA);
	sappend(s, s2);
	s2 = new_stmt(BPF_ALU|BPF_ADD|BPF_K);
	s2->s.k = 24;
	sappend(s, s2);
	s2 = new_stmt(BPF_ST);
	s2->s.k = reg_off_macpl;
	sappend(s, s2);
	s2 = new_stmt(BPF_LD|BPF_IND|BPF_B);
	s2->s.k = 0;
	sappend(s, s2);
	sjset_data_frame_1 = new_stmt(JMP(BPF_JSET));
	sjset_data_frame_1->s.k = 0x08;
	sappend(s, sjset_data_frame_1);
	sjset_data_frame_1->s.jt = sjset_data_frame_2 = new_stmt(JMP(BPF_JSET));
	sjset_data_frame_2->s.k = 0x04;
	sappend(s, sjset_data_frame_2);
	sjset_data_frame_1->s.jf = snext;
	sjset_data_frame_2->s.jt = snext;
	sjset_data_frame_2->s.jf = sjset_qos = new_stmt(JMP(BPF_JSET));
	sjset_qos->s.k = 0x80;	
	sappend(s, sjset_qos);
	sjset_qos->s.jt = s2 = new_stmt(BPF_LD|BPF_MEM);
	s2->s.k = reg_off_macpl;
	sappend(s, s2);
	s2 = new_stmt(BPF_ALU|BPF_ADD|BPF_IMM);
	s2->s.k = 2;
	sappend(s, s2);
	s2 = new_stmt(BPF_ST);
	s2->s.k = reg_off_macpl;
	sappend(s, s2);
	if (linktype == DLT_IEEE802_11_RADIO) {
		sjset_qos->s.jf = s2 = new_stmt(BPF_LD|BPF_ABS|BPF_W);
		s2->s.k = 4;
		sappend(s, s2);
		sjset_radiotap_flags = new_stmt(JMP(BPF_JSET));
		sjset_radiotap_flags->s.k = SWAPLONG(0x00000002);
		sappend(s, sjset_radiotap_flags);
		sjset_radiotap_flags->s.jf = snext;
		sjset_radiotap_tsft = sjset_radiotap_flags->s.jt =
		    new_stmt(JMP(BPF_JSET));
		sjset_radiotap_tsft->s.k = SWAPLONG(0x00000001);
		sappend(s, sjset_radiotap_tsft);
		sjset_radiotap_tsft->s.jt = s2 = new_stmt(BPF_LD|BPF_ABS|BPF_B);
		s2->s.k = 16;
		sappend(s, s2);
		sjset_tsft_datapad = new_stmt(JMP(BPF_JSET));
		sjset_tsft_datapad->s.k = 0x20;
		sappend(s, sjset_tsft_datapad);
		sjset_radiotap_tsft->s.jf = s2 = new_stmt(BPF_LD|BPF_ABS|BPF_B);
		s2->s.k = 8;
		sappend(s, s2);
		sjset_notsft_datapad = new_stmt(JMP(BPF_JSET));
		sjset_notsft_datapad->s.k = 0x20;
		sappend(s, sjset_notsft_datapad);
		s_roundup = new_stmt(BPF_LD|BPF_MEM);
		s_roundup->s.k = reg_off_macpl;
		sappend(s, s_roundup);
		s2 = new_stmt(BPF_ALU|BPF_ADD|BPF_IMM);
		s2->s.k = 3;
		sappend(s, s2);
		s2 = new_stmt(BPF_ALU|BPF_AND|BPF_IMM);
		s2->s.k = ~3;
		sappend(s, s2);
		s2 = new_stmt(BPF_ST);
		s2->s.k = reg_off_macpl;
		sappend(s, s2);
		sjset_tsft_datapad->s.jt = s_roundup;
		sjset_tsft_datapad->s.jf = snext;
		sjset_notsft_datapad->s.jt = s_roundup;
		sjset_notsft_datapad->s.jf = snext;
	} else
		sjset_qos->s.jf = snext;
	return s;
}
static struct slist * gen_load_802_11_header_len ( struct slist * s , struct slist * snext ) { struct slist * s2 ; struct slist * sjset_data_frame_1 ; struct slist * sjset_data_frame_2 ; struct slist * sjset_qos ; struct slist * sjset_radiotap_flags ; struct slist * sjset_radiotap_tsft ; struct slist * sjset_tsft_datapad , * sjset_notsft_datapad ; struct slist * s_roundup ; if ( reg_off_macpl == -1 ) { return ( s ) ; } no_optimize = 1 ; if ( s == NULL ) { s = new_stmt ( BPF_LDX | BPF_IMM ) ; s -> s . k = off_ll ; } s2 = new_stmt ( BPF_MISC | BPF_TXA ) ; sappend ( s , s2 ) ; s2 = new_stmt ( BPF_ALU | BPF_ADD | BPF_K ) ; s2 -> s . k = 24 ; sappend ( s , s2 ) ; s2 = new_stmt ( BPF_ST ) ; s2 -> s . k = reg_off_macpl ; sappend ( s , s2 ) ; s2 = new_stmt ( BPF_LD | BPF_IND | BPF_B ) ; s2 -> s . k = 0 ; sappend ( s , s2 ) ; sjset_data_frame_1 = new_stmt ( JMP ( BPF_JSET ) ) ; sjset_data_frame_1 -> s . k = 0x08 ; sappend ( s , sjset_data_frame_1 ) ; sjset_data_frame_1 -> s . jt = sjset_data_frame_2 = new_stmt ( JMP ( BPF_JSET ) ) ; sjset_data_frame_2 -> s . k = 0x04 ; sappend ( s , sjset_data_frame_2 ) ; sjset_data_frame_1 -> s . jf = snext ; sjset_data_frame_2 -> s . jt = snext ; sjset_data_frame_2 -> s . jf = sjset_qos = new_stmt ( JMP ( BPF_JSET ) ) ; sjset_qos -> s . k = 0x80 ; sappend ( s , sjset_qos ) ; sjset_qos -> s . jt = s2 = new_stmt ( BPF_LD | BPF_MEM ) ; s2 -> s . k = reg_off_macpl ; sappend ( s , s2 ) ; s2 = new_stmt ( BPF_ALU | BPF_ADD | BPF_IMM ) ; s2 -> s . k = 2 ; sappend ( s , s2 ) ; s2 = new_stmt ( BPF_ST ) ; s2 -> s . k = reg_off_macpl ; sappend ( s , s2 ) ; if ( linktype == DLT_IEEE802_11_RADIO ) { sjset_qos -> s . jf = s2 = new_stmt ( BPF_LD | BPF_ABS | BPF_W ) ; s2 -> s . k = 4 ; sappend ( s , s2 ) ; sjset_radiotap_flags = new_stmt ( JMP ( BPF_JSET ) ) ; sjset_radiotap_flags -> s . k = SWAPLONG ( 0x00000002 ) ; sappend ( s , sjset_radiotap_flags ) ; sjset_radiotap_flags -> s . jf = snext ; sjset_radiotap_tsft = sjset_radiotap_flags -> s . jt = new_stmt ( JMP ( BPF_JSET ) ) ; sjset_radiotap_tsft -> s . k = SWAPLONG ( 0x00000001 ) ; sappend ( s , sjset_radiotap_tsft ) ; sjset_radiotap_tsft -> s . jt = s2 = new_stmt ( BPF_LD | BPF_ABS | BPF_B ) ; s2 -> s . k = 16 ; sappend ( s , s2 ) ; sjset_tsft_datapad = new_stmt ( JMP ( BPF_JSET ) ) ; sjset_tsft_datapad -> s . k = 0x20 ; sappend ( s , sjset_tsft_datapad ) ; sjset_radiotap_tsft -> s . jf = s2 = new_stmt ( BPF_LD | BPF_ABS | BPF_B ) ; s2 -> s . k = 8 ; sappend ( s , s2 ) ; sjset_notsft_datapad = new_stmt ( JMP ( BPF_JSET ) ) ; sjset_notsft_datapad -> s . k = 0x20 ; sappend ( s , sjset_notsft_datapad ) ; s_roundup = new_stmt ( BPF_LD | BPF_MEM ) ; s_roundup -> s . k = reg_off_macpl ; sappend ( s , s_roundup ) ; s2 = new_stmt ( BPF_ALU | BPF_ADD | BPF_IMM ) ; s2 -> s . k = 3 ; sappend ( s , s2 ) ; s2 = new_stmt ( BPF_ALU | BPF_AND | BPF_IMM ) ; s2 -> s . k = ~ 3 ; sappend ( s , s2 ) ; s2 = new_stmt ( BPF_ST ) ; s2 -> s . k = reg_off_macpl ; sappend ( s , s2 ) ; sjset_tsft_datapad -> s . jt = s_roundup ; sjset_tsft_datapad -> s . jf = snext ; sjset_notsft_datapad -> s . jt = s_roundup ; sjset_notsft_datapad -> s . jf = snext ; } else sjset_qos -> s . jf = snext ; return s ; }
Load a value relative to the beginning of the link-layer header after the 802.11
 header, i.e.
Load a value relative to the beginning of the link - layer header after the 802 . 11 header i . e .
/*
		 * No register has been assigned to the offset of
		 * the MAC-layer payload, which means nobody needs
		 * it; don't bother computing it - just return
		 * what we already have.
		 */ /*
	 * This code is not compatible with the optimizer, as
	 * we are generating jmp instructions within a normal
	 * slist of instructions
	 */ /*
	 * If "s" is non-null, it has code to arrange that the X register
	 * contains the length of the prefix preceding the link-layer
	 * header.
	 *
	 * Otherwise, the length of the prefix preceding the link-layer
	 * header is "off_ll".
	 */ /*
		 * There is no variable-length header preceding the
		 * link-layer header.
		 *
		 * Load the length of the fixed-length prefix preceding
		 * the link-layer header (if any) into the X register,
		 * and store it in the reg_off_macpl register.
		 * That length is off_ll.
		 */ /*
	 * The X register contains the offset of the beginning of the
	 * link-layer header; add 24, which is the minimum length
	 * of the MAC header for a data frame, to that, and store it
	 * in reg_off_macpl, and then load the Frame Control field,
	 * which is at the offset in the X register, with an indexed load.
	 */ /*
	 * Check the Frame Control field to see if this is a data frame;
	 * a data frame has the 0x08 bit (b3) in that field set and the
	 * 0x04 bit (b2) clear.
	 */ /*
	 * If b3 is set, test b2, otherwise go to the first statement of
	 * the rest of the program.
	 */ /*
	 * If b2 is not set, this is a data frame; test the QoS bit.
	 * Otherwise, go to the first statement of the rest of the
	 * program.
	 */ /* QoS bit */ /*
	 * If it's set, add 2 to reg_off_macpl, to skip the QoS
	 * field.
	 * Otherwise, go to the first statement of the rest of the
	 * program.
	 */ /*
	 * If we have a radiotap header, look at it to see whether
	 * there's Atheros padding between the MAC-layer header
	 * and the payload.
	 *
	 * Note: all of the fields in the radiotap header are
	 * little-endian, so we byte-swap all of the values
	 * we test against, as they will be loaded as big-endian
	 * values.
	 */ /*
		 * Is the IEEE80211_RADIOTAP_FLAGS bit (0x0000002) set
		 * in the presence flag?
		 */ /*
		 * If not, skip all of this.
		 */ /*
		 * Otherwise, is the IEEE80211_RADIOTAP_TSFT bit set?
		 */ /*
		 * If IEEE80211_RADIOTAP_TSFT is set, the flags field is
		 * at an offset of 16 from the beginning of the raw packet
		 * data (8 bytes for the radiotap header and 8 bytes for
		 * the TSFT field).
		 *
		 * Test whether the IEEE80211_RADIOTAP_F_DATAPAD bit (0x20)
		 * is set.
		 */ /*
		 * If IEEE80211_RADIOTAP_TSFT is not set, the flags field is
		 * at an offset of 8 from the beginning of the raw packet
		 * data (8 bytes for the radiotap header).
		 *
		 * Test whether the IEEE80211_RADIOTAP_F_DATAPAD bit (0x20)
		 * is set.
		 */ /*
		 * In either case, if IEEE80211_RADIOTAP_F_DATAPAD is
		 * set, round the length of the 802.11 header to
		 * a multiple of 4.  Do that by adding 3 and then
		 * dividing by and multiplying by 4, which we do by
		 * ANDing with ~3.
		 */