예제 #1
0
int
fdatatlv_print(register const u_char * pptr, register u_int len,
	       u_int16_t op_msk _U_, int indent)
{
	const struct forces_tlv *tlv = (struct forces_tlv *)pptr;
	u_int rlen;
	register const u_char *tdp = (u_char *) TLV_DATA(tlv);
	u_int16_t type;

	/*
	 * pdatacnt_print() or pkeyitlv_print() has ensured that len
	 * (the TLV length) >= TLV_HDRL.
	 */
	rlen = len - TLV_HDRL;
	TCHECK(*tlv);
	type = EXTRACT_16BITS(&tlv->type);
	if (type != F_TLV_FULD) {
		printf("Error: expecting FULLDATA!\n");
		return -1;
	}

	if (vflag >= 3) {
		char *ib = indent_pr(indent + 2, 1);
		printf("%s[", &ib[1]);
		hex_print_with_offset(ib, tdp, rlen, 0);
		printf("\n%s]\n", &ib[1]);
	}
	return 0;

trunc:
	fputs("[|forces]", stdout);
	return -1;
}
예제 #2
0
static int
fdatatlv_print(netdissect_options *ndo,
               register const u_char * pptr, register u_int len,
               u_int16_t op_msk _U_, int indent)
{
	const struct forces_tlv *tlv = (struct forces_tlv *)pptr;
	u_int rlen;
	register const u_char *tdp = (u_char *) TLV_DATA(tlv);
	u_int16_t type;

	/*
	 * pdatacnt_print() or pkeyitlv_print() has ensured that len
	 * (the TLV length) >= TLV_HDRL.
	 */
	rlen = len - TLV_HDRL;
	ND_TCHECK(*tlv);
	type = EXTRACT_16BITS(&tlv->type);
	if (type != F_TLV_FULD) {
		ND_PRINT((ndo, "Error: expecting FULLDATA!\n"));
		return -1;
	}

	if (ndo->ndo_vflag >= 3) {
		char *ib = indent_pr(indent + 2, 1);
		ND_PRINT((ndo, "%s[", &ib[1]));
		hex_print_with_offset(ndo, ib, tdp, rlen, 0);
		ND_PRINT((ndo, "\n%s]\n", &ib[1]));
	}
	return 0;

trunc:
	ND_PRINT((ndo, "%s", tstr));
	return -1;
}
예제 #3
0
static int
sdatailv_print(netdissect_options *ndo,
               register const u_char * pptr, register u_int len,
               u_int16_t op_msk _U_, int indent)
{
	u_int rlen;
	const struct forces_ilv *ilv = (struct forces_ilv *)pptr;
	int invilv;

	if (len < ILV_HDRL) {
		ND_PRINT((ndo, "Error: BAD SPARSEDATA-TLV!\n"));
		return -1;
	}
	rlen = len;
	indent += 1;
	while (rlen != 0) {
#if 0
		ND_PRINT((ndo, "Jamal - outstanding length <%d>\n", rlen));
#endif
		char *ib = indent_pr(indent, 1);
		register const u_char *tdp = (u_char *) ILV_DATA(ilv);
		ND_TCHECK(*ilv);
		invilv = ilv_valid(ilv, rlen);
		if (invilv) {
			ND_PRINT((ndo, "%s[", &ib[1]));
			hex_print_with_offset(ndo, ib, tdp, rlen, 0);
			ND_PRINT((ndo, "\n%s]\n", &ib[1]));
			return -1;
		}
		if (ndo->ndo_vflag >= 3) {
			int ilvl = EXTRACT_32BITS(&ilv->length);
			ND_PRINT((ndo, "\n%s ILV: type %x length %d\n", &ib[1],
			       EXTRACT_32BITS(&ilv->type), ilvl));
			hex_print_with_offset(ndo, "\t\t[", tdp, ilvl-ILV_HDRL, 0);
		}

		ilv = GO_NXT_ILV(ilv, rlen);
	}

	return 0;

trunc:
	ND_PRINT((ndo, "%s", tstr));
	return -1;
}
예제 #4
0
int
sdatailv_print(register const u_char * pptr, register u_int len,
	       u_int16_t op_msk _U_, int indent)
{
	u_int rlen;
	const struct forces_ilv *ilv = (struct forces_ilv *)pptr;
	int invilv;

	if (len < ILV_HDRL) {
		printf("Error: BAD SPARSEDATA-TLV!\n");
		return -1;
	}
	rlen = len;
	indent += 1;
	while (rlen != 0) {
		char *ib = indent_pr(indent, 1);
		register const u_char *tdp = (u_char *) ILV_DATA(ilv);
		TCHECK(*ilv);
		invilv = ilv_valid(ilv, rlen);
		if (invilv) {
			printf("%s[", &ib[1]);
			hex_print_with_offset(ib, tdp, rlen, 0);
			printf("\n%s]\n", &ib[1]);
			return -1;
		}
		if (vflag >= 3) {
			int ilvl = EXTRACT_32BITS(&ilv->length);
			printf("\n%s ILV: type %x length %d\n", &ib[1],
			       EXTRACT_32BITS(&ilv->type), ilvl);
			hex_print_with_offset("\t\t[", tdp, ilvl-ILV_HDRL, 0);
		}

		ilv = GO_NXT_ILV(ilv, rlen);
	}

	return 0;

trunc:
	fputs("[|forces]", stdout);
	return -1;
}
예제 #5
0
int
invoptlv_print(register const u_char * pptr, register u_int len,
	       u_int16_t op_msk _U_, int indent)
{
	char *ib = indent_pr(indent, 1);

	if (vflag >= 3) {
		printf("%sData[", &ib[1]);
		hex_print_with_offset(ib, pptr, len, 0);
		printf("%s]\n", ib);
	}
	return -1;
}
예제 #6
0
void
telnet_print(netdissect_options *ndo, const u_char *sp, u_int length)
{
	int first = 1;
	const u_char *osp;
	int l;

	osp = sp;

	ND_TCHECK(*sp);
	while (length > 0 && *sp == IAC) {
		/*
		 * Parse the Telnet command without printing it,
		 * to determine its length.
		 */
		l = telnet_parse(ndo, sp, length, 0);
		if (l < 0)
			break;

		/*
		 * now print it
		 */
		if (ndo->ndo_Xflag && 2 < ndo->ndo_vflag) {
			if (first)
				ND_PRINT((ndo, "\nTelnet:"));
			hex_print_with_offset(ndo, "\n", sp, l, sp - osp);
			if (l > 8)
				ND_PRINT((ndo, "\n\t\t\t\t"));
			else
				ND_PRINT((ndo, "%*s\t", (8 - l) * 3, ""));
		} else
			ND_PRINT((ndo, "%s", (first) ? " [telnet " : ", "));

		(void)telnet_parse(ndo, sp, length, 1);
		first = 0;

		sp += l;
		length -= l;
		ND_TCHECK(*sp);
	}
	if (!first) {
		if (ndo->ndo_Xflag && 2 < ndo->ndo_vflag)
			ND_PRINT((ndo, "\n"));
		else
			ND_PRINT((ndo, "]"));
	}
	return;
trunc:
	ND_PRINT((ndo, "%s", tstr));
}
예제 #7
0
static int
invoptlv_print(netdissect_options *ndo,
               register const u_char * pptr, register u_int len,
               u_int16_t op_msk _U_, int indent)
{
	char *ib = indent_pr(indent, 1);

	if (ndo->ndo_vflag >= 3) {
		ND_PRINT((ndo, "%sData[", &ib[1]));
		hex_print_with_offset(ndo, ib, pptr, len, 0);
		ND_PRINT((ndo, "%s]\n", ib));
	}
	return -1;
}
예제 #8
0
int
main(int argc, char *argv[])
{
	hex_print("\n\t", "Hello, World!\n", 14);
	printf("\n");
	hex_and_ascii_print("\n\t", "Hello, World!\n", 14);
	printf("\n");
	ascii_print("Hello, World!\n", 14);
	printf("\n");
#define TMSG "Now is the winter of our discontent...\n"
	hex_print_with_offset("\n\t", TMSG, sizeof(TMSG) - 1, 0x100);
	printf("\n");
	hex_and_ascii_print_with_offset("\n\t", TMSG, sizeof(TMSG) - 1, 0x100);
	printf("\n");
	exit(0);
}
예제 #9
0
int
pdata_print(register const u_char * pptr, register u_int len,
	    u_int16_t op_msk, int indent)
{
	const struct pathdata_h *pdh = (struct pathdata_h *)pptr;
	char *ib = indent_pr(indent, 0);
	u_int minsize = 0;
	int more_pd = 0;
	u_int16_t idcnt = 0;

	TCHECK(*pdh);
	if (len < sizeof(struct pathdata_h))
		goto trunc;
	if (vflag >= 3) {
		printf("\n%sPathdata: Flags 0x%x ID count %d\n",
		       ib, EXTRACT_16BITS(&pdh->pflags), EXTRACT_16BITS(&pdh->pIDcnt));
	}

	if (EXTRACT_16BITS(&pdh->pflags) & F_SELKEY) {
		op_msk |= B_KEYIN;
	}
	pptr += sizeof(struct pathdata_h);
	len -= sizeof(struct pathdata_h);
	idcnt = EXTRACT_16BITS(&pdh->pIDcnt);
	minsize = idcnt * 4;
	if (len < minsize) {
		printf("\t\t\ttruncated IDs expected %uB got %uB\n", minsize,
		       len);
		hex_print_with_offset("\t\t\tID Data[", pptr, len, 0);
		printf("]\n");
		return -1;
	}
	more_pd = pdatacnt_print(pptr, len, idcnt, op_msk, indent);
	if (more_pd > 0) {
		int consumed = len - more_pd;
		pptr += consumed;
		len = more_pd; 
		/* XXX: Argh, recurse some more */
		return recpdoptlv_print(pptr, len, op_msk, indent+1);
	} else
		return 0;

trunc:
	fputs("[|forces]", stdout);
	return -1;
}
예제 #10
0
char *
telnet_print(const u_char *sp, u_int length)
{
   int first = 1;
   const u_char *osp;
   int l;

   osp = sp;

   while (length > 0 && *sp == IAC) {
      l = telnet_parse(sp, length, 0);
      if (l < 0)
         break;

      /*
       * now print it
       */
      if (ArgusParser->Xflag && 2 < ArgusParser->vflag) {
         if (first)
            sprintf(&ArgusBuf[strlen(ArgusBuf)],"Telnet:");
         hex_print_with_offset(" ", sp, l, sp - osp);
         if (l > 8)
            sprintf(&ArgusBuf[strlen(ArgusBuf)],"\n\t\t\t\t");
         else
            sprintf(&ArgusBuf[strlen(ArgusBuf)],"%*s\t", (8 - l) * 3, "");
      } else
         sprintf(&ArgusBuf[strlen(ArgusBuf)],"%s", (first) ? " [telnet " : ", ");

      (void)telnet_parse(sp, length, 1);
      first = 0;

      sp += l;
      length -= l;
   }
   if (!first) {
      if (ArgusParser->Xflag && 2 < ArgusParser->vflag)
         sprintf(&ArgusBuf[strlen(ArgusBuf)],"\n");
      else
         sprintf(&ArgusBuf[strlen(ArgusBuf)],"]");
   }

   return ArgusBuf;
}
예제 #11
0
void
telnet_print(const u_char *sp, u_int length)
{
	int first = 1;
	const u_char *osp;
	int l;

	osp = sp;

	while (length > 0 && *sp == IAC) {
		l = telnet_parse(sp, length, 0);
		if (l < 0)
			break;

		/*
		 * now print it
		 */
		if (Xflag && 2 < vflag) {
			if (first)
				printf("\nTelnet:");
			hex_print_with_offset("\n", sp, l, sp - osp);
			if (l > 8)
				printf("\n\t\t\t\t");
			else
				printf("%*s\t", (8 - l) * 3, "");
		} else
			printf("%s", (first) ? " [telnet " : ", ");

		(void)telnet_parse(sp, length, 1);
		first = 0;

		sp += l;
		length -= l;
	}
	if (!first) {
		if (Xflag && 2 < vflag)
			printf("\n");
		else
			printf("]");
	}
}
예제 #12
0
/*
 * just for completeness
 */
