static int extract_ping_reply_v4ts(const uint8_t *buf, uint32_t *off, const uint32_t len, scamper_ping_reply_v4ts_t **out, void *param) { scamper_addr_t *addr; uint8_t i, tsc, ipc; uint32_t u32; if(len - *off < 2) return -1; tsc = buf[(*off)++]; ipc = buf[(*off)++]; if((*out = scamper_ping_reply_v4ts_alloc(tsc, ipc)) == NULL) return -1; for(i=0; i<tsc; i++) { if(extract_uint32(buf, off, len, &u32, NULL) != 0) return -1; (*out)->tss[i] = u32; } for(i=0; i<ipc; i++) { if(extract_addr(buf, off, len, &addr, param) != 0) return -1; (*out)->ips[i] = addr; } return 0; }
static int extract_ping_probe_tsps(const uint8_t *buf, uint32_t *off, const uint32_t len, scamper_ping_v4ts_t **out, void *param) { scamper_addr_t *addr; uint8_t i, ipc; /* make sure there is room for the ip count */ if(len - *off < 1) return -1; ipc = buf[(*off)++]; if((*out = scamper_ping_v4ts_alloc(ipc)) == NULL) return -1; for(i=0; i<ipc; i++) { if(extract_addr(buf, off, len, &addr, param) != 0) return -1; (*out)->ips[i] = addr; } return 0; }
static int extract_ping_reply_v4rr(const uint8_t *buf, uint32_t *off, const uint32_t len, scamper_ping_reply_v4rr_t **out, void *param) { scamper_addr_t *addr; uint8_t i, rrc; if(len - *off < 1) return -1; rrc = buf[(*off)++]; if((*out = scamper_ping_reply_v4rr_alloc(rrc)) == NULL) return -1; for(i=0; i<rrc; i++) { if(extract_addr(buf, off, len, &addr, param) != 0) return -1; (*out)->rr[i] = addr; } return 0; }
static int extract_dealias_prefixscan_xs(const uint8_t *buf, uint32_t *off, const uint32_t len, scamper_dealias_prefixscan_t *pfs, void *param) { scamper_addr_t **xs; uint16_t xc, i; if(extract_uint16(buf, off, len, &xc, NULL) != 0) return -1; if(scamper_dealias_prefixscan_xs_alloc(pfs, xc) != 0) return -1; xs = pfs->xs; for(i=0; i<xc; i++) { if(extract_addr(buf, off, len, &xs[i], param) != 0) return -1; } pfs->xs = xs; pfs->xc = xc; return 0; }
char *resolveAddress(char *addr) { struct Arecord *rec = NULL; char *ret, *rev = extract_addr(addr); if (rev == NULL) return NULL; rec = resolve(rev, A_BYADDR); if (rec == NULL) return NULL; ret = strdup(rec->hostname); free(rec); free(rev); return ret; }
int flute_sdp_field_handler( SDP_Parser * parser, char type, const char * value, void * user_data) { char * temp; /* temp string for string search operations */ switch(type) { case 'v': case 'o': case 'i': case 't': break; case 'a': if (!strncmp(value, "flute-tsi:", 10) && isdigit((int)*(value+10))) { ((flute_cb *) user_data)->demux_label = atoi(value+10); } else if (!strncmp(value, "flute-ch:", 9) && isdigit((int)*(value+9))){ ((flute_cb *) user_data)->nb_layers = atoi(value+9); } else if (!strncmp(value, "source-filter:", 14) && isdigit((int)*(value+14))){ if (((flute_cb *) user_data)->sdp->media_part == true) /* source filters not allowed in media part */ return SDP_FAILURE; if ((temp = strstr(value,"excl")) != NULL) /* exclusive source filters not allowed */ return SDP_FAILURE; if ((temp = strstr(value,"IN")) == NULL) /* only IN source filters allowed */ return SDP_FAILURE; if ((temp = strstr(value,"IP4")) != NULL) { #ifdef WIN32 ((flute_cb *) user_data)->ip_version = 4; #endif } else if ((temp = strstr(value,"IP6")) != NULL) { #ifdef WIN32 ((flute_cb *) user_data)->ip_version = 6; #endif } /* get the IP address string */ temp = strstr(value,"* "); strncpy(((flute_cb *) user_data)->source_addr_str, temp+2, sizeof(((flute_cb *) user_data)->source_addr_str)); ((flute_cb *) user_data)->source_addr_str[255] = '\0'; if (extract_addr(((flute_cb *) user_data)->source_addr_str, &((flute_cb *) user_data)->src_addr, 0) < 0) { EXIT(("Flute: ERROR, extract_addr failed for src_addr argument -s%s\n", optarg)) } if (!isdigit((int)*(temp+1))) return SDP_FAILURE; ((flute_cb *) user_data)->port = atoi(temp+1); } #if 0 else if (!strncmp(value, "FEC-declaration:", 16) && isdigit((int)*(value+16))){ } #endif break; case 'm': /* we are starting parsing the media part */ if (((flute_cb *) user_data)->sdp->media_part == false) ((flute_cb *) user_data)->sdp->media_part = true; /* check if it is a FLUTE media type */ temp = strstr(value,"FLUTE/UDP"); if (temp == NULL) return SDP_FAILURE; /* jump to the port number */ /* (Normally the line looks like: * * m=application 12345 FLUTE/UDP 0 */ temp = strstr(value," "); if (!isdigit((int)*(temp+1))) return SDP_FAILURE; ((flute_cb *) user_data)->port = atoi(temp+1); break; case 'c': if ((temp = strstr(value,"IP4")) != NULL) { #ifdef WIN32 ((flute_cb *) user_data)->ip_version = 4; #endif } else if ((temp = strstr(value,"IP6")) != NULL) { #ifdef WIN32 ((flute_cb *) user_data)->ip_version = 6; #endif } else return SDP_FAILURE; /* get the IP address string */ { char *t,*c; strncpy(((flute_cb *) user_data)->remote_addr_str, temp+4, sizeof(((flute_cb *) user_data)->remote_addr_str)); /* ttl */ if ((t = strchr(((flute_cb *) user_data)->remote_addr_str, '/')) != NULL) { *t = '\0'; /* number of channels */ if ((c = strchr(t, '/')) != NULL){ *c = '\0'; } /* in host order */ ((flute_cb *) user_data)->ttl = (unsigned short)atoi(t+1); } ((flute_cb *) user_data)->remote_addr_str[255] = '\0'; } ((flute_cb *) user_data)->remote_address_set = true; default: break; }
static void properties_reply(DBusPendingCall *call, void *user_data) { struct supplicant_task *task = user_data; struct supplicant_result result; struct connman_network *network; DBusMessage *reply; DBusMessageIter array, dict; unsigned char strength; unsigned short channel, frequency; const char *mode, *security; char *group = NULL; reply = dbus_pending_call_steal_reply(call); if (reply == NULL) { _DBG_SUPPLICANT("task %p no reply", task); get_properties(task); return; } if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) { _DBG_SUPPLICANT("task %p ERROR", task); dbus_message_unref(reply); get_properties(task); return; } memset(&result, 0, sizeof(result)); result.frequency = -1; result.quality = -1; result.level = 0; result.noise = 0; dbus_message_iter_init(reply, &array); dbus_message_iter_recurse(&array, &dict); while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) { DBusMessageIter entry, value; const char *key; dbus_message_iter_recurse(&dict, &entry); dbus_message_iter_get_basic(&entry, &key); dbus_message_iter_next(&entry); dbus_message_iter_recurse(&entry, &value); //type = dbus_message_iter_get_arg_type(&value); //dbus_message_iter_get_basic(&value, &val); /* * bssid : a (97) * ssid : a (97) * wpaie : a (97) * rsnie : a (97) * wpsie : a (97) * frequency : i (105) * capabilities : q (113) * quality : i (105) * noise : i (105) * level : i (105) * maxrate : i (105) */ if (g_str_equal(key, "bssid") == TRUE) extract_addr(&value, &result); else if (g_str_equal(key, "ssid") == TRUE) extract_ssid(&value, &result); else if (g_str_equal(key, "wpaie") == TRUE) extract_wpaie(&value, &result); else if (g_str_equal(key, "rsnie") == TRUE) extract_rsnie(&value, &result); else if (g_str_equal(key, "wpsie") == TRUE) extract_wpsie(&value, &result); else if (g_str_equal(key, "capabilities") == TRUE) extract_capabilites(&value, &result); else if (g_str_equal(key, "frequency") == TRUE) dbus_message_iter_get_basic(&value, &result.frequency); else if (g_str_equal(key, "quality") == TRUE) dbus_message_iter_get_basic(&value, &result.quality); else if (g_str_equal(key, "noise") == TRUE) dbus_message_iter_get_basic(&value, &result.noise); else if (g_str_equal(key, "level") == TRUE) dbus_message_iter_get_basic(&value, &result.level); else if (g_str_equal(key, "maxrate") == TRUE) dbus_message_iter_get_basic(&value, &result.maxrate); dbus_message_iter_next(&dict); } if (result.path == NULL) goto done; if (result.path[0] == '\0') goto done; if (result.frequency > 0 && result.frequency < 14) result.frequency = 2407 + (5 * result.frequency); else if (result.frequency == 14) result.frequency = 2484; strength = calculate_strength(task, &result); channel = calculate_channel(&result); frequency = (result.frequency < 0) ? 0 : result.frequency; if (result.has_rsn == TRUE) security = "rsn"; else if (result.has_wpa == TRUE) security = "wpa"; else if (result.has_wep == TRUE) security = "wep"; else security = "none"; mode = (result.adhoc == TRUE) ? "adhoc" : "managed"; group = build_group(result.path, result.name, result.ssid, result.ssid_len, mode, security); network = connman_device_get_network(task->device, result.path); if (network == NULL) { int index; network = connman_network_create(result.path, CONNMAN_NETWORK_TYPE_WIFI); if (network == NULL) { _DBG_SUPPLICANT("cannot create network %s", result.name); goto done; } index = connman_device_get_index(task->device); connman_network_set_index(network, index); connman_network_set_protocol(network, CONNMAN_NETWORK_PROTOCOL_IP); connman_network_set_address(network, result.addr, result.addr_len); if (connman_device_add_network(task->device, network) < 0) { _DBG_SUPPLICANT("cannot add network %s", result.name); connman_network_unref(network); goto done; } _DBG_SUPPLICANT("add %s (%s %s) signal %d (%s) freq %u path %s", result.name, mode, security, strength, (result.has_wps == TRUE) ? "WPS" : "no WPS", frequency, result.path); } connman_network_set_scangen(network, task->scangen); if (result.name != NULL && result.name[0] != '\0') connman_network_set_name(network, result.name); connman_network_set_blob(network, "WiFi.SSID", result.ssid, result.ssid_len); connman_network_set_string(network, "WiFi.Mode", mode); connman_network_set_available(network, TRUE); connman_network_set_strength(network, strength); connman_network_set_uint16(network, "Frequency", frequency); connman_network_set_uint16(network, "WiFi.Channel", channel); connman_network_set_string(network, "WiFi.Security", security); if (result.ssid != NULL) connman_network_set_group(network, group); done: g_free(group); g_free(result.path); g_free(result.addr); g_free(result.name); g_free(result.ssid); dbus_message_unref(reply); get_properties(task); }