static int lnet_tag_type(lua_State* L) { libnet_t* ud = checkudata(L); libnet_pblock_t* pblock = checkpblock(L, ud, 2); lua_pushstring(L, libnet_diag_dump_pblock_type(pblock->type)); return 1; }
void libnet_diag_dump_pblock(libnet_t *l) { u_int32_t n; libnet_pblock_t *p; for (p = l->protocol_blocks; p; p = p->next) { fprintf(stderr, "pblock type:\t%s\n", libnet_diag_dump_pblock_type(p->type)); fprintf(stderr, "ptag number:\t%d\n", p->ptag); fprintf(stderr, "IP offset:\t%d\n", p->ip_offset); fprintf(stderr, "pblock address:\t%p\n", p); fprintf(stderr, "next pblock\t%p ", p->next); if (p->next) { fprintf(stderr, "(%s)", libnet_diag_dump_pblock_type(p->next->type)); } fprintf(stderr, "\n"); fprintf(stderr, "prev pblock\t%p ", p->prev); if (p->prev) { fprintf(stderr, "(%s)", libnet_diag_dump_pblock_type(p->prev->type)); } fprintf(stderr, "\n"); fprintf(stderr, "buf:\t\t"); for (n = 0; n < p->b_len; n++) { fprintf(stderr, "%02x", p->buf[n]); } fprintf(stderr, "\nbuffer length:\t%d\n", p->b_len); if ((p->flags) & LIBNET_PBLOCK_DO_CHECKSUM) { fprintf(stderr, "checksum flag:\tYes\n"); fprintf(stderr, "chksum length:\t%d\n", p->h_len); } else { fprintf(stderr, "checksum flag:\tNo\n"); } fprintf(stderr, "bytes copied:\t%d\n\n", p->copied); } }
/* check ptag argument is zero, or refers to a pblock of the expected type */ static int lnet_arg_ptag(lua_State* L, libnet_t* ud, int targ, int type) { int ptag = v_arg_integer_opt(L, targ, "ptag", LIBNET_PTAG_INITIALIZER); if(ptag) { libnet_pblock_t* pblock = libnet_pblock_find(ud, ptag); luaL_argcheck(L, pblock, targ, lua_pushfstring(L, "ptag %d cannot be found", ptag)); luaL_argcheck(L, pblock->type == type, targ, lua_pushfstring(L, "ptag %d of type %s/%s is not %s/%s", ptag, pushistring(L, "%#x", pblock->type), libnet_diag_dump_pblock_type(pblock->type), pushistring(L, "%#x", type), libnet_diag_dump_pblock_type(type) )); } return ptag; }
static libnet_pblock_t* checkptype(lua_State* L, libnet_t* l, uint8_t type) { libnet_pblock_t* pblock = libnet_pblock_by_type(l, type, NULL); if(!pblock) luaL_error(L, "pblock type %s (%s) not found", pushistring(L, "%#x", type), libnet_diag_dump_pblock_type(type)); return pblock; }
static void print_pblocks(libnet_t* l) { libnet_pblock_t* p = l->protocol_blocks; while(p) { printf(" tag %2d flags %d type %20s/%#x buf %p b_len %2u h_len %2u ip_offset %2u, copied %2u\n", p->ptag, p->flags, libnet_diag_dump_pblock_type(p->type), p->type, p->buf, p->b_len, p->h_len, p->ip_offset, p->copied); p = p->next; } printf(" link_offset %d aligner %d total_size %u nblocks %d\n", l->link_offset, l->aligner, l->total_size, l->n_pblocks); }
static void pushpblock(lua_State* L, libnet_pblock_t* pblock) { int tindex = lua_gettop(L) + 1; lua_newtable(L); setlstringfield(L, tindex, "buf", pblock->buf, pblock->b_len); setintfield(L, tindex, "b_len", pblock->b_len); setintfield(L, tindex, "h_len", pblock->h_len); setintfield(L, tindex, "copied", pblock->copied); setstringfield(L, tindex, "type", libnet_diag_dump_pblock_type(pblock->type)); setintfield(L, tindex, "flags", pblock->flags); setintfield(L, tindex, "ptag", pblock->ptag); if(pblock->next) setintfield(L, tindex, "next", pblock->next->ptag); if(pblock->prev) setintfield(L, tindex, "prev", pblock->prev->ptag); }
static void print_pblocks(libnet_t* l) { libnet_pblock_t* p = l->protocol_blocks; while(p) { /* h_len is header length for checksumming? "chksum length"? */ printf(" tag %d flags %d type %20s/%#x buf %p b_len %2u h_len %2u copied %2u\n", p->ptag, p->flags, libnet_diag_dump_pblock_type(p->type), p->type, p->buf, p->b_len, p->h_len, p->copied); p = p->next; } printf(" link_offset %d aligner %d total_size %u nblocks %d\n", l->link_offset, l->aligner, l->total_size, l->n_pblocks); }
static const char* type_string(u_int8_t type) { return libnet_diag_dump_pblock_type(type); }