Esempio n. 1
0
/* print a <domain-name> */
static const u_char *
blabel_print(const u_char *cp)
{
	int bitlen, slen, b;
	const u_char *bitp, *lim;
	char tc;

	if (!TTEST2(*cp, 1))
		return(NULL);
	if ((bitlen = *cp) == 0)
		bitlen = 256;
	slen = (bitlen + 3) / 4;
	lim = cp + 1 + slen;

	/* print the bit string as a hex string */
	printf("\\[x");
	for (bitp = cp + 1, b = bitlen; bitp < lim && b > 7; b -= 8, bitp++) {
		TCHECK(*bitp);
		printf("%02x", *bitp);
	}
	if (b > 4) {
		TCHECK(*bitp);
		tc = *bitp++;
		printf("%02x", tc & (0xff << (8 - b)));
	} else if (b > 0) {
		TCHECK(*bitp);
		tc = *bitp++;
		printf("%1x", ((tc >> 4) & 0x0f) & (0x0f << (4 - b)));
	}
Esempio n. 2
0
/*
 * Return a pointer to the first file handle in the packet.
 * If the packet was truncated, return 0.
 */
static const u_int32_t *
parsereq(register const struct sunrpc_msg *rp, register u_int length)
{
	register const u_int32_t *dp;
	register u_int len;

	/*
	 * find the start of the req data (if we captured it)
	 */
	dp = (u_int32_t *)&rp->rm_call.cb_cred;
	TCHECK(dp[1]);
	len = EXTRACT_32BITS(&dp[1]);
	if (len < length) {
		dp += (len + (2 * sizeof(*dp) + 3)) / sizeof(*dp);
		TCHECK(dp[1]);
		len = EXTRACT_32BITS(&dp[1]);
		if (len < length) {
			dp += (len + (2 * sizeof(*dp) + 3)) / sizeof(*dp);
			TCHECK2(dp[0], 0);
			return (dp);
		}
	}
trunc:
	return (NULL);
}
static const u_char *
isakmp_sa_print(const struct isakmp_gen *ext,
		u_int item_len _U_,
		const u_char *ep, u_int32_t phase, u_int32_t doi0 _U_,
		u_int32_t proto0, int depth)
{
	const struct isakmp_pl_sa *p;
	struct isakmp_pl_sa sa;
	const u_int32_t *q;
	u_int32_t doi, sit, ident;
	const u_char *cp, *np;
	int t;

	printf("%s:", NPSTR(ISAKMP_NPTYPE_SA));

	p = (struct isakmp_pl_sa *)ext;
	TCHECK(*p);
	safememcpy(&sa, ext, sizeof(sa));
	doi = ntohl(sa.doi);
	sit = ntohl(sa.sit);
	if (doi != 1) {
		printf(" doi=%d", doi);
		printf(" situation=%u", (u_int32_t)ntohl(sa.sit));
		return (u_char *)(p + 1);
	}

	printf(" doi=ipsec");
	q = (u_int32_t *)&sa.sit;
	printf(" situation=");
	t = 0;
	if (sit & 0x01) {
		printf("identity");
		t++;
	}
	if (sit & 0x02) {
		printf("%ssecrecy", t ? "+" : "");
		t++;
	}
	if (sit & 0x04)
		printf("%sintegrity", t ? "+" : "");

	np = (u_char *)ext + sizeof(sa);
	if (sit != 0x01) {
		TCHECK2(*(ext + 1), sizeof(ident));
		safememcpy(&ident, ext + 1, sizeof(ident));
		printf(" ident=%u", (u_int32_t)ntohl(ident));
		np += sizeof(ident);
	}

	ext = (struct isakmp_gen *)np;
	TCHECK(*ext);

	cp = isakmp_sub_print(ISAKMP_NPTYPE_P, ext, ep, phase, doi, proto0,
		depth);

	return cp;
trunc:
	printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_SA));
	return NULL;
}
Esempio n. 4
0
void
ospf6_print(register const u_char *bp, register u_int length)
{
	register const struct ospf6hdr *op;
	register const u_char *dataend;
	register const char *cp;

	op = (struct ospf6hdr *)bp;

	/* If the type is valid translate it, or just print the type */
	/* value.  If it's not valid, say so and return */
	TCHECK(op->ospf6_type);
	cp = tok2str(ospf6_type_values, "unknown LS-type", op->ospf6_type);
	printf("OSPFv%u, %s, length %d", op->ospf6_version, cp, length);
	if (*cp == 'u') {
		return;
        }

        if(!vflag) { /* non verbose - so lets bail out here */
                return;
        }

	TCHECK(op->ospf6_len);
	if (length != EXTRACT_16BITS(&op->ospf6_len)) {
		printf(" [len %d]", EXTRACT_16BITS(&op->ospf6_len));
		return;
	}
	dataend = bp + length;

	/* Print the routerid if it is not the same as the source */
	TCHECK(op->ospf6_routerid);
	printf("\n\tRouter-ID %s", ipaddr_string(&op->ospf6_routerid));

	TCHECK(op->ospf6_areaid);
	if (op->ospf6_areaid != 0)
		printf(", Area %s", ipaddr_string(&op->ospf6_areaid));
	else
		printf(", Backbone Area");
	TCHECK(op->ospf6_instanceid);
	if (op->ospf6_instanceid)
		printf(", Instance %u", op->ospf6_instanceid);

	/* Do rest according to version.	 */
	switch (op->ospf6_version) {

	case 3:
		/* ospf version 3 */
		if (ospf6_decode_v3(op, dataend))
			goto trunc;
		break;

	default:
		printf(" ospf [version %d]", op->ospf6_version);
		break;
	}			/* end switch on version */

	return;
trunc:
	fputs(tstr, stdout);
}
Esempio n. 5
0
/*
 * Print IPX datagram packets.
 */
