cpack.c File Reference

#include <include.h>
#include <tcpdump-stdinc.h>
#include "cpack.h"
#include "extract.h"

Include dependency graph for cpack.c:

Go to the source code of this file.

Functions

static u_int8_t * cpack_next_boundary (u_int8_t *buf, u_int8_t *p, size_t alignment)
static u_int8_t * cpack_align_and_reserve (struct cpack_state *cs, size_t wordsize)
int cpack_init (struct cpack_state *cs, u_int8_t *buf, size_t buflen)
int cpack_uint64 (struct cpack_state *cs, u_int64_t *u)
int cpack_uint32 (struct cpack_state *cs, u_int32_t *u)
int cpack_uint16 (struct cpack_state *cs, u_int16_t *u)
int cpack_uint8 (struct cpack_state *cs, u_int8_t *u)


Function Documentation

static u_int8_t* cpack_next_boundary ( u_int8_t *  buf,
u_int8_t *  p,
size_t  alignment 
) [static]

Definition at line 41 of file cpack.c.

Referenced by cpack_align_and_reserve().

00042 {
00043   size_t misalignment = (size_t)(p - buf) % alignment;
00044 
00045   if (misalignment == 0)
00046     return p;
00047 
00048   return p + (alignment - misalignment);
00049 }

static u_int8_t* cpack_align_and_reserve ( struct cpack_state cs,
size_t  wordsize 
) [static]

Definition at line 56 of file cpack.c.

References cpack_state::c_buf, cpack_state::c_len, cpack_state::c_next, and cpack_next_boundary().

Referenced by cpack_uint16(), cpack_uint32(), and cpack_uint64().

00057 {
00058   u_int8_t *next;
00059 
00060   /* Ensure alignment. */
00061   next = cpack_next_boundary(cs->c_buf, cs->c_next, wordsize);
00062 
00063   /* Too little space for wordsize bytes? */
00064   if (next - cs->c_buf + wordsize > cs->c_len)
00065     return NULL;
00066 
00067   return next;
00068 }

int cpack_init ( struct cpack_state cs,
u_int8_t *  buf,
size_t  buflen 
)

Definition at line 71 of file cpack.c.

References cpack_state::c_buf, cpack_state::c_len, and cpack_state::c_next.

Referenced by FillRadioData().

00072 {
00073   memset(cs, 0, sizeof(*cs));
00074 
00075   cs->c_buf = buf;
00076   cs->c_len = buflen;
00077   cs->c_next = cs->c_buf;
00078 
00079   return 0;
00080 }

int cpack_uint64 ( struct cpack_state cs,
u_int64_t *  u 
)

Definition at line 84 of file cpack.c.

References cpack_state::c_next, cpack_align_and_reserve(), and EXTRACT_LE_64BITS.

Referenced by extract_radiotap_field().

00085 {
00086   u_int8_t *next;
00087 
00088   if ((next = cpack_align_and_reserve(cs, sizeof(*u))) == NULL)
00089     return -1;
00090 
00091   *u = EXTRACT_LE_64BITS(next);
00092 
00093   /* Move pointer past the u_int64_t. */
00094   cs->c_next = next + sizeof(*u);
00095   return 0;
00096 }

int cpack_uint32 ( struct cpack_state cs,
u_int32_t *  u 
)

Definition at line 100 of file cpack.c.

References cpack_state::c_next, cpack_align_and_reserve(), and EXTRACT_LE_32BITS.

00101 {
00102   u_int8_t *next;
00103 
00104   if ((next = cpack_align_and_reserve(cs, sizeof(*u))) == NULL)
00105     return -1;
00106 
00107   *u = EXTRACT_LE_32BITS(next);
00108 
00109   /* Move pointer past the u_int32_t. */
00110   cs->c_next = next + sizeof(*u);
00111   return 0;
00112 }

int cpack_uint16 ( struct cpack_state cs,
u_int16_t *  u 
)

Definition at line 116 of file cpack.c.

References cpack_state::c_next, cpack_align_and_reserve(), and EXTRACT_LE_16BITS.

Referenced by extract_radiotap_field().

00117 {
00118   u_int8_t *next;
00119 
00120   if ((next = cpack_align_and_reserve(cs, sizeof(*u))) == NULL)
00121     return -1;
00122 
00123   *u = EXTRACT_LE_16BITS(next);
00124 
00125   /* Move pointer past the u_int16_t. */
00126   cs->c_next = next + sizeof(*u);
00127   return 0;
00128 }

int cpack_uint8 ( struct cpack_state cs,
u_int8_t *  u 
)

Definition at line 132 of file cpack.c.

References cpack_state::c_buf, cpack_state::c_len, and cpack_state::c_next.

Referenced by extract_radiotap_field().

00133 {
00134   /* No space left? */
00135   if ((size_t)(cs->c_next - cs->c_buf) >= cs->c_len)
00136     return -1;
00137 
00138   *u = *cs->c_next;
00139 
00140   /* Move pointer past the u_int8_t. */
00141   cs->c_next++;
00142   return 0;
00143 }


Generated on Fri Jul 25 17:10:48 2008 for WifiScanner by  doxygen 1.5.5