/* Try to find the size of the ASs encoded in an as-path. It is not obvious, as both Old speakers that do not support 4 byte AS, and the new speakers that do support, exchange AS-Path with the same path-attribute type value 0x02.  */
static int bgp_attr_get_as_size(netdissect_options *ndo, uint8_t bgpa_type, const u_char *pptr, int len)
/* Try to find the size of the ASs encoded in an as-path. It is not obvious, as both Old speakers that do not support 4 byte AS, and the new speakers that do support, exchange AS-Path with the same path-attribute type value 0x02.  */
static int bgp_attr_get_as_size(netdissect_options *ndo, uint8_t bgpa_type, const u_char *pptr, int len)
{
    const u_char *tptr = pptr;
    if (bgpa_type == BGPTYPE_AS4_PATH) {
        return 4;
    }
    while (tptr < pptr + len) {
        ND_TCHECK(tptr[0]);
        if (tptr[0] < BGP_AS_SEG_TYPE_MIN || tptr[0] > BGP_AS_SEG_TYPE_MAX) {
            goto trunc;
        }
        ND_TCHECK(tptr[1]);
        tptr += 2 + tptr[1] * 2;
    }
    if (tptr == pptr + len) {
        return 2;
    }
trunc:
   return 4;
}