void
ipx_print(const u_char *p, u_int length)
{
	const struct ipxHdr *ipx = (const struct ipxHdr *)p;

	if (!eflag)
		printf("IPX ");

	TCHECK(ipx->srcSkt);
	(void)printf("%s.%04x > ",
		     ipxaddr_string(EXTRACT_32BITS(ipx->srcNet), ipx->srcNode),
		     EXTRACT_16BITS(&ipx->srcSkt));

	(void)printf("%s.%04x: ",
		     ipxaddr_string(EXTRACT_32BITS(ipx->dstNet), ipx->dstNode),
		     EXTRACT_16BITS(&ipx->dstSkt));

	/* take length from ipx header */
	TCHECK(ipx->length);
	length = EXTRACT_16BITS(&ipx->length);

	ipx_decode(ipx, (u_char *)ipx + ipxSize, length - ipxSize);
	return;
trunc:
	printf("[|ipx %d]", length);
}
Esempio n. 6
0
void
carp_print(register const u_char *bp, register u_int len, int ttl)
{
	int version, type;
	char *type_s;

	TCHECK(bp[0]);
	version = (bp[0] & 0xf0) >> 4;
	type = bp[0] & 0x0f;
	if (type == 1)
		type_s = "advertise";
	else
		type_s = "unknown";
	printf("CARPv%d-%s %d: ", version, type_s, len);
	if (ttl != 255)
		printf("[ttl=%d!] ", ttl);
	if (version != 2 || type != 1)
		return;
	TCHECK(bp[2]);
	TCHECK(bp[5]);
	printf("vhid=%d advbase=%d advskew=%d demote=%d",
	    bp[1], bp[5], bp[2], bp[4]);
	if (vflag) {
		if (TTEST2(bp[0], len) && in_cksum((const u_short*)bp, len, 0))
			printf(" (bad carp cksum %x!)",
				EXTRACT_16BITS(&bp[6]));
	}
	return;
trunc:
	printf("[|carp]");
}
static const u_char *
isakmp_p_print(const struct isakmp_gen *ext, u_int item_len _U_,
	       const u_char *ep, u_int32_t phase, u_int32_t doi0,
	       u_int32_t proto0 _U_, int depth)
{
	const struct isakmp_pl_p *p;
	struct isakmp_pl_p prop;
	const u_char *cp;

	printf("%s:", NPSTR(ISAKMP_NPTYPE_P));

	p = (struct isakmp_pl_p *)ext;
	TCHECK(*p);
	safememcpy(&prop, ext, sizeof(prop));
	printf(" #%d protoid=%s transform=%d",
		prop.p_no, PROTOIDSTR(prop.prot_id), prop.num_t);
	if (prop.spi_size) {
		printf(" spi=");
		if (!rawprint((caddr_t)(p + 1), prop.spi_size))
			goto trunc;
	}

	ext = (struct isakmp_gen *)((u_char *)(p + 1) + prop.spi_size);
	TCHECK(*ext);

	cp = isakmp_sub_print(ISAKMP_NPTYPE_T, ext, ep, phase, doi0,
		prop.prot_id, depth);

	return cp;
trunc:
	printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_P));
	return NULL;
}
Esempio n. 8
0
static int 
print_report(register const u_char *bp, register const u_char *ep,
    register u_int len)
{
	register u_int32_t mask, origin;
	register int metric, done;
	register u_int i, width;

	while (len > 0) {
		if (len < 3) {
			printf(" [|]");
			return (0);
		}
		TCHECK2(bp[0], 3);
		mask = (u_int32_t)0xff << 24 | bp[0] << 16 | bp[1] << 8 | bp[2];
		width = 1;
		if (bp[0])
			width = 2;
		if (bp[1])
			width = 3;
		if (bp[2])
			width = 4;

		printf("\n\tMask %s", intoa(htonl(mask)));
		bp += 3;
		len -= 3;
		do {
			if (bp + width + 1 > ep) {
				printf(" [|]");
				return (0);
			}
			if (len < width + 1) {
				printf("\n\t  [Truncated Report]");
				return (0);
			}
			origin = 0;
			for (i = 0; i < width; ++i) {
				TCHECK(*bp);
				origin = origin << 8 | *bp++;
			}
			for ( ; i < 4; ++i)
				origin <<= 8;

			TCHECK(*bp);
			metric = *bp++;
			done = metric & 0x80;
			metric &= 0x7f;
			printf("\n\t  %s metric %d", intoa(htonl(origin)),
				metric);
			len -= width + 1;
		} while (!done);
	}
	return (0);
trunc:
	return (-1);
}
void
ospf6_print(register const u_char *bp, register u_int length)
{
	register const struct ospf6hdr *op;
	register const u_char *dataend;
	register const char *cp;

	op = (struct ospf6hdr *)bp;

	/* If the type is valid translate it, or just print the type */
	/* value.  If it's not valid, say so and return */
	TCHECK(op->ospf6_type);
	cp = tok2str(type2str, "type%d", op->ospf6_type);
	printf("OSPFv%d-%s %d:", op->ospf6_version, cp, length);
	if (*cp == 't')
		return;

	TCHECK(op->ospf6_len);
	if (length != EXTRACT_16BITS(&op->ospf6_len)) {
		printf(" [len %d]", EXTRACT_16BITS(&op->ospf6_len));
		return;
	}
	dataend = bp + length;

	/* Print the routerid if it is not the same as the source */
	TCHECK(op->ospf6_routerid);
	printf(" rtrid %s", ipaddr_string(&op->ospf6_routerid));

	TCHECK(op->ospf6_areaid);
	if (op->ospf6_areaid != 0)
		printf(" area %s", ipaddr_string(&op->ospf6_areaid));
	else
		printf(" backbone");
	TCHECK(op->ospf6_instanceid);
	if (op->ospf6_instanceid)
		printf(" instance %u", op->ospf6_instanceid);

	/* Do rest according to version.	 */
	switch (op->ospf6_version) {

	case 3:
		/* ospf version 3 */
		if (ospf6_decode_v3(op, dataend))
			goto trunc;
		break;

	default:
		printf(" ospf [version %d]", op->ospf6_version);
		break;
	}			/* end switch on version */

	return;
trunc:
	fputs(tstr, stdout);
}
Esempio n. 10
0
void
vrrp_print(register const u_char *bp, register u_int len, int ttl)
{
    int version, type, auth_type;
    const char *type_s;

    TCHECK(bp[0]);
    version = (bp[0] & 0xf0) >> 4;
    type = bp[0] & 0x0f;
    type_s = tok2str(type2str, "unknown type (%u)", type);
    printf("VRRPv%u, %s", version, type_s);
    if (ttl != 255)
        printf(", (ttl %u)", ttl);
    if (version != 2 || type != VRRP_TYPE_ADVERTISEMENT)
        return;
    TCHECK(bp[2]);
    printf(", vrid %u, prio %u", bp[1], bp[2]);
    TCHECK(bp[5]);
    auth_type = bp[4];
    printf(", authtype %s", tok2str(auth2str, NULL, auth_type));
    printf(", intvl %us, length %u", bp[5],len);
    if (vflag) {
        int naddrs = bp[3];
        int i;
        char c;

        if (TTEST2(bp[0], len) && in_cksum((const u_short*)bp, len, 0))
            printf(", (bad vrrp cksum %x)",
                   EXTRACT_16BITS(&bp[6]));
        printf(", addrs");
        if (naddrs > 1)
            printf("(%d)", naddrs);
        printf(":");
        c = ' ';
        bp += 8;
        for (i = 0; i < naddrs; i++) {
            TCHECK(bp[3]);
            printf("%c%s", c, ipaddr_string(bp));
            c = ',';
            bp += 4;
        }
        if (auth_type == VRRP_AUTH_SIMPLE) { /* simple text password */
            TCHECK(bp[7]);
            printf(" auth \"");
            if (fn_printn(bp, 8, snapend)) {
                printf("\"");
                goto trunc;
            }
            printf("\"");
        }
    }
    return;
trunc:
    printf("[|vrrp]");
}
Esempio n. 11
0
static int
ospf_print_lshdr(register const struct lsa_hdr *lshp)
{
        u_int ls_length;

        TCHECK(lshp->ls_length);
        ls_length = EXTRACT_16BITS(&lshp->ls_length);
        if (ls_length < sizeof(struct lsa_hdr)) {
                printf("\n\t    Bogus length %u < %lu", ls_length,
                    (unsigned long)sizeof(struct lsa_hdr));
                return(-1);
        }

        TCHECK(lshp->ls_seq);	/* XXX - ls_length check checked this */
	printf("\n\t  Advertising Router: %s, seq 0x%08x, age %us, length: %u",
	       ipaddr_string(&lshp->ls_router),
	       EXTRACT_32BITS(&lshp->ls_seq),
	       EXTRACT_16BITS(&lshp->ls_age),
               ls_length-(u_int)sizeof(struct lsa_hdr));

	TCHECK(lshp->ls_type);	/* XXX - ls_length check checked this */
        switch (lshp->ls_type) {
	/* the LSA header for opaque LSAs was slightly changed */
        case LS_TYPE_OPAQUE_LL:
        case LS_TYPE_OPAQUE_AL:
        case LS_TYPE_OPAQUE_DW:
            printf("\n\t    %s LSA (%d), Opaque-Type: %s LSA (%u), Opaque-ID: %u",
                   tok2str(lsa_values,"unknown",lshp->ls_type),
                   lshp->ls_type,

		   tok2str(lsa_opaque_values,
			   "unknown",
			   *(&lshp->un_lsa_id.opaque_field.opaque_type)),
		   *(&lshp->un_lsa_id.opaque_field.opaque_type),
		   EXTRACT_24BITS(&lshp->un_lsa_id.opaque_field.opaque_id)
                   
                   );
            break;

	/* all other LSA types use regular style LSA headers */
	default:
            printf("\n\t    %s LSA (%d), LSA-ID: %s",
                   tok2str(lsa_values,"unknown",lshp->ls_type),
                   lshp->ls_type,
                   ipaddr_string(&lshp->un_lsa_id.lsa_id));
            break;
        }

	TCHECK(lshp->ls_options);	/* XXX - ls_length check checked this */
        printf("\n\t    Options: [%s]", bittok2str(ospf_option_values,"none",lshp->ls_options));

        return (ls_length);
trunc:
	return (-1);
}
Esempio n. 12
0
/*
 * RFC 2338:
 *     0                   1                   2                   3
 *     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *    |Version| Type  | Virtual Rtr ID|   Priority    | Count IP Addrs|
 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *    |   Auth Type   |   Adver Int   |          Checksum             |
 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *    |                         IP Address (1)                        |
 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *    |                            .                                  |
 *    |                            .                                  |
 *    |                            .                                  |
 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *    |                         IP Address (n)                        |
 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *    |                     Authentication Data (1)                   |
 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *    |                     Authentication Data (2)                   |
 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 */
