void extract_info(char *str, string &site_name, visit &visit) { char *ips=NULL, *site=NULL, *date=NULL; #define TOK_ERR "Found a record with invalid formatting... ignoring entry" if((ips = strtok(str," "))==NULL) throw (string)(TOK_ERR); if((site = strtok(NULL," "))==NULL) throw (string)(TOK_ERR); if((date = strtok(NULL," "))==NULL) throw (string)(TOK_ERR); #undef TOK_ERR if(!strlen(site)) throw("Found a record with site name missing... ignoring entry"); UI ipn; mmddyyyy sd; try { ipn = extract_ip(ips); sd = extract_date(date); } catch(string e) { throw "Found a record with an " + e + " ignoring entry"; } // success site_name = site; visit.ip = ipn; visit.date = sd; }
bool __plugin_setting_dataxserver(void *class_ptr, char *method_name, void *input_pack) { uint8_t *arg_ptr = (uint8_t *)input_pack; char *ip; bool res = true; memcpy(&ip, arg_ptr, sizeof(char *)); arg_ptr += sizeof(char *); Serial1.printf("%s\r\n", ip); if (extract_ip(ip, EEPROM.getDataPtr() + EEP_DATA_SERVER_IP)) { memcpy(EEPROM.getDataPtr() + EEP_DATA_SERVER_ADDR, ip, strlen(ip)); memset(EEPROM.getDataPtr() + EEP_DATA_SERVER_ADDR + strlen(ip) , 0, 1); EEPROM.commit(); stream_print(STREAM_CMD, TYPE_STRING, "\"ok\""); response_msg_close(STREAM_CMD); delay(100); fire_reboot(NULL); } else { stream_print(STREAM_CMD, TYPE_STRING, "\"failed, bad ip format.\""); return false; } return true; }
static int change_remote_ip(request_rec *r) { const char *fwdvalue; char *val; rpaf_server_cfg *cfg = (rpaf_server_cfg *)ap_get_module_config(r->server->module_config, &rpaf_module); if (!cfg->enable) return DECLINED; if (cfg->remote_addr_env) { apr_table_set(r->subprocess_env, cfg->remote_addr_env, r->connection->remote_ip); } if (is_in_array(r->connection->remote_ip, cfg->proxy_ips) == 1) { /* check if cfg->headername is set and if it is use that instead of X-Forwarded-For by default */ if (cfg->headername && (fwdvalue = apr_table_get(r->headers_in, cfg->headername))) { // } else if ((fwdvalue = apr_table_get(r->headers_in, "X-Forwarded-For"))) { // } else { return DECLINED; } if (fwdvalue) { rpaf_cleanup_rec *rcr = (rpaf_cleanup_rec *)apr_pcalloc(r->pool, sizeof(rpaf_cleanup_rec)); apr_array_header_t *arr = apr_array_make(r->pool, 0, sizeof(char*)); while (*fwdvalue && (val = ap_get_token(r->pool, &fwdvalue, 1))) { *(char **)apr_array_push(arr) = apr_pstrdup(r->pool, val); if (*fwdvalue != '\0') ++fwdvalue; } rcr->old_ip = r->connection->remote_ip; rcr->old_family = r->connection->remote_addr->sa.sin.sin_family; rcr->r = r; apr_pool_cleanup_register(r->pool, (void *)rcr, rpaf_cleanup, apr_pool_cleanup_null); r->connection->remote_ip = apr_pstrdup(r->pool, extract_ip(arr, cfg->proxy_ips, cfg->recursive)); r->connection->remote_addr->sa.sin.sin_addr.s_addr = apr_inet_addr(r->connection->remote_ip); r->connection->remote_addr->sa.sin.sin_family = AF_INET; if (cfg->sethostname) { const char *hostvalue; if ((hostvalue = apr_table_get(r->headers_in, "X-Forwarded-Host"))) { /* 2.0 proxy frontend or 1.3 => 1.3.25 proxy frontend */ apr_table_set(r->headers_in, "Host", apr_pstrdup(r->pool, hostvalue)); r->hostname = apr_pstrdup(r->pool, hostvalue); ap_update_vhost_from_headers(r); } else if ((hostvalue = apr_table_get(r->headers_in, "X-Host"))) { /* 1.3 proxy frontend with mod_proxy_add_forward */ apr_table_set(r->headers_in, "Host", apr_pstrdup(r->pool, hostvalue)); r->hostname = apr_pstrdup(r->pool, hostvalue); ap_update_vhost_from_headers(r); } } } } return DECLINED; }
// NATed udp protocol void protocol_udp(char *line) { char *token; char *buf[35]; int count; token = strtok(line," "); count = 0; while(token != NULL) { buf[count] = token; if(!strlen(buf[count])) buf[count]=""; count++; token = strtok(NULL," "); } if ((match(buf[2], "=")) && (match(buf[3], "=")) && (match(buf[6], "=")) && (match(buf[6], "="))) { extract_ip(buf[2]); extract_ip(buf[3]); extract_ip(buf[6]); extract_ip(buf[7]); if (SNAT) { if ((!strcmp(buf[2],buf[7])==0) && (strcmp(buf[3],buf[6])==0)) { check_src_dst(buf[0],buf[2],buf[6],buf[4],buf[5]," "); } } if (DNAT) { if ((strcmp(buf[2],buf[7])==0) && (!strcmp(buf[3],buf[6])==0)) { check_src_dst(buf[0],buf[2],buf[6],buf[4],buf[5]," "); } } if (LOCAL) { if ((strcmp(buf[2],buf[7])==0) && (strcmp(buf[3],buf[6])==0)) { check_src_dst(buf[0],buf[2],buf[6],buf[4],buf[5]," "); } } } }
static void add_connection(const char *path, DBusMessageIter *properties, void *user_data) { struct connection_data *data; int err; char *ident = get_ident(path); connman_bool_t found = FALSE; data = g_hash_table_lookup(vpn_connections, ident); if (data != NULL) { /* * We might have a dummy connection struct here that * was created by configuration_create_reply() so in * that case just continue. */ if (data->connect_pending == FALSE) return; found = TRUE; } else { data = create_connection_data(path); if (data == NULL) return; } DBG("data %p path %s", data, path); while (dbus_message_iter_get_arg_type(properties) == DBUS_TYPE_DICT_ENTRY) { DBusMessageIter entry, value; const char *key; char *str; dbus_message_iter_recurse(properties, &entry); dbus_message_iter_get_basic(&entry, &key); dbus_message_iter_next(&entry); dbus_message_iter_recurse(&entry, &value); if (g_str_equal(key, "State") == TRUE) { dbus_message_iter_get_basic(&value, &str); DBG("state %s -> %s", data->state, str); data->state = g_strdup(str); } else if (g_str_equal(key, "IPv4") == TRUE) { extract_ip(&value, AF_INET, data); } else if (g_str_equal(key, "IPv6") == TRUE) { extract_ip(&value, AF_INET6, data); } else if (g_str_equal(key, "Name") == TRUE) { dbus_message_iter_get_basic(&value, &str); data->name = g_strdup(str); } else if (g_str_equal(key, "Type") == TRUE) { dbus_message_iter_get_basic(&value, &str); data->type = g_strdup(str); } else if (g_str_equal(key, "Host") == TRUE) { dbus_message_iter_get_basic(&value, &str); data->host = g_strdup(str); } else if (g_str_equal(key, "Domain") == TRUE) { dbus_message_iter_get_basic(&value, &str); data->domain = g_strdup(str); } else if (g_str_equal(key, "Nameservers") == TRUE) { extract_nameservers(&value, data); } else if (g_str_equal(key, "Index") == TRUE) { dbus_message_iter_get_basic(&value, &data->index); } else { if (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) { dbus_message_iter_get_basic(&value, &str); g_hash_table_replace(data->setting_strings, g_strdup(key), g_strdup(str)); } else { DBG("unknown key %s", key); } } dbus_message_iter_next(properties); } if (found == FALSE) g_hash_table_insert(vpn_connections, g_strdup(data->ident), data); err = create_provider(data, user_data); if (err < 0) goto out; resolv_host_addr(data); if (data->connect_pending == TRUE) connect_provider(data, data->cb_data); return; out: DBG("removing %s", data->ident); g_hash_table_remove(vpn_connections, data->ident); }
int pack_parse(struct pkt_info_t *syn) { while (1) { char *p = get_packet(syn->fd); struct ether_header eth; struct ip ip; struct tcphdr tcp; char *opts; memcpy(ð, p, s_eth); if (eth.ether_type == 0x8) { memcpy(&ip, &p[s_eth], s_iph); if (ip.ip_p == 0x6) { memcpy(&tcp, &p[s_eth + s_iph], s_tcp); int opt_len = ((4 * tcp.th_off) - s_tcp); if (opt_len) { opts = malloc(opt_len + 1); memcpy(opts, &p[s_eth + s_iph + s_tcp], opt_len); } char *sip = extract_ip(ip.ip_src.s_addr); char *dip = extract_ip(ip.ip_dst.s_addr); if (chk_ip_src(sip, syn->p_dst_ip)) { struct tcp_timestamp time; memset(&time, 0x0, s_tme); time = extract_timestamp(opt_len, opts); syn->p_seq = ntohl(tcp.th_seq); syn->p_ack = ntohl(tcp.th_ack); syn->p_tsval = ntohl(time.tsval) + 1; syn->p_tsecr = ntohl(time.tsecr); printf("\nRECV | (%d bytes) %s -> %s" "\n.......(seq %d) (ack %d)" "\n.......(ports %d -> %d) (val/secr: %d %d )" "\n.......(flags %s %s %s %s %s %s) (options %d)" "\n.......(thread %p)\n", s_eth + s_iph + s_tcp + opt_len, sip, dip, syn->p_seq, syn->p_ack, ntohs(tcp.th_sport), ntohs(tcp.th_dport), syn->p_tsval, syn->p_tsecr, (tcp. th_flags & TH_URG ? "URG" : ""), (tcp. th_flags & TH_SYN ? "SYN" : ""), (tcp. th_flags & TH_ACK ? "ACK" : ""), (tcp. th_flags & TH_PUSH ? "PSH" : ""), (tcp. th_flags & TH_RST ? "RST" : ""), (tcp. th_flags & TH_FIN ? "FIN" : ""), opt_len, (void *)pthread_self()); if (syn->p_flags & TH_SYN) thread_destructor(sip, syn-> p_dst_ip); return 1; } } } } return 0; }