void relocInfo::set_type(relocType t) { int old_offset = addr_offset(); int old_format = format(); (*this) = relocInfo(t, old_offset, old_format); assert(type()==(int)t, "sanity check"); assert(addr_offset()==old_offset, "sanity check"); assert(format()==old_format, "sanity check"); }
static void do_parse_addrs(const cdp_data *d, char *data, size_t len) { struct cdp_addrs *as = (struct cdp_addrs *)data; if (sizeof as->cnt > len) return; as->cnt = ntohl(as->cnt); printf("%s %u as->cnt=%lu\n", __func__, __LINE__, (unsigned long)as->cnt); if (as->cnt > 0 && len >= CDP_ADDR_MINBYTES) { struct cdp_addr *a = &as->addr; struct cdp_addr_addr *aa = (struct cdp_addr_addr *)((char *)a + addr_offset(a, len, 1)); aa->len = ntohs(aa->len); } }
static size_t do_dump_addrs(const cdp_data *d, const char *data, size_t len, FILE *out) { struct cdp_addrs *as = (struct cdp_addrs *)data; u32 cnt = as->cnt; int bytes = fprintf(out, "cnt=%lu", (unsigned long)as->cnt); assert(cnt < 5); while (cnt--) { const struct cdp_addr *a = (struct cdp_addr *)&as->addr; bytes += fprintf(out, "(type=%u len=%u", a->type, a->len); if (1 == a->len && Addr_Type_NLPID == a->type && Addr_Prot_IP == a->prot.nlpid) { struct cdp_addr_addr *aa = (struct cdp_addr_addr *)((char *)a + sizeof a->type + sizeof a->len + sizeof a->prot.nlpid); if (4 == aa->len) { const u8 *ip = (u8 *)aa->data; bytes += fprintf(out, " ip=%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]); } } fputc(')', out); bytes++; a = (struct cdp_addr *)((char *)a + addr_offset(a, len - ((char *)a - data), 0)); } return (size_t)bytes; }
void relocInfo::set_format(int f) { int old_offset = addr_offset(); assert((f & format_mask) == f, "wrong format"); _value = (_value & ~(format_mask << offset_width)) | (f << offset_width); assert(addr_offset()==old_offset, "sanity check"); }