void
vrrp_print(register const u_char *bp, register u_int len, int ttl)
{
	int version, type, auth_type;
	char *type_s;

	TCHECK(bp[0]);
	version = (bp[0] & 0xf0) >> 4;
	type = bp[0] & 0x0f;
	if (type == 1)
		type_s = "advertise";
	else
		type_s = "unknown";
	printf("VRRPv%d-%s %d: ", version, type_s, len);
	if (ttl != 255)
		printf("[ttl=%d!] ", ttl);
	if (version != 2 || type != 1)
		return;
	TCHECK(bp[2]);
	printf("vrid=%d prio=%d", bp[1], bp[2]);
	TCHECK(bp[5]);
	auth_type = bp[4];
	if (auth_type != 0)
		printf(" authtype=%d", auth_type);
	printf(" intvl=%d", bp[5]);
	if (vflag) {
		int naddrs = bp[3];
		int i;
		char c;

		if (TTEST2(bp[0], len) && in_cksum((const u_short*)bp, len, 0))
			printf(" (bad vrrp cksum %x!)",
				EXTRACT_16BITS(&bp[6]));
		printf(" addrs");
		if (naddrs > 1)
			printf("(%d)", naddrs);
		printf(":");
		c = ' ';
		bp += 8;
		for (i = 0; i < naddrs; i++) {
			TCHECK(bp[3]);
			printf("%c%s", c, ipaddr_string(bp));
			c = ',';
			bp += 4;
		}
		if (auth_type == 1) { /* simple text password */
			TCHECK(bp[7]);
			printf(" auth %.8s", bp);
		}
	}
	return;
trunc:
	printf("[|vrrp]");
}
Esempio n. 13
0
void
ipx_sap_print(const u_short *ipx, u_int length)
{
    int command, i;

    TCHECK(ipx[0]);
    command = EXTRACT_16BITS(ipx);
    ipx++;
    length -= 2;

    switch (command) {
      case 1:
      case 3:
	if (command == 1)
	    (void)printf("ipx-sap-req");
	else
	    (void)printf("ipx-sap-nearest-req");

	TCHECK(ipx[0]);
	(void)printf(" %s", ipxsap_string(htons(EXTRACT_16BITS(&ipx[0]))));
	break;

      case 2:
      case 4:
	if (command == 2)
	    (void)printf("ipx-sap-resp");
	else
	    (void)printf("ipx-sap-nearest-resp");

	for (i = 0; i < 8 && length > 0; i++) {
	    TCHECK(ipx[0]);
	    (void)printf(" %s '", ipxsap_string(htons(EXTRACT_16BITS(&ipx[0]))));
	    if (fn_printzp((u_char *)&ipx[1], 48, snapend)) {
		printf("'");
		goto trunc;
	    }
	    TCHECK2(ipx[25], 10);
	    printf("' addr %s",
		ipxaddr_string(EXTRACT_32BITS(&ipx[25]), (u_char *)&ipx[27]));
	    ipx += 32;
	    length -= 64;
	}
	break;
      default:
	(void)printf("ipx-sap-?%x", command);
	break;
    }
    return;
trunc:
    printf("[|ipx %d]", length);
}
Esempio n. 14
0
/*
 * Decoding routines for GTP version 0.
 */
