bool auth_attr_addr::deserialize_body(NetMsg &msg, coding_t coding, uint16 body_length, IEErrorList &err, uint32 &bytes_read, bool skip) { uint32 start_pos = msg.get_pos(); // Error: Message is shorter than the length field makes us believe. if ( msg.get_bytes_left() < body_length ) { catch_bad_alloc( err.put(new IEMsgTooShort(coding, category, start_pos)) ); msg.set_pos(start_pos); return false; } if(sub_type==IPV4_ADDRESS){ struct in_addr tmp_ip; msg.decode(tmp_ip); ip.set_ip(tmp_ip); bytes_read = 4; }else{ struct in6_addr tmp_ip; msg.decode(tmp_ip); ip.set_ip(tmp_ip); bytes_read = 16; } // Error: We expected the length field to be different. if ( (body_length + HEADER_LENGTH) !=(uint32) get_serialized_size_nopadding(coding) || body_length!= bytes_read) { catch_bad_alloc( err.put( new IEWrongLength(coding, get_category(), get_xtype(), get_subtype(), msg.get_pos())) ); msg.set_pos(start_pos); return false; } return true; }
int main(void) { const unsigned int FrameLen = 36; unsigned char *macframe = malloc(FrameLen); // alloc MAC header until frame body // fill header with junk, to make this more interesting for (unsigned int i = 0; i < FrameLen; i++) { macframe[i] = 0xde; } set_proto_version(macframe, 0); set_type(macframe, 1); set_subtype(macframe, 1); set_to_ds(macframe, 1); set_from_ds(macframe, 0); set_retry(macframe, 0); set_more_data(macframe, 0); print_header(macframe); printf("Protocol version: %d\n", get_proto_version(macframe)); printf("Type: %d\n", get_type(macframe)); printf("Subtype: %d\n", get_subtype(macframe)); printf("Flags: To DS: %d From DS: %d Retry: %d More Data: %d\n", get_to_ds(macframe) != 0, get_from_ds(macframe) != 0, get_retry(macframe) != 0, get_more_data(macframe) != 0); free(macframe); }
bool type::operator==(const type &lhs) const { if( ty == lhs.ty ) { if( ty == 4 ) { if( !subtype ) if( !lhs.subtype ) if( get_subtype() == lhs.get_subtype() ) return true; } else return true; // types are equal, and not arrays } return false; }
static isc_result_t parse_geoip_element(const cfg_obj_t *obj, isc_log_t *lctx, cfg_aclconfctx_t *ctx, dns_aclelement_t *dep) { const cfg_obj_t *ge; const char *dbname = NULL; const char *stype, *search; dns_geoip_subtype_t subtype; dns_aclelement_t de; size_t len; REQUIRE(dep != NULL); de = *dep; ge = cfg_tuple_get(obj, "db"); if (!cfg_obj_isvoid(ge)) dbname = cfg_obj_asstring(ge); stype = cfg_obj_asstring(cfg_tuple_get(obj, "subtype")); search = cfg_obj_asstring(cfg_tuple_get(obj, "search")); len = strlen(search); if (len == 0) { cfg_obj_log(obj, lctx, ISC_LOG_ERROR, "zero-length geoip search field"); return (ISC_R_FAILURE); } if (strcasecmp(stype, "country") == 0 && len == 2) { /* Two-letter country code */ subtype = dns_geoip_countrycode; strlcpy(de.geoip_elem.as_string, search, sizeof(de.geoip_elem.as_string)); } else if (strcasecmp(stype, "country") == 0 && len == 3) { /* Three-letter country code */ subtype = dns_geoip_countrycode3; strlcpy(de.geoip_elem.as_string, search, sizeof(de.geoip_elem.as_string)); } else if (strcasecmp(stype, "country") == 0) { /* Country name */ subtype = dns_geoip_countryname; strlcpy(de.geoip_elem.as_string, search, sizeof(de.geoip_elem.as_string)); } else if (strcasecmp(stype, "region") == 0 && len == 2) { /* Two-letter region code */ subtype = dns_geoip_region; strlcpy(de.geoip_elem.as_string, search, sizeof(de.geoip_elem.as_string)); } else if (strcasecmp(stype, "region") == 0) { /* Region name */ subtype = dns_geoip_regionname; strlcpy(de.geoip_elem.as_string, search, sizeof(de.geoip_elem.as_string)); } else if (strcasecmp(stype, "city") == 0) { /* City name */ subtype = dns_geoip_city_name; strlcpy(de.geoip_elem.as_string, search, sizeof(de.geoip_elem.as_string)); } else if (strcasecmp(stype, "postal") == 0 || strcasecmp(stype, "postalcode") == 0) { if (len < 7) { subtype = dns_geoip_city_postalcode; strlcpy(de.geoip_elem.as_string, search, sizeof(de.geoip_elem.as_string)); } else { cfg_obj_log(obj, lctx, ISC_LOG_ERROR, "geoiop postal code (%s) too long", search); return (ISC_R_FAILURE); } } else if (strcasecmp(stype, "metro") == 0 || strcasecmp(stype, "metrocode") == 0) { subtype = dns_geoip_city_metrocode; de.geoip_elem.as_int = atoi(search); } else if (strcasecmp(stype, "area") == 0 || strcasecmp(stype, "areacode") == 0) { subtype = dns_geoip_city_areacode; de.geoip_elem.as_int = atoi(search); } else if (strcasecmp(stype, "tz") == 0 || strcasecmp(stype, "timezone") == 0) { subtype = dns_geoip_city_timezonecode; strlcpy(de.geoip_elem.as_string, search, sizeof(de.geoip_elem.as_string)); } else if (strcasecmp(stype, "continent") == 0 && len == 2) { /* Two-letter continent code */ subtype = dns_geoip_city_continentcode; strlcpy(de.geoip_elem.as_string, search, sizeof(de.geoip_elem.as_string)); } else if (strcasecmp(stype, "continent") == 0) { cfg_obj_log(obj, lctx, ISC_LOG_ERROR, "geoiop continent code (%s) too long", search); return (ISC_R_FAILURE); } else if (strcasecmp(stype, "isp") == 0) { subtype = dns_geoip_isp_name; strlcpy(de.geoip_elem.as_string, search, sizeof(de.geoip_elem.as_string)); } else if (strcasecmp(stype, "asnum") == 0) { subtype = dns_geoip_as_asnum; strlcpy(de.geoip_elem.as_string, search, sizeof(de.geoip_elem.as_string)); } else if (strcasecmp(stype, "org") == 0) { subtype = dns_geoip_org_name; strlcpy(de.geoip_elem.as_string, search, sizeof(de.geoip_elem.as_string)); } else if (strcasecmp(stype, "domain") == 0) { subtype = dns_geoip_domain_name; strlcpy(de.geoip_elem.as_string, search, sizeof(de.geoip_elem.as_string)); } else if (strcasecmp(stype, "netspeed") == 0) { subtype = dns_geoip_netspeed_id; de.geoip_elem.as_int = atoi(search); } else INSIST(0); de.geoip_elem.subtype = get_subtype(obj, lctx, subtype, dbname); if (! geoip_can_answer(&de, ctx)) { cfg_obj_log(obj, lctx, ISC_LOG_ERROR, "no GeoIP database installed which can answer " "queries of type '%s'", stype); return (ISC_R_FAILURE); } *dep = de; return (ISC_R_SUCCESS); }