diff --git a/libmobile_zte.c b/libmobile_zte.c index 645eeb4145e1e34724407781db02bbf1b8bd8edf..9840f356703b160ef0a341daaf94f76b7281d7d5 100644 --- a/libmobile_zte.c +++ b/libmobile_zte.c @@ -430,8 +430,8 @@ struct json_object *mobile_get_roam_status_zte(char *ip_addr) struct json_object *mobile_get_current_apn_zte(char *ip_addr) { - struct json_object *idx_json, *apn_profiles, *current_profile; - int idx, counter = 0; + struct json_object *current_idx, *idx_json, *apn_profiles, *current_profile; + int idx, counter = 0, rv; idx_json = prepare_request(ip_addr, "Current_index", GET); if (!idx_json) { @@ -439,7 +439,12 @@ struct json_object *mobile_get_current_apn_zte(char *ip_addr) goto fail; } - idx = json_object_get_int(idx_json); + json_object_object_get_ex(idx_json, "Current_index", ¤t_idx); + if (!current_idx) { + //debug_print("no current idx in response!\n"); + goto fail_idx; + } + idx = json_object_get_int(current_idx); if (idx < 0 || idx > 9) { //debug_print("Something is very wrong!\n"); goto fail_idx; @@ -448,7 +453,7 @@ struct json_object *mobile_get_current_apn_zte(char *ip_addr) json_object_object_foreach(apn_profiles, key, val) { counter++; - if (counter < idx) + if (counter <= idx) continue; current_profile = json_object_get(val); break;