void
gtp_v0_print(const u_char *cp, u_int length, u_short sport, u_short dport)
{
    struct gtp_v0_hdr *gh = (struct gtp_v0_hdr *)cp;
    int len, version;
    u_int64_t tid;

    gtp_proto = GTP_V0_PROTO;

    /* Check if this is GTP prime. */
    TCHECK(gh->flags);
    if ((gh->flags & GTPV0_HDR_PROTO_TYPE) == 0) {
        gtp_proto = GTP_V0_PRIME_PROTO;
        gtp_v0_print_prime(cp);
        return;
    }

    /* Print GTP header. */
    TCHECK(*gh);
    cp += sizeof(struct gtp_v0_hdr);
    len = ntohs(gh->length);
    bcopy(&gh->tid, &tid, sizeof(tid));
    printf(" GTPv0 (len %u, seqno %u, flow %u, N-PDU %u, tid 0x%llx) ",
           ntohs(gh->length), ntohs(gh->seqno), ntohs(gh->flow),
           ntohs(gh->npduno), betoh64(tid));

    /* Decode GTP message. */
    printf("%s", tok2str(gtp_v0_msgtype, "Message Type %u", gh->msgtype));

    if (!vflag)
        return;

    if (gh->msgtype == GTPV0_T_PDU) {

        TCHECK(cp[0]);
        version = cp[0] >> 4;

        printf(" { ");

        if (version == 4)
            ip_print(cp, len);
#ifdef INET6
        else if (version == 6)
            ip6_print(cp, len);
#endif
        else
            printf("Unknown IP version %u", version);

        printf(" }");
    } else
Esempio n. 15
0
int
sdatatlv_print(register const u_char * pptr, register u_int len,
	       u_int16_t op_msk, 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() has ensured that len (the TLV length)
	 * >= TLV_HDRL.
	 */
	rlen = len - TLV_HDRL;
	TCHECK(*tlv);
	type = EXTRACT_16BITS(&tlv->type);
	if (type != F_TLV_SPAD) {
		printf("Error: expecting SPARSEDATA!\n");
		return -1;
	}

	return sdatailv_print(tdp, rlen, op_msk, indent);

trunc:
	fputs("[|forces]", stdout);
	return -1;
}
Esempio n. 16
0
static int
ospf6_print_lsaprefix(register const struct lsa6_prefix *lsapp)
{
	u_int wordlen;
	struct in6_addr prefix;

	TCHECK(*lsapp);
	wordlen = (lsapp->lsa_p_len + 31) / 32;
	if (wordlen * 4 > sizeof(struct in6_addr)) {
		printf(" bogus prefixlen /%d", lsapp->lsa_p_len);
		goto trunc;
	}
	memset(&prefix, 0, sizeof(prefix));
	memcpy(&prefix, lsapp->lsa_p_prefix, wordlen * 4);
	printf("\n\t\t%s/%d", ip6addr_string(&prefix),
		lsapp->lsa_p_len);
        if (lsapp->lsa_p_opt) {
            printf(", Options [%s]",
                   bittok2str(ospf6_lsa_prefix_option_values,
                              "none", lsapp->lsa_p_opt));
        }
        printf(", metric %u", EXTRACT_16BITS(&lsapp->lsa_p_metric));
	return sizeof(*lsapp) - 4 + wordlen * 4;

trunc:
	return -1;
}
Esempio n. 17
0
/*
 * Print out a file name and return pointer to 32-bit word past it.
 * If packet was truncated, return 0.
 */
static const u_int32_t *
parsefn(register const u_int32_t *dp)
{
	register u_int32_t len;
	register const u_char *cp;

	/* Bail if we don't have the string length */
	TCHECK(*dp);

	/* Fetch string length; convert to host order */
	len = *dp++;
	NTOHL(len);

	TCHECK2(*dp, ((len + 3) & ~3));

	cp = (u_char *)dp;
	/* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
	dp += ((len + 3) & ~3) / sizeof(*dp);
	putchar('"');
	if (fn_printn(cp, len, snapend)) {
		putchar('"');
		goto trunc;
	}
	putchar('"');

	return (dp);
trunc:
	return NULL;
}
Esempio n. 18
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;
}
Esempio n. 19
0
static int
parsepathconf(const u_int32_t *dp)
{
	int er;
	struct nfsv3_pathconf *spp;

	if (!(dp = parsestatus(dp, &er)))
		return (0);
	if (vflag)
		printf(" POST:");
	if (!(dp = parse_post_op_attr(dp, vflag)))
		return (0);
	if (er)
		return (1);

	spp = (struct nfsv3_pathconf *)dp;
	TCHECK(*spp);

	printf(" linkmax %u namemax %u %s %s %s %s",
	       EXTRACT_32BITS(&spp->pc_linkmax),
	       EXTRACT_32BITS(&spp->pc_namemax),
	       EXTRACT_32BITS(&spp->pc_notrunc) ? "notrunc" : "",
	       EXTRACT_32BITS(&spp->pc_chownrestricted) ? "chownres" : "",
	       EXTRACT_32BITS(&spp->pc_caseinsensitive) ? "igncase" : "",
	       EXTRACT_32BITS(&spp->pc_casepreserving) ? "keepcase" : "");
	return (1);
trunc:
	return (0);
}
Esempio n. 20
0
static const u_int32_t *
parsecreateopres(const u_int32_t *dp, int verbose)
{
	int er;

	if (!(dp = parsestatus(dp, &er)))
		return (0);
	if (er)
		dp = parse_wcc_data(dp, verbose);
	else {
		TCHECK(dp[0]);
		if (!EXTRACT_32BITS(&dp[0]))
			return (dp + 1);
		dp++;
		if (!(dp = parsefh(dp, 1)))
			return (0);
		if (verbose) {
			if (!(dp = parse_post_op_attr(dp, verbose)))
				return (0);
			if (vflag > 1) {
				printf(" dir attr:");
				dp = parse_wcc_data(dp, verbose);
			}
		}
	}
	return (dp);
trunc:
	return (NULL);
}
Esempio n. 21
0
static int
ospf6_print_lshdr(register const struct lsa_hdr *lshp)
{

	TCHECK(lshp->ls_type);
	printf(" {");						/* } (ctags) */

	TCHECK(lshp->ls_seq);
	ospf6_print_seqage(EXTRACT_32BITS(&lshp->ls_seq), EXTRACT_16BITS(&lshp->ls_age));
	ospf6_print_ls_type(EXTRACT_16BITS(&lshp->ls_type), &lshp->ls_stateid,
		&lshp->ls_router, "ls_type %d");

	return (0);
trunc:
	return (1);
}
Esempio n. 22
0
static int
ospf6_print_lsaprefix(register const struct lsa_prefix *lsapp)
{
	u_int k;
	struct in6_addr prefix;

	TCHECK(*lsapp);
	k = (lsapp->lsa_p_len + 31) / 32;
	if (k * 4 > sizeof(struct in6_addr)) {
		printf("??prefixlen %d??", lsapp->lsa_p_len);
		goto trunc;
	}
	memset(&prefix, 0, sizeof(prefix));
	memcpy(&prefix, lsapp->lsa_p_prefix, k * 4);
	printf(" %s/%d", ip6addr_string(&prefix),
		lsapp->lsa_p_len);
	if (lsapp->lsa_p_opt)
		printf("(opt=%x)", lsapp->lsa_p_opt);
	if (lsapp->lsa_p_mbz)
		printf("(mbz=%x)", EXTRACT_16BITS(&lsapp->lsa_p_mbz)); /* XXX */
	return sizeof(*lsapp) - 4 + k * 4;

trunc:
	return -1;
}
static void
cmu_print(register const u_char *bp)
{
	register const struct cmu_vend *cmu;

#define PRINTCMUADDR(m, s) { TCHECK(cmu->m); \
    if (cmu->m.s_addr != 0) \
	printf(" %s:%s", s, ipaddr_string(&cmu->m.s_addr)); }

	printf(" vend-cmu");
	cmu = (const struct cmu_vend *)bp;

	/* Only print if there are unknown bits */
	TCHECK(cmu->v_flags);
	if ((cmu->v_flags & ~(VF_SMASK)) != 0)
		printf(" F:0x%x", cmu->v_flags);
	PRINTCMUADDR(v_dgate, "DG");
	PRINTCMUADDR(v_smask, cmu->v_flags & VF_SMASK ? "SM" : "SM*");
	PRINTCMUADDR(v_dns1, "NS1");
	PRINTCMUADDR(v_dns2, "NS2");
	PRINTCMUADDR(v_ins1, "IEN1");
	PRINTCMUADDR(v_ins2, "IEN2");
	PRINTCMUADDR(v_ts1, "TS1");
	PRINTCMUADDR(v_ts2, "TS2");
	return;

trunc:
	fputs(tstr, stdout);
#undef PRINTCMUADDR
}
Esempio n. 24
0
void
nfsreq_print(register const u_char *bp, u_int length,
    register const u_char *bp2)
{
	register const struct sunrpc_msg *rp;
	char srcid[20], dstid[20];	/*fits 32bit*/

	nfserr = 0;		/* assume no error */
	rp = (const struct sunrpc_msg *)bp;

	TCHECK(rp->rm_xid);
	if (!nflag) {
		snprintf(srcid, sizeof(srcid), "%u",
		    EXTRACT_32BITS(&rp->rm_xid));
		strlcpy(dstid, "nfs", sizeof(dstid));
	} else {
		snprintf(srcid, sizeof(srcid), "%u",
		    EXTRACT_32BITS(&rp->rm_xid));
		snprintf(dstid, sizeof(dstid), "%u", NFS_PORT);
	}
	print_nfsaddr(bp2, srcid, dstid);
	(void)printf("%d", length);

	nfsreq_print_noaddr(bp, length, bp2);
	return;

trunc:
	if (!nfserr)
		printf("%s", tstr);
}
Esempio n. 25
0
int
ah_print(register const u_char *bp)
{
    register const struct ah *ah;
    register const u_char *ep;
    int sumlen;
    u_int32_t spi;

    ah = (const struct ah *)bp;
    ep = snapend;		/* 'ep' points to the end of available data. */

    TCHECK(*ah);

    sumlen = ah->ah_len << 2;
    spi = EXTRACT_32BITS(&ah->ah_spi);

    printf("AH(spi=0x%08x", spi);
    if (vflag)
        printf(",sumlen=%d", sumlen);
    printf(",seq=0x%x", EXTRACT_32BITS(ah + 1));
    if (bp + sizeof(struct ah) + sumlen > ep)
        fputs("[truncated]", stdout);
    fputs("): ", stdout);

    return sizeof(struct ah) + sumlen;
trunc:
    fputs("[|AH]", stdout);
    return -1;
}
Esempio n. 26
0
/*
 * Decode and print information elements from message. The actual work is
 * handled in the appropriate Tag/Value (TV) or Tag/Length/Value (TLV)
 * decoding routine.
 */