void
hex_print(register const char *ident, register const u_char *cp, register u_int length)
{
	hex_print_with_offset(ident, cp, length, 0);
}
예제 #13
0
static int
pdata_print(netdissect_options *ndo,
            register const u_char * pptr, register u_int len,
            u_int16_t op_msk, int indent)
{
	const struct pathdata_h *pdh = (struct pathdata_h *)pptr;
	char *ib = indent_pr(indent, 0);
	u_int minsize = 0;
	int more_pd = 0;
	u_int16_t idcnt = 0;

	ND_TCHECK(*pdh);
	if (len < sizeof(struct pathdata_h))
		goto trunc;
	if (ndo->ndo_vflag >= 3) {
		ND_PRINT((ndo, "\n%sPathdata: Flags 0x%x ID count %d\n",
		       ib, EXTRACT_16BITS(&pdh->pflags), EXTRACT_16BITS(&pdh->pIDcnt)));
	}

	if (EXTRACT_16BITS(&pdh->pflags) & F_SELKEY) {
		op_msk |= B_KEYIN;
	}

	/* Table GET Range operation */
	if (EXTRACT_16BITS(&pdh->pflags) & F_SELTABRANGE) {
		op_msk |= B_TRNG;
	}
	/* Table SET append operation */
	if (EXTRACT_16BITS(&pdh->pflags) & F_TABAPPEND) {
		op_msk |= B_APPND;
	}

	pptr += sizeof(struct pathdata_h);
	len -= sizeof(struct pathdata_h);
	idcnt = EXTRACT_16BITS(&pdh->pIDcnt);
	minsize = idcnt * 4;
	if (len < minsize) {
		ND_PRINT((ndo, "\t\t\ttruncated IDs expected %uB got %uB\n", minsize,
		       len));
		hex_print_with_offset(ndo, "\t\t\tID Data[", pptr, len, 0);
		ND_PRINT((ndo, "]\n"));
		return -1;
	}

	if ((op_msk & B_TRNG) && (op_msk & B_KEYIN)) {
		ND_PRINT((ndo, "\t\t\tIllegal to have both Table ranges and keys\n"));
		return -1;
	}

	more_pd = pdatacnt_print(ndo, pptr, len, idcnt, op_msk, indent);
	if (more_pd > 0) {
		int consumed = len - more_pd;
		pptr += consumed;
		len = more_pd;
		/* XXX: Argh, recurse some more */
		return recpdoptlv_print(ndo, pptr, len, op_msk, indent+1);
	} else
		return 0;

trunc:
	ND_PRINT((ndo, "%s", tstr));
	return -1;
}
예제 #14
0
static int
pdatacnt_print(netdissect_options *ndo,
               register const u_char * pptr, register u_int len,
               u_int16_t IDcnt, u_int16_t op_msk, int indent)
{
	u_int i;
	u_int32_t id;
	char *ib = indent_pr(indent, 0);

	if ((op_msk & B_APPND) && ndo->ndo_vflag >= 3) {
		ND_PRINT((ndo, "%sTABLE APPEND\n", ib));
	}
	for (i = 0; i < IDcnt; i++) {
		ND_TCHECK2(*pptr, 4);
		if (len < 4)
			goto trunc;
		id = EXTRACT_32BITS(pptr);
		if (ndo->ndo_vflag >= 3)
			ND_PRINT((ndo, "%sID#%02u: %d\n", ib, i + 1, id));
		len -= 4;
		pptr += 4;
	}

	if ((op_msk & B_TRNG) || (op_msk & B_KEYIN)) {
		if (op_msk & B_TRNG) {
			u_int32_t starti, endi;

			if (len < PTH_DESC_SIZE) {
				ND_PRINT((ndo, "pathlength %d with key/range too short %d\n",
				       len, PTH_DESC_SIZE));
				return -1;
			}

			pptr += sizeof(struct forces_tlv);
			len -= sizeof(struct forces_tlv);

			starti = EXTRACT_32BITS(pptr);
			pptr += 4;
			len -= 4;

			endi = EXTRACT_32BITS(pptr);
			pptr += 4;
			len -= 4;

			if (ndo->ndo_vflag >= 3)
				ND_PRINT((ndo, "%sTable range: [%d,%d]\n", ib, starti, endi));
		}

		if (op_msk & B_KEYIN) {
			struct forces_tlv *keytlv;
			u_int16_t tll;

			if (len < PTH_DESC_SIZE) {
				ND_PRINT((ndo, "pathlength %d with key/range too short %d\n",
				       len, PTH_DESC_SIZE));
				return -1;
			}

			/* skip keyid */
			pptr += 4;
			len -= 4;
			keytlv = (struct forces_tlv *)pptr;
			/* skip header */
			pptr += sizeof(struct forces_tlv);
			len -= sizeof(struct forces_tlv);
			/* skip key content */
			tll = EXTRACT_16BITS(&keytlv->length);
			if (tll < TLV_HDRL) {
				ND_PRINT((ndo, "key content length %u < %u\n",
					tll, TLV_HDRL));
				return -1;
			}
			tll -= TLV_HDRL;
			if (len < tll) {
				ND_PRINT((ndo, "key content too short\n"));
				return -1;
			}
			pptr += tll;
			len -= tll;
		}

	}

	if (len) {
		const struct forces_tlv *pdtlv = (struct forces_tlv *)pptr;
		u_int16_t type;
		u_int16_t tll;
		int pad = 0;
		u_int aln;
		u_int invtlv;

		ND_TCHECK(*pdtlv);
		type = EXTRACT_16BITS(&pdtlv->type);
		invtlv = tlv_valid(pdtlv, len);
		if (invtlv) {
			ND_PRINT((ndo, "%s Outstanding bytes %d for TLV type 0x%x TLV len %d\n",
			          tok2str(ForCES_TLV_err, NULL, invtlv), len, type,
			          EXTRACT_16BITS(&pdtlv->length)));
			goto pd_err;
		}
		/*
		 * At this point, tlv_valid() has ensured that the TLV
		 * length is large enough but not too large (it doesn't
		 * go past the end of the containing TLV).
		 */
		tll = EXTRACT_16BITS(&pdtlv->length) - TLV_HDRL;
		aln = F_ALN_LEN(EXTRACT_16BITS(&pdtlv->length));
		if (aln > EXTRACT_16BITS(&pdtlv->length)) {
			if (aln > len) {
				ND_PRINT((ndo,
				          "Invalid padded pathdata TLV type 0x%x len %d missing %d pad bytes\n",
				          type, EXTRACT_16BITS(&pdtlv->length), aln - len));
			} else {
				pad = aln - EXTRACT_16BITS(&pdtlv->length);
			}
		}
		if (pd_valid(type)) {
			const struct pdata_ops *ops = get_forces_pd(type);

			if (ndo->ndo_vflag >= 3 && ops->v != F_TLV_PDAT) {
				if (pad)
					ND_PRINT((ndo, "%s  %s (Length %d DataLen %d pad %d Bytes)\n",
					          ib, ops->s, EXTRACT_16BITS(&pdtlv->length), tll, pad));
				else
					ND_PRINT((ndo, "%s  %s (Length %d DataLen %d Bytes)\n",
					          ib, ops->s, EXTRACT_16BITS(&pdtlv->length), tll));
			}

			chk_op_type(ndo, type, op_msk, ops->op_msk);

			if (ops->print(ndo, (const u_char *)pdtlv,
					tll + pad + TLV_HDRL, op_msk,
					indent + 2) == -1)
				return -1;
			len -= (TLV_HDRL + pad + tll);
		} else {
			ND_PRINT((ndo, "Invalid path data content type 0x%x len %d\n",
			       type, EXTRACT_16BITS(&pdtlv->length)));
pd_err:
			if (EXTRACT_16BITS(&pdtlv->length)) {
                                hex_print_with_offset(ndo, "Bad Data val\n\t  [",
						      pptr, len, 0);
				ND_PRINT((ndo, "]\n"));

				return -1;
			}
		}
	}
	return len;

trunc:
	ND_PRINT((ndo, "%s", tstr));
	return -1;
}
예제 #15
0
/*
 * just for completeness
 */
