Lines Matching +full:byte +full:- +full:len

21  * pcap-util.c - common code for various files
26 #include <pcap-types.h>
33 #include "pcap-int.h"
35 #include "pcap-usb-linux-common.h"
37 #include "pcap-util.h"
41 * Most versions of the DLT_PFLOG pseudo-header have UID and PID fields
42 * that are saved in host byte order.
45 * the byte order of the host that wrote the file to this host's byte
51 u_int caplen = hdr->caplen; in swap_pflog_header()
52 u_int length = hdr->len; in swap_pflog_header()
56 if (caplen < (u_int) (offsetof(struct pfloghdr, uid) + sizeof pflhdr->uid) || in swap_pflog_header()
57 length < (u_int) (offsetof(struct pfloghdr, uid) + sizeof pflhdr->uid)) { in swap_pflog_header()
62 pfloghdr_length = pflhdr->length; in swap_pflog_header()
64 if (pfloghdr_length < (u_int) (offsetof(struct pfloghdr, uid) + sizeof pflhdr->uid)) { in swap_pflog_header()
68 pflhdr->uid = SWAPLONG(pflhdr->uid); in swap_pflog_header()
70 if (caplen < (u_int) (offsetof(struct pfloghdr, pid) + sizeof pflhdr->pid) || in swap_pflog_header()
71 length < (u_int) (offsetof(struct pfloghdr, pid) + sizeof pflhdr->pid)) { in swap_pflog_header()
75 if (pfloghdr_length < (u_int) (offsetof(struct pfloghdr, pid) + sizeof pflhdr->pid)) { in swap_pflog_header()
79 pflhdr->pid = SWAPLONG(pflhdr->pid); in swap_pflog_header()
81 if (caplen < (u_int) (offsetof(struct pfloghdr, rule_uid) + sizeof pflhdr->rule_uid) || in swap_pflog_header()
82 length < (u_int) (offsetof(struct pfloghdr, rule_uid) + sizeof pflhdr->rule_uid)) { in swap_pflog_header()
86 if (pfloghdr_length < (u_int) (offsetof(struct pfloghdr, rule_uid) + sizeof pflhdr->rule_uid)) { in swap_pflog_header()
90 pflhdr->rule_uid = SWAPLONG(pflhdr->rule_uid); in swap_pflog_header()
92 if (caplen < (u_int) (offsetof(struct pfloghdr, rule_pid) + sizeof pflhdr->rule_pid) || in swap_pflog_header()
93 length < (u_int) (offsetof(struct pfloghdr, rule_pid) + sizeof pflhdr->rule_pid)) { in swap_pflog_header()
97 if (pfloghdr_length < (u_int) (offsetof(struct pfloghdr, rule_pid) + sizeof pflhdr->rule_pid)) { in swap_pflog_header()
101 pflhdr->rule_pid = SWAPLONG(pflhdr->rule_pid); in swap_pflog_header()
107 * of the payload,with the CAN ID being in the byte order of the host
111 * acceptance field in the byte order of the host that wrote the packet.
114 * packets and, if the byte order host that wrote the packet, as
115 * indicated by the byte order of the pcap file or pcapng section
116 * containing the packet, is the opposite of our byte order, convert
117 * the header files to our byte order by byte-swapping them.
132 * by byte-swapping the CAN ID field. in swap_socketcan_header()
135 if (caplen < (u_int) (offsetof(pcap_can_socketcan_hdr, can_id) + sizeof hdrp->can_id) || in swap_socketcan_header()
136 length < (u_int) (offsetof(pcap_can_socketcan_hdr, can_id) + sizeof hdrp->can_id)) { in swap_socketcan_header()
140 hdrp->can_id = SWAPLONG(hdrp->can_id); in swap_socketcan_header()
146 * byte-swapping the priority/VCID field, the in swap_socketcan_header()
150 …if (caplen < (u_int) (offsetof(pcap_can_socketcan_xl_hdr, priority_vcid) + sizeof xl_hdrp->priorit… in swap_socketcan_header()
151 …length < (u_int) (offsetof(pcap_can_socketcan_xl_hdr, priority_vcid) + sizeof xl_hdrp->priority_vc… in swap_socketcan_header()
155 xl_hdrp->priority_vcid = SWAPLONG(xl_hdrp->priority_vcid); in swap_socketcan_header()
156 …if (caplen < (u_int) (offsetof(pcap_can_socketcan_xl_hdr, payload_length) + sizeof xl_hdrp->payloa… in swap_socketcan_header()
157 …length < (u_int) (offsetof(pcap_can_socketcan_xl_hdr, payload_length) + sizeof xl_hdrp->payload_le… in swap_socketcan_header()
161 xl_hdrp->payload_length = SWAPSHORT(xl_hdrp->payload_length); in swap_socketcan_header()
162 …if (caplen < (u_int) (offsetof(pcap_can_socketcan_xl_hdr, acceptance_field) + sizeof xl_hdrp->acce… in swap_socketcan_header()
163 …length < (u_int) (offsetof(pcap_can_socketcan_xl_hdr, acceptance_field) + sizeof xl_hdrp->acceptan… in swap_socketcan_header()
167 xl_hdrp->acceptance_field = SWAPLONG(xl_hdrp->acceptance_field); in swap_socketcan_header()
181 * with the CAN ID being in host byte order.
184 * packets and convert the CAN ID from the byte order of the host that
185 * wrote the file to this host's byte order.
190 u_int caplen = hdr->caplen; in swap_linux_sll_socketcan_header()
191 u_int length = hdr->len; in swap_linux_sll_socketcan_header()
201 * Byte-swap what needs to be byte-swapped. in swap_linux_sll_socketcan_header()
203 swap_socketcan_header(EXTRACT_BE_U_2(&shdr->sll_protocol), in swap_linux_sll_socketcan_header()
204 caplen - (u_int) sizeof(struct sll_header), in swap_linux_sll_socketcan_header()
205 length - (u_int) sizeof(struct sll_header), in swap_linux_sll_socketcan_header()
215 u_int caplen = hdr->caplen; in swap_linux_sll2_socketcan_header()
216 u_int length = hdr->len; in swap_linux_sll2_socketcan_header()
226 * Byte-swap what needs to be byte-swapped. in swap_linux_sll2_socketcan_header()
228 swap_socketcan_header(EXTRACT_BE_U_2(&shdr->sll2_protocol), in swap_linux_sll2_socketcan_header()
229 caplen - (u_int) sizeof(struct sll2_header), in swap_linux_sll2_socketcan_header()
230 length - (u_int) sizeof(struct sll2_header), in swap_linux_sll2_socketcan_header()
236 * byte order when capturing (it's supplied directly from a
237 * memory-mapped buffer shared by the kernel).
240 * need to convert it from the byte order of the host that wrote the
241 * file to this host's byte order.
258 * convert it to the reading host's byte order??? in swap_linux_usb_header()
261 if (hdr->caplen < offset) in swap_linux_usb_header()
263 uhdr->id = SWAPLL(uhdr->id); in swap_linux_usb_header()
265 offset += 4; /* skip past various 1-byte fields */ in swap_linux_usb_header()
268 if (hdr->caplen < offset) in swap_linux_usb_header()
270 uhdr->bus_id = SWAPSHORT(uhdr->bus_id); in swap_linux_usb_header()
272 offset += 2; /* skip past various 1-byte fields */ in swap_linux_usb_header()
275 if (hdr->caplen < offset) in swap_linux_usb_header()
277 uhdr->ts_sec = SWAPLL(uhdr->ts_sec); in swap_linux_usb_header()
280 if (hdr->caplen < offset) in swap_linux_usb_header()
282 uhdr->ts_usec = SWAPLONG(uhdr->ts_usec); in swap_linux_usb_header()
285 if (hdr->caplen < offset) in swap_linux_usb_header()
287 uhdr->status = SWAPLONG(uhdr->status); in swap_linux_usb_header()
290 if (hdr->caplen < offset) in swap_linux_usb_header()
292 uhdr->urb_len = SWAPLONG(uhdr->urb_len); in swap_linux_usb_header()
295 if (hdr->caplen < offset) in swap_linux_usb_header()
297 uhdr->data_len = SWAPLONG(uhdr->data_len); in swap_linux_usb_header()
299 if (uhdr->transfer_type == URB_ISOCHRONOUS) { in swap_linux_usb_header()
301 if (hdr->caplen < offset) in swap_linux_usb_header()
303 uhdr->s.iso.error_count = SWAPLONG(uhdr->s.iso.error_count); in swap_linux_usb_header()
306 if (hdr->caplen < offset) in swap_linux_usb_header()
308 uhdr->s.iso.numdesc = SWAPLONG(uhdr->s.iso.numdesc); in swap_linux_usb_header()
317 * the header is not s.iso.numdesc, it's ndesc - only the in swap_linux_usb_header()
327 * a "version 0" header from a memory-mapped in swap_linux_usb_header()
328 * capture, with 16 bytes of zeroed-out padding in swap_linux_usb_header()
329 * at the end. Byte swap them as if this were in swap_linux_usb_header()
333 if (hdr->caplen < offset) in swap_linux_usb_header()
335 uhdr->interval = SWAPLONG(uhdr->interval); in swap_linux_usb_header()
338 if (hdr->caplen < offset) in swap_linux_usb_header()
340 uhdr->start_frame = SWAPLONG(uhdr->start_frame); in swap_linux_usb_header()
343 if (hdr->caplen < offset) in swap_linux_usb_header()
345 uhdr->xfer_flags = SWAPLONG(uhdr->xfer_flags); in swap_linux_usb_header()
348 if (hdr->caplen < offset) in swap_linux_usb_header()
350 uhdr->ndesc = SWAPLONG(uhdr->ndesc); in swap_linux_usb_header()
352 if (uhdr->transfer_type == URB_ISOCHRONOUS) { in swap_linux_usb_header()
358 for (i = 0; i < uhdr->ndesc; i++) { in swap_linux_usb_header()
360 if (hdr->caplen < offset) in swap_linux_usb_header()
362 pisodesc->status = SWAPLONG(pisodesc->status); in swap_linux_usb_header()
365 if (hdr->caplen < offset) in swap_linux_usb_header()
367 pisodesc->offset = SWAPLONG(pisodesc->offset); in swap_linux_usb_header()
369 offset += 4; /* skip past len */ in swap_linux_usb_header()
370 if (hdr->caplen < offset) in swap_linux_usb_header()
372 pisodesc->len = SWAPLONG(pisodesc->len); in swap_linux_usb_header()
383 * The DLT_NFLOG "packets" have a mixture of big-endian and host-byte-order
384 * data. They begin with a fixed-length header with big-endian fields,
386 * byte order but the values are either big-endian or are a raw byte
387 * sequence that's the same regardless of the host's byte order.
390 * length values from the byte order of the host that wrote the file
391 * to the byte order of this host.
399 u_int caplen = hdr->caplen; in swap_nflog_header()
400 u_int length = hdr->len; in swap_nflog_header()
409 if (nfhdr->nflog_version != 0) { in swap_nflog_header()
414 length -= sizeof(nflog_hdr_t); in swap_nflog_header()
415 caplen -= sizeof(nflog_hdr_t); in swap_nflog_header()
422 tlv->tlv_type = SWAPSHORT(tlv->tlv_type); in swap_nflog_header()
423 tlv->tlv_length = SWAPSHORT(tlv->tlv_length); in swap_nflog_header()
426 size = tlv->tlv_length; in swap_nflog_header()
428 size += 4 - size % 4; in swap_nflog_header()
443 length -= size; in swap_nflog_header()
444 caplen -= size; in swap_nflog_header()
453 * Convert pseudo-headers from the byte order of in swap_pseudo_headers()
455 * byte order, as necessary. in swap_pseudo_headers()
499 usb_hdr->urb_len; in packet_length_might_be_wrong()
500 return (hdr->len == old_style_packet_length); in packet_length_might_be_wrong()
511 * Is this a memory-mapped Linux USB capture? in pcapint_post_process()
517 * In older versions of libpcap, in memory-mapped Linux in pcapint_post_process()
530 * We only do this if we have the full USB pseudo-header, in pcapint_post_process()
534 if (hdr->caplen < sizeof (pcap_usb_header_mmapped)) { in pcapint_post_process()
536 * We don't have the full pseudo-header. in pcapint_post_process()
563 * unsigned 32-bit integer. in pcapint_post_process()
565 if (usb_hdr->ndesc > USB_MAXDESC) in pcapint_post_process()
568 if (!usb_hdr->data_flag && in pcapint_post_process()
571 u_int len; in pcapint_post_process() local
580 if (hdr->caplen < iso_pseudo_header_len(usb_hdr)) in pcapint_post_process()
586 len = incoming_isochronous_transfer_completed_len(hdr, in pcapint_post_process()
590 * len is the smaller of UINT_MAX and the total in pcapint_post_process()
598 if (len >= hdr->caplen) in pcapint_post_process()
599 hdr->len = len; in pcapint_post_process()
620 * of the actual length - and to make sure the in pcapint_post_process()
623 if (hdr->caplen > hdr->len) in pcapint_post_process()
624 hdr->len = hdr->caplen; in pcapint_post_process()