void
gtp_decode_ie(register const u_char *cp, u_short version, int len)
{
    int val, ielen, iecount = 0;

    if (len <= 0)
        return;

    printf(" {");

    while (len > 0) {

        iecount++;
        if (iecount > 1)
            printf(" ");

        TCHECK(cp[0]);
        val = (u_int)cp[0];
        cp++;

        printf("[");

        switch (version) {
        case GTP_VERSION_0:
            if ((val & GTPV0_IE_TYPE_MASK) == 0)
                ielen = gtp_v0_print_tv(cp, val);
            else
                ielen = gtp_v0_print_tlv(cp, val);
            break;

        case GTP_VERSION_1:
            if ((val & GTPV1_IE_TYPE_MASK) == 0)
                ielen = gtp_v1_print_tv(cp, val);
            else
                ielen = gtp_v1_print_tlv(cp, val);
            break;

        default:
            /* Version not supported... */
            ielen = -1;
            break;
        }

        printf("]");

        if (ielen < 0)
            goto trunc;

        len -= ielen;
        cp += ielen - 1;
    }

    if (iecount > 0)
        printf("}");

    return;

trunc:
    printf(" [|%s]", tok2str(gtp_type, "GTP", gtp_proto));
}
Esempio n. 27
0
static void
radius_attrs_print(register const u_char *attr, u_int length)
{
   register const struct radius_attr *rad_attr = (struct radius_attr *)attr;
   const char *attr_string;

   while (length > 0)
   {
     if (length < 2)
        goto trunc;
     TCHECK(*rad_attr);
     
     if (rad_attr->type > 0 && rad_attr->type < TAM_SIZE(attr_type))
	attr_string = attr_type[rad_attr->type].name;
     else
	attr_string = "Unknown";
     if (rad_attr->len < 2)
     {
	printf("\n\t  %s Attribute (%u), length: %u (bogus, must be >= 2)",
               attr_string,
               rad_attr->type,
               rad_attr->len);
	return;
     }
     if (rad_attr->len > length)
     {
	printf("\n\t  %s Attribute (%u), length: %u (bogus, goes past end of packet)",
               attr_string,
               rad_attr->type,
               rad_attr->len);
        return;
     }
     printf("\n\t  %s Attribute (%u), length: %u, Value: ",
            attr_string,
            rad_attr->type,
            rad_attr->len);

     if (rad_attr->type < TAM_SIZE(attr_type))
     {
         if (rad_attr->len > 2)
         {
             if ( attr_type[rad_attr->type].print_func )
                 (*attr_type[rad_attr->type].print_func)(
                     ((u_char *)(rad_attr+1)),
                     rad_attr->len - 2, rad_attr->type);
         }
     }
     /* do we also want to see a hex dump ? */
     if (vflag> 1)
         print_unknown_data((u_char *)rad_attr+2,"\n\t    ",(rad_attr->len)-2);

     length-=(rad_attr->len);
     rad_attr = (struct radius_attr *)( ((char *)(rad_attr))+rad_attr->len);
   }
   return;

trunc:
   printf(" [|radius]");
}
Esempio n. 28
0
static int
ospf_print_lshdr(register const struct lsa_hdr *lshp)
{

	TCHECK(lshp->ls_type);
	printf(" {");						/* } (ctags) */

	TCHECK(lshp->ls_options);
	ospf_print_bits(ospf_option_bits, lshp->ls_options);
	TCHECK(lshp->ls_seq);
	ospf_print_seqage(ntohl(lshp->ls_seq), ntohs(lshp->ls_age));
	ospf_print_ls_type(lshp->ls_type, &lshp->ls_stateid, &lshp->ls_router,
	    "ls_type %d");

	return (0);
trunc:
	return (1);
}
Esempio n. 29
0
void
lwapp_data_print(const u_char *pptr, u_int len) {

    const struct lwapp_transport_header *lwapp_trans_header;
    const u_char *tptr;
    int tlen;

    tptr=pptr;

    /* check if enough bytes for AP identity */
    if (!TTEST2(*tptr, 6))
        goto trunc;
    lwapp_trans_header = (const struct lwapp_transport_header *)pptr;
    TCHECK(*lwapp_trans_header);

    /*
     * Sanity checking of the header.
     */
    if (LWAPP_EXTRACT_VERSION(lwapp_trans_header->version) != LWAPP_VERSION) {
        printf("LWAPP version %u packet not supported",
               LWAPP_EXTRACT_VERSION(lwapp_trans_header->version));
        return;
    }

    /* non-verbose */
    if (vflag < 1) {
        printf("LWAPPv%u, %s frame, Flags [%s], length %u",
               LWAPP_EXTRACT_VERSION(lwapp_trans_header->version),
               LWAPP_EXTRACT_CONTROL_BIT(lwapp_trans_header->version) ? "Control" : "Data",
               bittok2str(lwapp_header_bits_values,"none",(lwapp_trans_header->version)&0x07),
               len);
        return;
    }

    /* ok they seem to want to know everything - lets fully decode it */
    tlen=EXTRACT_16BITS(lwapp_trans_header->length);

    printf("LWAPPv%u, %s frame, Radio-id  %u, Flags [%s], Frag-id  %u, length %u",
           LWAPP_EXTRACT_VERSION(lwapp_trans_header->version),
           LWAPP_EXTRACT_CONTROL_BIT(lwapp_trans_header->version) ? "Control" : "Data",
           LWAPP_EXTRACT_RID(lwapp_trans_header->version),
           bittok2str(lwapp_header_bits_values,"none",(lwapp_trans_header->version)&0x07),
           lwapp_trans_header->frag_id,
           tlen);

    tptr+=sizeof(const struct lwapp_transport_header);
    tlen-=sizeof(const struct lwapp_transport_header);

    /* FIX - An IEEE 802.11 frame follows - hexdump for now */
    print_unknown_data(tptr, "\n\t", tlen);

    return;

 trunc:
    printf("\n\t\t packet exceeded snapshot");
}
Esempio n. 30
0
    void Condition::waitTimeout(uint32_t second)
    {
        struct timespec abstime;
        clock_gettime(CLOCK_REALTIME, &abstime);

        abstime.tv_sec += second;
        abstime.tv_nsec += 0;

        TCHECK(pthread_cond_timedwait(&cond_, &mutexlock_.getMutex(), &abstime));
    }