void
hex_print(netdissect_options *ndo,const char *ident, const u_char *cp, u_int length)
{
  hex_print_with_offset(ndo, ident, cp, length, 0);
}
예제 #16
0
int
pdatacnt_print(register const u_char * pptr, register u_int len,
	       u_int16_t IDcnt, u_int16_t op_msk, int indent)
{
	u_int i;
	u_int32_t id;
	char *ib = indent_pr(indent, 0);

	for (i = 0; i < IDcnt; i++) {
		TCHECK2(*pptr, 4);
		if (len < 4)
			goto trunc;
		id = EXTRACT_32BITS(pptr);
		if (vflag >= 3)
			printf("%s  ID#%02u: %d\n", ib, i + 1, id);
		len -= 4;
		pptr += 4;
	}
	if (len) {
		const struct forces_tlv *pdtlv = (struct forces_tlv *)pptr;
		u_int16_t type;
		u_int16_t tll;
		int pad = 0;
		u_int aln;
		int invtlv;

		TCHECK(*pdtlv);
		type = EXTRACT_16BITS(&pdtlv->type);
		invtlv = tlv_valid(pdtlv, len);
		if (invtlv) {
			printf
			    ("%s Outstanding bytes %d for TLV type 0x%x TLV len %d\n",
			     tok2str(ForCES_TLV_err, NULL, invtlv), len, type,
			     EXTRACT_16BITS(&pdtlv->length));
			goto pd_err;
		}
		/*
		 * At this point, tlv_valid() has ensured that the TLV
		 * length is large enough but not too large (it doesn't
		 * go past the end of the containing TLV).
		 */
		tll = EXTRACT_16BITS(&pdtlv->length) - TLV_HDRL;
		aln = F_ALN_LEN(EXTRACT_16BITS(&pdtlv->length));
		if (aln > EXTRACT_16BITS(&pdtlv->length)) {
			if (aln > len) {
				printf
				    ("Invalid padded pathdata TLV type 0x%x len %d missing %d pad bytes\n",
				     type, EXTRACT_16BITS(&pdtlv->length), aln - len);
			} else {
				pad = aln - EXTRACT_16BITS(&pdtlv->length);
			}
		}
		if (pd_valid(type)) {
			const struct pdata_ops *ops = get_forces_pd(type);

			if (vflag >= 3 && ops->v != F_TLV_PDAT) {
				if (pad)
					printf
					    ("%s  %s (Length %d DataLen %d pad %d Bytes)\n",
					     ib, ops->s, EXTRACT_16BITS(&pdtlv->length),
					     tll, pad);
				else
					printf
					    ("%s  %s (Length %d DataLen %d Bytes)\n",
					     ib, ops->s, EXTRACT_16BITS(&pdtlv->length),
					     tll);
			}

			chk_op_type(type, op_msk, ops->op_msk);

			if (ops->print((const u_char *)pdtlv,
					tll + pad + TLV_HDRL, op_msk,
					indent + 2) == -1)
				return -1;
			len -= (TLV_HDRL + pad + tll);
		} else {
			printf("Invalid path data content type 0x%x len %d\n",
			       type, EXTRACT_16BITS(&pdtlv->length));
pd_err:
			if (EXTRACT_16BITS(&pdtlv->length)) {
				hex_print_with_offset("Bad Data val\n\t  [",
						      pptr, len, 0);
				printf("]\n");

				return -1;
			}
		}
	}
	return len;

trunc:
	fputs("[|forces]", stdout);
	return -1;
}
예제 #17
0
/*
 * just for completeness
 */
static void hex_print(DBG * d, register const char *ident, register const u_char * cp, register u_int length)
{
	hex_print_with_offset(d, ident, cp, length, 0);
}