Esempio n. 1
0
//get net interface info
void getnetinfo(const char *netname, struct str_net_addr *net_info) //ccc
{
  struct ifaddrs *ifaces, *ifa;
  char abuf[64], mbuf[64], dbuf[64];
  
  if (getifaddrs (&ifaces) < 0)
  {
       printf ("Couldn't get any interfaces\n");
	   if(ifaces)
	   	  freeifaddrs (ifaces);
	   return;
  }
 
  for (ifa = ifaces; ifa != NULL; ifa = ifa->ifa_next)
  {

	  if(strcmp(ifa->ifa_name, netname)==0)
	  {
	  
      	  printf ("%-15s%#.4x  %-15s %-15s %-15s\n",
	      ifa->ifa_name, ifa->ifa_flags,
	      addr_string (ifa->ifa_addr, abuf, sizeof (abuf)),
	      addr_string (ifa->ifa_netmask, mbuf, sizeof (mbuf)),
	      addr_string (ifa->ifa_broadaddr, dbuf, sizeof (dbuf)));
	  	  str2ip(abuf, net_info->ip);
		  str2ip(mbuf, net_info->mask);
	  }
  }
  freeifaddrs(ifaces);
}
Esempio n. 2
0
cmd_state_t
cmd_set_ip(int argc, char* argv[], void* ctx)
{
        struct net_cfg *ncfg = ctx;
        struct ip_addr lwip_addr;
        struct netif *nif = ncfg->netif;

        if (argc == 2 &&
            (strncmp(argv[1], "none", 4) == 0)) {
                ncfg->dhcp_enabled = 1;

                return CMD_DONE;
        }
        else if (argc != 4 ) {
                printk("usage: ip <ip> <netmask> <gateway-ip>\n");
                printk("  or : ip none (to enable DHCP)\n");
                return CMD_DONE;
        }
        /* IP address */
        lwip_addr = str2ip(argv[1]);
        netif_set_ipaddr(nif, &lwip_addr);
        /* Netmask */
        lwip_addr = str2ip(argv[2]);
        netif_set_netmask(nif, &lwip_addr);
        /* Default Gateway address */
        lwip_addr = str2ip(argv[3]);
        netif_set_gw(nif, &lwip_addr);
        /* Disable DHCP */
        ncfg->dhcp_enabled = 0;

        return CMD_DONE;
}
Esempio n. 3
0
int prober_config_load(int argc, char **argv, char *tracefile, int *fileid)
{
  int c = 0;
  opterr = 0;

  serv_port = SERV_PORT_UDP;
  serverip = htonl(str2ip("143.215.131.173"));
  //serverip = htonl(str2ip("38.102.0.111"));

  while ((c = getopt (argc, argv, "s:p:vh")) != -1)
  {
  switch (c)
  {
  case 's':
	  serverip = htonl(str2ip(optarg));
	  break;
  case 'p':
	  serv_port = atoi(optarg);
	  break;
  case 'v':
	  verbose = 1;
	  break;
  case '?':
  case ':':
  case 'h':
  default:
	  fprintf(stderr, "Usage: %s -s <server>\n", argv[0]);
	  return -1;
  }
  }
  return 0;
}
Esempio n. 4
0
/** initializes a net structure from a string.
 * @param dst - net structure that will be filled
 * @param s - string of the form "ip", "ip/mask_len" or "ip/ip_mak".
 * @return -1 on error, 0 on succes
 */
int mk_net_str(struct net* dst, str* s)
{
	struct ip_addr* t;
	char* p;
	struct ip_addr ip;
	str addr;
	str mask;
	unsigned int bitlen;
	
	/* test for ip only */
	t = str2ip(s);
	if (unlikely(t == 0))
		t = str2ip6(s);
	if (likely(t))
		return mk_net_bitlen(dst, t, t->len*8);
	/* not a simple ip, maybe an ip/netmask pair */
	p = q_memchr(s->s, '/', s->len);
	if (likely(p)) {
		addr.s = s->s;
		addr.len = (int)(long)(p - s->s);
		mask.s = p + 1;
		mask.len = s->len - (addr.len + 1);
		/* allow '/' enclosed by whitespace */
		trim_trailing(&addr);
		trim_leading(&mask);
		t = str2ip(&addr);
		if (likely(t)) {
			/* it can be a number */
			if (str2int(&mask, &bitlen) == 0)
				return mk_net_bitlen(dst, t, bitlen);
			ip = *t;
			t = str2ip(&mask);
			if (likely(t))
				return mk_net(dst, &ip, t);
			/* error */
			return -1;
		}
		else {
			t = str2ip6(&addr);
			if (likely(t)) {
				/* it can be a number */
				if (str2int(&mask, &bitlen) == 0)
					return mk_net_bitlen(dst, t, bitlen);
				ip = *t;
				t = str2ip6(&mask);
				if (likely(t))
					return mk_net(dst, &ip, t);
				/* error */
				return -1;
			}
		}
	}
	return -1;
}
Esempio n. 5
0
BOOLEAN HttpcStartProv()
{
	UCHAR pDns[MAX_DNS_LEN];
	UCHAR pDstIP[IP_ALEN];

	if (_pProvUrl)
	{
		GetProvAddr(pDns);
		if (strlen(pDns))
		{
			if (str2ip(pDns, pDstIP))
			{
				HttpcStartStep2(pDstIP);
			}
			else
			{
				TaskDnsQuery(pDns, DNS_TYPE_A, HTTP_BANK_OFFSET, (USHORT)HttpcStartStep2);
			}
			return TRUE;
		}
	}

	UdpDebugString("Prov Url error");
	return FALSE;
}
Esempio n. 6
0
/** internal sip naptr resolver function: resolves a host name trying:
 * - NAPTR lookup if the address is not an ip and *proto==0 and *port==0.
 *   The result of the NAPTR query will be used for a SRV lookup
 * - SRV lookup if the address is not an ip *port==0. The result of the SRV
 *   query will be used for an A/AAAA lookup.
 *  - normal A/AAAA lookup (either fallback from the above or if *port!=0
 *   and *proto!=0 or port==0 && proto==0)
 * when performing SRV lookup (*port==0) it will use proto to look for
 * tcp or udp hosts, otherwise proto is unused; if proto==0 => no SRV lookup
 * returns: hostent struct & *port filled with the port from the SRV record;
 *  0 on error
 */
struct hostent* naptr_sip_resolvehost(str* name,  unsigned short* port,
										char* proto)
{
	struct hostent* he;
	struct ip_addr* ip;
	static char tmp[MAX_DNS_NAME]; /* tmp. buff. for SRV lookups and
	                                  null. term  strings */
	struct rdata* l;
	struct rdata* naptr_head;
	char n_proto;
	str srv_name;
	naptr_bmp_t tried_bmp; /* tried bitmap */
	char origproto;

	if(proto) origproto = *proto;
	naptr_head=0;
	he=0;
	if (name->len >= MAX_DNS_NAME) {
		LM_ERR("domain name too long\n");
		goto end;
	}
	/* try NAPTR if no port or protocol is specified and NAPTR lookup is
	 * enabled */
	if (port && proto && (*proto==0) && (*port==0)){
		*proto=PROTO_UDP; /* just in case we don't find another */
		if ( ((ip=str2ip(name))!=0)
			  || ((ip=str2ip6(name))!=0)
		){
			/* we are lucky, this is an ip address */
			he=ip_addr2he(name,ip);
			*port=SIP_PORT;
			goto end;
		}
		memcpy(tmp, name->s, name->len);
		tmp[name->len] = '\0';
		naptr_head=get_record(tmp, T_NAPTR, RES_AR);
		naptr_iterate_init(&tried_bmp);
		while((l=naptr_sip_iterate(naptr_head, &tried_bmp,
										&srv_name, &n_proto))!=0){
			if ((he=srv_sip_resolvehost(&srv_name, 1, port, proto, 1, l))!=0){
				*proto=n_proto;
				return he;
			}
		}
		/*clean up on exit*/
		LM_DBG("no NAPTR record found for %.*s, trying SRV lookup...\n",
					name->len, name->s);
	}
	/* fallback to srv lookup */
	if(proto) *proto = origproto;
	he=no_naptr_srv_sip_resolvehost(name,port,proto);
	/* fallback all the way down to A/AAAA */
	if (he==0) {
		he=dns_get_he(name,dns_flags);
	}
end:
	if (naptr_head)
		free_rdata_list(naptr_head);
	return he;
}
Esempio n. 7
0
int prober_config_load(int argc, char **argv, char *tracefile, int *fileid)
{
  int c = 0;
  opterr = 0;

  serverip = htonl(str2ip("143.215.129.100"));
  //serverip = htonl(str2ip("38.102.0.111"));

  while ((c = getopt (argc, argv, "vh")) != -1)
  {
  switch (c)
  {
  case 'v':
	  verbose = 1;
	  break;
  case '?':
  case ':':
  case 'h':
  default:
	  fprintf(stderr, "ShaperProbe beta candidate.\n\n");
	  fprintf(stderr, "Usage: %s\n", argv[0]);
	  return -1;
  }
  }
  return 0;
}
Esempio n. 8
0
/**
 * Reading Lan Support configuration.
 * @param lancfgName: Name of the lan configuration (could be fullpath)
 * @return 0:success, 1:failure (file not found|readable)
 */
int login_lan_config_read(const char *lancfgName) {
	FILE *fp;
	int line_num = 0, s_subnet=ARRAYLENGTH(subnet);
	char line[1024], w1[64], w2[64], w3[64], w4[64];

	if((fp = fopen(lancfgName, "r")) == NULL) {
		ShowWarning("LAN Support configuration file is not found: %s\n", lancfgName);
		return 1;
	}

	while(fgets(line, sizeof(line), fp))
	{
		line_num++;
		if ((line[0] == '/' && line[1] == '/') || line[0] == '\n' || line[1] == '\n')
			continue;

		if(sscanf(line,"%63[^:]: %63[^:]:%63[^:]:%63[^\r\n]", w1, w2, w3, w4) != 4)
		{
			ShowWarning("Error syntax of configuration file %s in line %d.\n", lancfgName, line_num);
			continue;
		}

		if( strcmpi(w1, "subnet") == 0 ){
			if(subnet_count>=s_subnet) { //We skip instead of break in case we want to add other conf in that file.
				ShowError("%s: Too many subnets defined, skipping line %d...\n", lancfgName, line_num);
				continue;
			}
			subnet[subnet_count].mask = str2ip(w2);
			subnet[subnet_count].char_ip = str2ip(w3);
			subnet[subnet_count].map_ip = str2ip(w4);

			if( (subnet[subnet_count].char_ip & subnet[subnet_count].mask) != (subnet[subnet_count].map_ip & subnet[subnet_count].mask) )
			{
				ShowError("%s: Configuration Error: The char server (%s) and map server (%s) belong to different subnetworks!\n", lancfgName, w3, w4);
				continue;
			}

			subnet_count++;
		}
	}

	if( subnet_count > 1 ) /* only useful if there is more than 1 available */
		ShowStatus("Read information about %d subnetworks.\n", subnet_count);

	fclose(fp);
	return 0;
}
Esempio n. 9
0
static int init_ping_info(int argc, char* argv[], struct ping_info_t* ping_info)
{
        int c;
        ping_complete_cb_t cb;
        void *ctx;

        cb = ping_info->complete_cb;
        ctx = ping_info->ctx;
        memset(ping_info, 0, sizeof(struct ping_info_t));
        ping_info->complete_cb = cb;
        ping_info->ctx = ctx;

        ping_info->deadline = 0;
        ping_info->interval = 1000;
        ping_info->timeout = 3000;
        ping_info->data_size = 32;
        ping_info->count = 3;
        ping_info->destination =
                netif_default ? netif_default->gw : ip_addr_any;

        optind = 1;
        while ((c = getopt(argc, argv, "c:i:s:w:q")) != -1) {
                switch (c) {
                case 'c':
                        ping_info->count = atoi(optarg);
                        break;

                case 'i':
                        ping_info->interval = atoi(optarg);
                        break;

                case 's':
                        ping_info->data_size = atoi(optarg);
                        break;

                case 'q':
                        ping_info->quiet = 1;
                        break;

                case 'w':
                        ping_info->deadline = atoi(optarg);
                        break;
                }
        }

        ping_info->size = sizeof(struct icmp_echo_hdr) + ping_info->data_size;

        if (optind >= argc)
                return -1;

        ping_info->destination = str2ip(argv[optind]);
        if (!ping_info->destination.addr)
                return -1;


        ping_info->last_rx_tm = timer_get_ms();

        return 0;
}
Esempio n. 10
0
/* Checks, if the IP PORT is a LB destination
 */
int lb_is_dst(struct lb_data *data, struct sip_msg *_m,
					pv_spec_t *pv_ip, pv_spec_t *pv_port, int grp, int active)
{
	pv_value_t val;
	struct ip_addr *ip;
	int port;
	struct lb_dst *dst;
	int k;

	/* get the address to test */
	if (pv_get_spec_value( _m, pv_ip, &val)!=0) {
		LM_ERR("failed to get IP value from PV\n");
		return -1;
	}
	if ( (val.flags&PV_VAL_STR)==0 ) {
		LM_ERR("IP PV val is not string\n");
		return -1;
	}
	if ( (ip=str2ip( &val.rs ))==NULL ) {
		LM_ERR("IP val is not IP <%.*s>\n",val.rs.len,val.rs.s);
		return -1;
	}

	/* get the port to test */
	if (pv_port) {
		if (pv_get_spec_value( _m, pv_port, &val)!=0) {
			LM_ERR("failed to get PORT value from PV\n");
			return -1;
		}
		if ( (val.flags&PV_VAL_INT)==0 ) {
			LM_ERR("PORT PV val is not integer\n");
			return -1;
		}
		port = val.ri;
	} else {
		port = 0;
	}

	/* and now search !*/
	for( dst=data->dsts ; dst ; dst=dst->next) {
		if ( ((grp==-1) || (dst->group==grp)) &&  /*group matches*/
		( !active || (active && (dst->flags&LB_DST_STAT_DSBL_FLAG)==0 ) )
		) {
			/* check the IPs */
			for(k=0 ; k<dst->ips_cnt ; k++ ) {
				if ( (dst->ports[k]==0 || port==0 || port==dst->ports[k]) &&
				ip_addr_cmp( ip, &dst->ips[k]) ) {
					/* found */
					return 1;
				}
			}
		}
	}

	return -1;
}
Esempio n. 11
0
/**
 * Show account info from login-server to user
 */
void mapif_accinfo_ack(bool success, int map_fd, int u_fd, int u_aid, int account_id, int8 type,
	int group_id, int logincount, int state, const char *email, const char *last_ip, const char *lastlogin,
	const char *birthdate, const char *user_pass, const char *pincode, const char *userid)
{
	
	if (map_fd <= 0 || !session_isActive(map_fd))
		return; // check if we have a valid fd

	if (!success) {
		inter_to_fd(map_fd, u_fd, u_aid, (char *)msg_txt(216), account_id);
		return;
	}

	if (type == 1) { //type 1 we don't want all the info [lighta] @CHECKME
		mapif_acc_info_ack(map_fd, u_fd, account_id, userid);
		return;
	}

	inter_to_fd(map_fd, u_fd, u_aid, (char *)msg_txt(217), account_id);
	inter_to_fd(map_fd, u_fd, u_aid, (char *)msg_txt(218), userid, group_id, state);
	inter_to_fd(map_fd, u_fd, u_aid, (char *)msg_txt(219), user_pass[0] != '\0' ? user_pass : msg_txt(220), pincode[0] != '\0' ? msg_txt(220) : pincode);
	inter_to_fd(map_fd, u_fd, u_aid, (char *)msg_txt(221), email, birthdate);
	inter_to_fd(map_fd, u_fd, u_aid, (char *)msg_txt(222), last_ip, geoip_getcountry(str2ip(last_ip)));
	inter_to_fd(map_fd, u_fd, u_aid, (char *)msg_txt(223), logincount, lastlogin);
	inter_to_fd(map_fd, u_fd, u_aid, (char *)msg_txt(224));

	if ( SQL_ERROR == Sql_Query(sql_handle, "SELECT `char_id`, `name`, `char_num`, `class`, `base_level`, `job_level`, `online` FROM `%s` WHERE `account_id` = '%d' ORDER BY `char_num` LIMIT %d", schema_config.char_db, account_id, MAX_CHARS)
		|| Sql_NumRows(sql_handle) == 0 )
	{
		if( Sql_NumRows(sql_handle) == 0 )
			inter_to_fd(map_fd, u_fd, u_aid, (char *)msg_txt(226));
		else {
			inter_to_fd(map_fd, u_fd, u_aid, (char *)msg_txt(213));
			Sql_ShowDebug(sql_handle);
		}
	} else {
		while ( SQL_SUCCESS == Sql_NextRow(sql_handle) ) {
			uint32 char_id, class_;
			short char_num, base_level, job_level, online;
			char name[NAME_LENGTH];
			char *data;

			Sql_GetData(sql_handle, 0, &data, NULL); char_id = atoi(data);
			Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name));
			Sql_GetData(sql_handle, 2, &data, NULL); char_num = atoi(data);
			Sql_GetData(sql_handle, 3, &data, NULL); class_ = atoi(data);
			Sql_GetData(sql_handle, 4, &data, NULL); base_level = atoi(data);
			Sql_GetData(sql_handle, 5, &data, NULL); job_level = atoi(data);
			Sql_GetData(sql_handle, 6, &data, NULL); online = atoi(data);

			inter_to_fd(map_fd, u_fd, u_aid, (char *)msg_txt(225), char_num, char_id, name, job_name(class_), base_level, job_level, online?"Online":"Offline");
		}
	}
	Sql_FreeResult(sql_handle);
}
Esempio n. 12
0
void mapif_parse_accinfo2(bool success, int map_fd, int u_fd, int u_aid, int account_id, const char *userid, const char *user_pass, const char *email, const char *last_ip, const char *lastlogin, const char *pin_code, const char *birthdate, int group_id, int logincount, int state) {
	if (map_fd <= 0 || !session_isActive(map_fd))
		return; // check if we have a valid fd

	if (!success) {
		inter_msg_to_fd(map_fd, u_fd, u_aid, "No account with ID '%d' was found.", account_id);
		return;
	}

	inter_msg_to_fd(map_fd, u_fd, u_aid, "-- Account %d --", account_id);
	inter_msg_to_fd(map_fd, u_fd, u_aid, "User: %s | GM Group: %d | State: %d", userid, group_id, state);

	if (user_pass && *user_pass != '\0') { /* password is only received if your gm level is greater than the one you're searching for */
		if (pin_code && *pin_code != '\0')
			inter_msg_to_fd(map_fd, u_fd, u_aid, "Password: %s (PIN:%s)", user_pass, pin_code);
		else
			inter_msg_to_fd(map_fd, u_fd, u_aid, "Password: %s", user_pass );
	}

	inter_msg_to_fd(map_fd, u_fd, u_aid, "Account e-mail: %s | Birthdate: %s", email, birthdate);
	inter_msg_to_fd(map_fd, u_fd, u_aid, "Last IP: %s (%s)", last_ip, geoip_getcountry(str2ip(last_ip)));
	inter_msg_to_fd(map_fd, u_fd, u_aid, "This user has logged %d times, the last time were at %s", logincount, lastlogin);
	inter_msg_to_fd(map_fd, u_fd, u_aid, "-- Character Details --");

	if ( SQL_ERROR == SQL->Query(sql_handle, "SELECT `char_id`, `name`, `char_num`, `class`, `base_level`, `job_level`, `online` "
	                                         "FROM `%s` WHERE `account_id` = '%d' ORDER BY `char_num` LIMIT %d", char_db, account_id, MAX_CHARS)
	  || SQL->NumRows(sql_handle) == 0 ) {
		if (SQL->NumRows(sql_handle) == 0) {
			inter_msg_to_fd(map_fd, u_fd, u_aid, "This account doesn't have characters.");
		} else {
			inter_msg_to_fd(map_fd, u_fd, u_aid, "An error occurred, bother your admin about it.");
			Sql_ShowDebug(sql_handle);
		}
	} else {
		while ( SQL_SUCCESS == SQL->NextRow(sql_handle) ) {
			char *data;
			int char_id, class_;
			short char_num, base_level, job_level, online;
			char name[NAME_LENGTH];

			SQL->GetData(sql_handle, 0, &data, NULL); char_id = atoi(data);
			SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name));
			SQL->GetData(sql_handle, 2, &data, NULL); char_num = atoi(data);
			SQL->GetData(sql_handle, 3, &data, NULL); class_ = atoi(data);
			SQL->GetData(sql_handle, 4, &data, NULL); base_level = atoi(data);
			SQL->GetData(sql_handle, 5, &data, NULL); job_level = atoi(data);
			SQL->GetData(sql_handle, 6, &data, NULL); online = atoi(data);

			inter_msg_to_fd(map_fd, u_fd, u_aid, "[Slot/CID: %d/%d] %s | %s | Level: %d/%d | %s", char_num, char_id, name, job_name(class_), base_level, job_level, online?"On":"Off");
		}
	}
	SQL->FreeResult(sql_handle);

	return;
}
Esempio n. 13
0
ER dhcp_open(T_IF_SOFTC  *ic)
{

    static UB   shost_addr[sizeof("00:00:00:00:00:00") + 1];
    ER          ercd;

    /* DHCPによるIPアドレス取得 */
    memcpy(Dhcp.macaddr, ic->ifaddr.lladdr, ETHER_ADDR_LEN);
    mac2str(shost_addr, Dhcp.macaddr);
    syslog(LOG_NOTICE, "[get_dhcp_addr] started on MAC Addr: %s.", shost_addr);

    dhcp_packet = (DHCP_PACKET *)udp_rbuf;

    ercd = get_dhcp_addr(&Dhcp);
    if(ercd == E_OK) {
        /* インタフェースにIPv4アドレスを設定する */
        in4_add_ifaddr((T_IN4_ADDR)str2ip(Dhcp.ipaddr), (T_IN4_ADDR)str2ip(Dhcp.maskaddr));
    }

    return ercd;
}
Esempio n. 14
0
static inline ip_addr_t *strtoipX(str *ips)
{
	/* try to figure out INET class */
	if(ips->s[0] == '[' || memchr(ips->s, ':', ips->len)!=NULL)
	{
		/* IPv6 */
		return str2ip6(ips);
	} else {
		/* IPv4 */
		return str2ip(ips);
	}
}
Esempio n. 15
0
void send_insertion_packet(struct send_tcp_vars *vars, unsigned int flags)
{
    if (flags & INS_DISC_SMALL_TTL) {
        unsigned char ttl = get_ttl(str2ip(vars->dst_ip));
        vars->ttl = ttl - 3;
    }

    if (flags & INS_DISC_BAD_TCP_CHECKSUM) {
        vars->wrong_tcp_checksum = 1;
    }

    if (flags & INS_DISC_NO_TCP_FLAG) {
        // this will override existing flags
        vars->flags = 0;
    }

    if (flags & INS_DISC_BAD_ACK_NUM) {
        // ack number in the future, is it good for all cases?
        vars->ack_num + 100000;
    }

    if (flags & INS_DISC_MD5) {
        u_char bytes[20] = {0x13,0x12,0xf9,0x89,0x5c,0xdd,0xa6,0x15,0x12,0x83,0x3e,0x93,0x11,0x22,0x33,0x44,0x55,0x66,0x01,0x01};
        memcpy(vars->tcp_opt + vars->tcp_opt_len, bytes, 20);
        vars->tcp_opt_len += 20;
    }

    if (flags & INS_DISC_OLD_TIMESTAMP) {
        // check if there's timestamp 
        int i;
        for (i = 0; i < vars->tcp_opt_len; i++) {
            unsigned char kind = vars->tcp_opt[i];
            if (kind == 1) continue;  // padding
            unsigned char len = vars->tcp_opt[i + 1];
            if (kind == 8) // Timestamp
            {
                unsigned int *tsval = (unsigned int*)(vars->tcp_opt + i + 2);
                *tsval = htonl(ntohl(*tsval) - 10000);
                break;
            }
            else 
            {
                i += len;
            }
        }
    }

    //dump_send_tcp_vars(vars);

    send_tcp(vars);
}
Esempio n. 16
0
/* Adds a new entry to the blacklist */
void dst_blst_add(rpc_t* rpc, void* ctx)
{
	str ip;
	int port, proto, flags;
	unsigned char err_flags;
	struct ip_addr *ip_addr;

	if (!cfg_get(core, core_cfg, use_dst_blacklist)){
		rpc->fault(ctx, 500, "dst blacklist support disabled");
		return;
	}
	if (rpc->scan(ctx, "Sddd", &ip, &port, &proto, &flags) < 4)
		return;

	err_flags = (unsigned char)flags;
	/* sanity checks */
	if ((unsigned char)proto > PROTO_SCTP) {
		rpc->fault(ctx, 400, "Unknown protocol");
		return;
	}

	if (err_flags & BLST_IS_IPV6) {
#ifdef USE_IPV6
		/* IPv6 address is specified */
		ip_addr = str2ip6(&ip);
#else  /* USE_IPV6 */
		rpc->fault(ctx, 400, "IPv6 support disabled");
		return;
#endif /* USE_IPV6 */
	} else {
		/* try IPv4 first, than IPv6 */
		ip_addr = str2ip(&ip);
		if (!ip_addr) {
#ifdef USE_IPV6
			ip_addr = str2ip6(&ip);
			err_flags |= BLST_IS_IPV6;
#else  /* USE_IPV6 */
			rpc->fault(ctx, 400, "Malformed or IPv6 ip address");
			return;
#endif /* USE_IPV6 */
		}
	}
	if (!ip_addr) {
		rpc->fault(ctx, 400, "Malformed ip address");
		return;
	}

	if (dst_blacklist_add_ip(err_flags, proto, ip_addr, port, 
				    S_TO_TICKS(cfg_get(core, core_cfg, blst_timeout))))
		rpc->fault(ctx, 400, "Failed to add the entry to the blacklist");
}
Esempio n. 17
0
static int parse_args(int argc, char **argv)
{
	int c;

	if (argc < 2)
		return -1;

	/* reinitialize getopt() */
	optind = 0;
	opterr = 0;
	while ((c = getopt(argc, argv, "s:t:c:?h")) != -1) {
		switch (c) {
		case 's':
			size = atoi(optarg);
			break;
		case 'c':
			recv = count = atoi(optarg);
			finite = 1;
			break;
		case 't':
			ttl = atoi(optarg);
			break;
		case 'h':
		case '?':
		default:
			return -1;
		}
	}
	if (size < 0 || size > 65507) {
		printf("Packet size %d is too large. Maximum is 65507\n", size);
		return -2;
	}
	if (ttl < 0 || ttl > 255) {
		printf("ttl %d out of range\n", ttl);
		return -2;
	}
	if (finite && count <= 0)
		printf("bad number of packets to transmit\n");

	argc -= optind;
	argv += optind;
	if (argc != 1)
		return -1;

	if (str2ip(*argv, &ipaddr) < 0) {
		printf("bad ip address %s\n", *argv);
		return -2;
	}
	return 0;
}
Esempio n. 18
0
/*
 * sip_config_get_backup_proxy_addr()
 *
 * Get table entry from the table string and option number
 */
uint16_t
sip_config_get_backup_proxy_addr (cpr_ip_addr_t *IPAddress, char *buffer, int buffer_len)
{

    *IPAddress = ip_addr_invalid;

    config_get_string(CFGID_PROXY_BACKUP, buffer, buffer_len);

    if ((cpr_strcasecmp(buffer, UNPROVISIONED) == 0) || (buffer[0] == 0)) {
        buffer[0] = 0;
    } else {
        (void) str2ip(buffer, IPAddress);
    }
    return (1);
}
Esempio n. 19
0
static int parse_domain_def(char *val, str *id, struct ip_addr **ip,
											unsigned int *port, str *domain)
{
	char *p = (char*)val;
	str s;

	/* format is ID=ip:port or  ID=string */

	/* first get the ID */
	id->s = p;
	if ( (p=strchr( p, '='))==NULL )
		goto parse_err;
	id->len = p-id->s;
	p++;

	/* get IP */
	s.s = p;
	if ( (p=strchr( p, ':'))==NULL )
		goto has_domain;
	s.len = p-s.s;
	p++;
	if ( (*ip=str2ip( &s ))==NULL ) {
		LM_ERR("[%.*s] is not an ip\n", s.len, s.s);
		goto parse_err;
	}

	/* what is left should be a port */
	s.s = p;
	s.len = val + strlen(val) - p;
	if (str2int( &s, port)<0) {
		LM_ERR("[%.*s] is not a port\n", s.len, s.s);
		goto parse_err;
	}

	return 0;

has_domain:
	/* what is left should be a domain */
	domain->s = s.s;
	domain->len = val + strlen(val) - s.s;
	*ip = NULL;

	return 0;
parse_err:
	LM_ERR("invalid TSL domain [%s] (error around pos %d)\n",
		val, (int)(long)(p-val) );
	return -1;
}
Esempio n. 20
0
int x18_process_request(struct mypacket *packet)
{
    char sip[16], dip[16];
    unsigned short sport, dport;

    struct in_addr s_in_addr = {packet->iphdr->saddr};
    struct in_addr d_in_addr = {packet->iphdr->daddr};
    strncpy(sip, inet_ntoa(s_in_addr), 16);
    strncpy(dip, inet_ntoa(d_in_addr), 16);
    sport = ntohs(packet->tcphdr->th_sport);
    dport = ntohs(packet->tcphdr->th_dport);

    int ttl = get_ttl(str2ip(dip));
    log_debug("[TTL Probing] The probed TTL value for %s is %d.", dip, ttl);

    return 0;
}
Esempio n. 21
0
bool ladmin_auth(struct login_session_data* sd, const char* ip)
{
	bool result = false;

	if( str2ip(ip) != host2ip(login_config.admin_allowed_host) )
		ShowNotice("'ladmin'-login: Connection in administration mode REFUSED - IP isn't authorised (ip: %s).\n", ip);
	else
	if( !login_config.admin_state )
		ShowNotice("'ladmin'-login: Connection in administration mode REFUSED - remote administration is disabled (ip: %s)\n", ip);
	else
	if( !check_password(sd->md5key, sd->passwdenc, sd->passwd, login_config.admin_pass) )
		ShowNotice("'ladmin'-login: Connection in administration mode REFUSED - invalid password (ip: %s)\n", ip);
	else
	{
		ShowNotice("'ladmin'-login: Connection in administration mode accepted (ip: %s)\n", ip);
		session[sd->fd]->func_parse = parse_admin;
		result = true;
	}

	return result;
}
Esempio n. 22
0
/* これはちゃんと動作しない */
ER dhcp_release(DHCP *dhcp)
{

    T_IPV4EP p_dstaddr;
    ER       ercd;

    memset((VP)dhcp_packet, 0, sizeof(DHCP_PACKET));

    dhcp_packet->opecode        = 0x01;
    dhcp_packet->hard_addr      = 0x01;
    dhcp_packet->hard_addr_len  = 0x06;
    dhcp_packet->hop_count      = 0x00;
    dhcp_packet->transaction_id = htonl(TRANSACTION_ID);
    dhcp_packet->second         = htons(0x0000);
    dhcp_packet->dummy          = htons(0x0000);
    /* dhcp_packet->client_ip[4]; */
    /* dhcp_packet->user_ip[4]; */
    /* dhcp_packet->server_ip[4]; */
    /* dhcp_packet->gateway_ip[4]; */
    memcpy((VP)dhcp_packet->client_hard_addr, (const VP)dhcp->macaddr, 6);
    /* dhcp_packet->server_host_name[64]; */
    /* dhcp_packet->file_name[128]; */

    memcpy((VP)dhcp_packet->options.magic_cookie, (const VP)magic_cookie, 4);
                                                    /* Magic Cookie */
    memcpy((VP)dhcp_packet->options.message_type1, (const VP)message_and_length, 2);
                                                    /* DHCP Message */
    dhcp_packet->options.message_type2 = DHCP_RELEASE;
    memcpy((VP)dhcp_packet->options.client_id1, (const VP)client_identifier, 3);
                                                    /* Client Identifier, Ethernet */
    memcpy((VP)dhcp_packet->options.client_mac, (const VP)dhcp->macaddr, 6);
    dhcp_packet->options.dummy[0]      = 0xff;

    p_dstaddr.ipaddr = str2ip(dhcp->dhcpsrvaddr);
    p_dstaddr.portno = BROADCAST_PORT;
    ercd = udp_snd_dat(UDP_CLIENT_CEPID, &p_dstaddr, (VP)&dhcp_packet->opecode,
             sizeof(DHCP_PACKET), TMO_NBLK);

    return ercd;
}
Esempio n. 23
0
u_int32_t select_public_resolver(u_int32_t exclude_ip)
{
    int idx, total;
    u_int32_t ret;
    const char PUBLIC_DNS_RESOLVERS[][16] = {
        "203.112.2.4",
        "216.146.35.35",
        "216.146.36.36",
        "208.67.220.220",
        "208.67.222.222",
        "202.45.84.58"
    };
    total = 4;

    do {
        idx = rand() % total;
        ret = str2ip(PUBLIC_DNS_RESOLVERS[idx]);
    } 
    while (ret == exclude_ip);
    log_debug("Using public DNS resolver #%d: %s", idx+1, PUBLIC_DNS_RESOLVERS[idx]);
    
    return ret;
}
Esempio n. 24
0
static int mod_init(void)
{
	struct ip_addr *_ip;

	if (ip.s) {
		ip.len = strlen(ip.s);
		if ( (_ip=str2ip(&ip)) == NULL ) {
			LM_ERR("invalid IP [%.*s]\n", ip.len, ip.s);
			return -1;
		}
	}

	if (post_buf_size < MIN_POST_BUF_SIZE) {
		LM_ERR("post_buf_size should be bigger then %d\n",
			MIN_POST_BUF_SIZE);
		return -1;
	}
	if (buffer.len == 0)
		buffer.len = (pkg_mem_size/4)*3;
	LM_DBG("buf_size=[%d]\n", buffer.len);

	return 0;
}
Esempio n. 25
0
int x34_process_synack(struct mypacket *packet)
{
    char sip[16], dip[16];
    unsigned short sport, dport;

    struct in_addr s_in_addr = {packet->iphdr->saddr};
    struct in_addr d_in_addr = {packet->iphdr->daddr};
    strncpy(sip, inet_ntoa(s_in_addr), 16);
    strncpy(dip, inet_ntoa(d_in_addr), 16);
    sport = ntohs(packet->tcphdr->th_sport);
    dport = ntohs(packet->tcphdr->th_dport);

    unsigned char ttl = get_ttl(str2ip(sip));
    log_debug("The probed TTL value is %d.", ttl);
    ttl -= 2; // to not reach server

    send_RST_super(dip, dport, sip, sport, packet->tcphdr->th_ack, ttl);
    usleep(30000);
    send_RST_super(dip, dport, sip, sport, packet->tcphdr->th_ack, ttl);
    usleep(30000);
    send_RST_super(dip, dport, sip, sport, packet->tcphdr->th_ack, ttl);
    
    return 1;
}
Esempio n. 26
0
/* [Dekamaster/Nightroad] */
void mapif_parse_accinfo(int fd) {
	int u_fd = RFIFOL(fd,2), aid = RFIFOL(fd,6), castergroup = RFIFOL(fd,10);
	char query[NAME_LENGTH], query_esq[NAME_LENGTH*2+1];
	int account_id;
	char *data;

	safestrncpy(query, (char*) RFIFOP(fd,14), NAME_LENGTH);

	SQL->EscapeString(sql_handle, query_esq, query);

	account_id = atoi(query);

	if (account_id < START_ACCOUNT_NUM) {	// is string
		if ( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id`,`name`,`class`,`base_level`,`job_level`,`online` FROM `%s` WHERE `name` LIKE '%s' LIMIT 10", char_db, query_esq)
				|| SQL->NumRows(sql_handle) == 0 ) {
			if( SQL->NumRows(sql_handle) == 0 ) {
				inter_msg_to_fd(fd, u_fd, aid, "No matches were found for your criteria, '%s'",query);
			} else {
				Sql_ShowDebug(sql_handle);
				inter_msg_to_fd(fd, u_fd, aid, "An error occured, bother your admin about it.");
			}
			SQL->FreeResult(sql_handle);
			return;
		} else {
			if( SQL->NumRows(sql_handle) == 1 ) {//we found a perfect match
				SQL->NextRow(sql_handle);
				SQL->GetData(sql_handle, 0, &data, NULL); account_id = atoi(data);
				SQL->FreeResult(sql_handle);
			} else {// more than one, listing... [Dekamaster/Nightroad]
				inter_msg_to_fd(fd, u_fd, aid, "Your query returned the following %d results, please be more specific...",(int)SQL->NumRows(sql_handle));
				while ( SQL_SUCCESS == SQL->NextRow(sql_handle) ) {
					int class_;
					short base_level, job_level, online;
					char name[NAME_LENGTH];

					SQL->GetData(sql_handle, 0, &data, NULL); account_id = atoi(data);
					SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name));
					SQL->GetData(sql_handle, 2, &data, NULL); class_ = atoi(data);
					SQL->GetData(sql_handle, 3, &data, NULL); base_level = atoi(data);
					SQL->GetData(sql_handle, 4, &data, NULL); job_level = atoi(data);
					SQL->GetData(sql_handle, 5, &data, NULL); online = atoi(data);

					inter_msg_to_fd(fd, u_fd, aid, "[AID: %d] %s | %s | Level: %d/%d | %s", account_id, name, job_name(class_), base_level, job_level, online?"Online":"Offline");
				}
				SQL->FreeResult(sql_handle);
				return;
			}
		}
	}

	/* it will only get here if we have a single match */
	if( account_id ) {
		char userid[NAME_LENGTH], user_pass[NAME_LENGTH], email[40], last_ip[20], lastlogin[30], pin_code[5], birthdate[11];
		short level = -1;
		int logincount = 0,state = 0;
		// FIXME: No, this doesn't really look right.  We can't, and shouldn't, access the login table from the char server.
		if ( SQL_ERROR == SQL->Query(sql_handle, "SELECT `userid`, `user_pass`, `email`, `last_ip`, `group_id`, `lastlogin`, `logincount`, `state`,`pincode`,`birthdate` FROM `login` WHERE `account_id` = '%d' LIMIT 1", account_id)
			|| SQL->NumRows(sql_handle) == 0 ) {
			if( SQL->NumRows(sql_handle) == 0 ) {
				inter_msg_to_fd(fd, u_fd, aid,  "No account with ID '%d' was found.", account_id );
			} else {
				inter_msg_to_fd(fd, u_fd, aid, "An error occured, bother your admin about it.");
				Sql_ShowDebug(sql_handle);
			}
		} else {
			SQL->NextRow(sql_handle);
			SQL->GetData(sql_handle, 0, &data, NULL); safestrncpy(userid, data, sizeof(userid));
			SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(user_pass, data, sizeof(user_pass));
			SQL->GetData(sql_handle, 2, &data, NULL); safestrncpy(email, data, sizeof(email));
			SQL->GetData(sql_handle, 3, &data, NULL); safestrncpy(last_ip, data, sizeof(last_ip));
			SQL->GetData(sql_handle, 4, &data, NULL); level = atoi(data);
			SQL->GetData(sql_handle, 5, &data, NULL); safestrncpy(lastlogin, data, sizeof(lastlogin));
			SQL->GetData(sql_handle, 6, &data, NULL); logincount = atoi(data);
			SQL->GetData(sql_handle, 7, &data, NULL); state = atoi(data);
			SQL->GetData(sql_handle, 8, &data, NULL); safestrncpy(pin_code, data, sizeof(pin_code));
			SQL->GetData(sql_handle, 9, &data, NULL); safestrncpy(birthdate, data, sizeof(birthdate));
		}

		SQL->FreeResult(sql_handle);

		if (level == -1)
			return;

		inter_msg_to_fd(fd, u_fd, aid, "-- Account %d --", account_id );
		inter_msg_to_fd(fd, u_fd, aid, "User: %s | GM Group: %d | State: %d", userid, level, state );

		if (level < castergroup) { /* only show pass if your gm level is greater than the one you're searching for */
			if( strlen(pin_code) )
				inter_msg_to_fd(fd, u_fd, aid, "Password: %s (PIN:%s)", user_pass, pin_code );
			else
				inter_msg_to_fd(fd, u_fd, aid, "Password: %s", user_pass );
		}

		inter_msg_to_fd(fd, u_fd, aid, "Account e-mail: %s | Birthdate: %s", email, birthdate);
		inter_msg_to_fd(fd, u_fd, aid, "Last IP: %s (%s)", last_ip, geoip_getcountry(str2ip(last_ip)) );
		inter_msg_to_fd(fd, u_fd, aid, "This user has logged %d times, the last time were at %s", logincount, lastlogin );
		inter_msg_to_fd(fd, u_fd, aid, "-- Character Details --" );


		if ( SQL_ERROR == SQL->Query(sql_handle, "SELECT `char_id`, `name`, `char_num`, `class`, `base_level`, `job_level`, `online` FROM `%s` WHERE `account_id` = '%d' ORDER BY `char_num` LIMIT %d", char_db, account_id, MAX_CHARS)
				|| SQL->NumRows(sql_handle) == 0 ) {

				if( SQL->NumRows(sql_handle) == 0 )
					inter_msg_to_fd(fd, u_fd, aid,"This account doesn't have characters.");
				else {
					inter_msg_to_fd(fd, u_fd, aid,"An error occured, bother your admin about it.");
					Sql_ShowDebug(sql_handle);
				}

		} else {
			while ( SQL_SUCCESS == SQL->NextRow(sql_handle) ) {
				int char_id, class_;
				short char_num, base_level, job_level, online;
				char name[NAME_LENGTH];

				SQL->GetData(sql_handle, 0, &data, NULL); char_id = atoi(data);
				SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name));
				SQL->GetData(sql_handle, 2, &data, NULL); char_num = atoi(data);
				SQL->GetData(sql_handle, 3, &data, NULL); class_ = atoi(data);
				SQL->GetData(sql_handle, 4, &data, NULL); base_level = atoi(data);
				SQL->GetData(sql_handle, 5, &data, NULL); job_level = atoi(data);
				SQL->GetData(sql_handle, 6, &data, NULL); online = atoi(data);

				inter_msg_to_fd(fd, u_fd, aid, "[Slot/CID: %d/%d] %s | %s | Level: %d/%d | %s", char_num, char_id, name, job_name(class_), base_level, job_level, online?"On":"Off");
			}
		}
		SQL->FreeResult(sql_handle);
	}

	return;
}
Esempio n. 27
0
static int w_ip_is_trusted(struct sip_msg* msg, char* _ip_set, char* _ip) {
	str ip_set_s, ip_s;
	struct ip_addr *ip, ip_buf;
	struct ip_set new_ip_set, *ip_set;
	struct ip_set_list_item *isli = NULL;
	int kind;
	kind = ((struct ip_set_param*)_ip_set)->kind;
	if (kind == IP_SET_PARAM_KIND_LOCAL) {
		if (get_str_fparam(&ip_set_s, msg, ((struct ip_set_param*)_ip_set)->u.local.fparam) < 0) {
		    ERR(MODULE_NAME": ip_is_trusted: Error while obtaining ip_set parameter value\n");
			return -1;
		}
		if (is_ip_set_name(&ip_set_s)) {
			isli = ip_set_list_find_by_name(ip_set_s);
			if (!isli) {
				ERR(MODULE_NAME": ip_is_trusted: ip set '%.*s' is not declared\n", ip_set_s.len, ip_set_s.s);
				return -1;
			}
			kind = IP_SET_PARAM_KIND_GLOBAL;
			goto force_global;
		}		
		ip_set = &((struct ip_set_param*)_ip_set)->u.local.ip_set;
	}
	else {
		isli = ((struct ip_set_param*)_ip_set)->u.global.ip_set;
	force_global:
		if (!isli->ip_set) return -1; /* empty ip set */
		
		if (unlikely(isli->ip_set != ip_set_list_local[isli->idx])) {   /* global ip set has changed ? */
			if (ip_set_list_local[isli->idx]) {
				if (atomic_dec_and_test(&ip_set_list_local[isli->idx]->refcnt)) {
					ip_set_destroy(&ip_set_list_local[isli->idx]->ip_set);
					shm_free(ip_set_list_local[isli->idx]);
					ip_set_list_local[isli->idx] = NULL;
				}
			}
			lock_get(&isli->read_lock);			
			atomic_inc(&isli->ip_set->refcnt);
			ip_set_list_local[isli->idx] = isli->ip_set;
			lock_release(&isli->read_lock);
		}
		ip_set = &ip_set_list_local[isli->idx]->ip_set;
	}
	
	if (get_str_fparam(&ip_s, msg, (fparam_t*)_ip) < 0) {
	    ERR(MODULE_NAME": ip_is_trusted: Error while obtaining ip parameter value\n");
	    return -1;
	}
	if (!ip_s.len || !ip_set_s.len) return -1;
	switch (ip_s.s[0]) {
		case 's':	/* src */
		case 'S':
			ip = &msg->rcv.src_ip;
			break;
		case 'd':	/* dst */
		case 'D':
			ip = &msg->rcv.dst_ip;
			break;
		case 'r':	/* rcv */
		case 'R':
			ip = &msg->rcv.bind_address->address;
			break;			
		default:
			/* string -> ip */

			if ( ((ip = str2ip(&ip_s))==0)
			                  && ((ip = str2ip6(&ip_s))==0)
							                  ){
				ERR(MODULE_NAME": ip_is_trusted: string to ip conversion error '%.*s'\n", ip_s.len, ip_s.s);
				return -1;
			}
			ip_buf = *ip;
			ip = &ip_buf;  /* value has been in static buffer */			
			break;
	}

	/* test if ip_set string has changed since last call */
	if (kind == IP_SET_PARAM_KIND_LOCAL) {
		if (((struct ip_set_param*)_ip_set)->u.local.s.len != ip_set_s.len || 
			memcmp(((struct ip_set_param*)_ip_set)->u.local.s.s, ip_set_s.s, ip_set_s.len) != 0) {

			ip_set_init(&new_ip_set, 0);
			if (ip_set_add_list(&new_ip_set, ip_set_s) < 0) {
				ip_set_destroy(&new_ip_set);
				return -1;
			};
			if (((struct ip_set_param*)_ip_set)->u.local.sz < ip_set_s.len) {
				void *p;
				p = pkg_realloc(((struct ip_set_param*)_ip_set)->u.local.s.s, ip_set_s.len);
				if (!p) {
					ip_set_destroy(&new_ip_set);
					return E_OUT_OF_MEM;
				}
				((struct ip_set_param*)_ip_set)->u.local.s.s = p;			
				((struct ip_set_param*)_ip_set)->u.local.sz = ip_set_s.len;			
			}
			memcpy(((struct ip_set_param*)_ip_set)->u.local.s.s, ip_set_s.s, ip_set_s.len);
			((struct ip_set_param*)_ip_set)->u.local.s.len = ip_set_s.len;
			ip_set_destroy(&((struct ip_set_param*)_ip_set)->u.local.ip_set);
			((struct ip_set_param*)_ip_set)->u.local.ip_set = new_ip_set;
		}
	}
/* ip_set_print(stderr, &ip_set); */
	switch (ip_set_ip_exists(ip_set, ip)) {
		case IP_TREE_FIND_FOUND:
		case IP_TREE_FIND_FOUND_UPPER_SET:
			return 1;
		default:
			return -1;
	}
}
Esempio n. 28
0
static void InitParameters(void)
{
	char cfg[128];
	char ip[4][16];
	char wifiippass[128];
	int i;
	unsigned int addr = 0;
	unsigned int mask = 0;
	unsigned int gateway = 0;

	memset(cfg, 0x00, sizeof(cfg));
	if (my_ssid[0]) {
		SetWindowText(WifiWnd[0], my_ssid);
	} else if (LoadStr("SSID", cfg)) {
		SetWindowText(WifiWnd[0], cfg);
	}
	LoadStr("wifipasswd", wifiippass);
	SetWindowText(WifiWnd[1], wifiippass);

	memset(oldip, 0, sizeof(oldip));
	memset(newip, 0, sizeof(newip));

	if (gOptions.wifidhcpfunon) {
		dhcpswitch(1);
		if (wireless_is_online()) {
			//printf("_____%s%d\n", __FILE__, __LINE__);
			unsigned char ip[4];
			memset(ip, 0, sizeof(ip));
			wireless_get_ipaddr(&addr);
			str2ip((char*)ipaddr_to_string(addr), (BYTE*)ip);
			sprintf((char*)oldip[0], "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
			printf("dynaic wifi: %d:%d:%d:%d\n", ip[0], ip[1], ip[2], ip[3]);

			memset(ip, 0, sizeof(ip));
			wireless_get_mask(&mask);
			str2ip(ipaddr_to_string(mask), (BYTE*)ip);
			sprintf((char*)oldip[1], "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);

			memset(ip, 0, sizeof(ip));
			wireless_get_default_route(&gateway);
			str2ip(ipaddr_to_string(gateway), (BYTE*)ip);
			sprintf((char*)oldip[2], "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
		}
	} else {
		LoadStr("wifiip", (char*)oldip[0]);
		LoadStr("wifimask", (char*)oldip[1]);
		LoadStr("wifigateway", (char*)oldip[2]);
	}

	memcpy(newip, oldip, sizeof(oldip));
	//set ip
	if(ParseIP(newip[0],ip[0],ip[1],ip[2],ip[3])){
		for(i=0;i<4;i++){
			if (strlen(ip[i])>0) {
				SetWindowText(WifiWnd[3+i],ip[i]);
			} else {
				SetWindowText(WifiWnd[3+i],"0");
			}
		}
	}
	//set sub mask
	if(ParseIP(newip[1],ip[0],ip[1],ip[2],ip[3])){
		for(i=0;i<4;i++){
			SetWindowText(WifiWnd[7+i],ip[i]);
		}
	}

	//set Gate Way
	if(ParseIP(newip[2],ip[0],ip[1],ip[2],ip[3])){
		for(i=0;i<4;i++){
			SetWindowText(WifiWnd[11+i],ip[i]);
		}
	}
}
Esempio n. 29
0
int pike_check_req(struct sip_msg *msg)
{
	struct ip_node *node;
	struct ip_node *father;
	unsigned char flags;
	struct ip_addr* ip;


#ifdef _test
	/* get the ip address from second via */
	if (parse_headers(msg, HDR_VIA1_F, 0)!=0 )
		return -1;
	if (msg->via1==0 )
		return -1;
	/* convert from string to ip_addr */
	ip = str2ip( &msg->via1->host );
	if (ip==0)
		return -1;
#else
	ip = &(msg->rcv.src_ip);
#endif


	/* first lock the proper tree branch and mark the IP with one more hit*/
	lock_tree_branch( ip->u.addr[0] );
	node = mark_node( ip->u.addr, ip->len, &father, &flags);
	if (node==0) {
		unlock_tree_branch( ip->u.addr[0] );
		/* even if this is an error case, we return true in script to avoid
		 * considering the IP as marked (bogdan) */
		return 1;
	}

	LM_DBG("src IP [%s],node=%p; hits=[%d,%d],[%d,%d] node_flags=%d"
		" func_flags=%d\n", ip_addr2a( ip ), node,
		node->hits[PREV_POS],node->hits[CURR_POS],
		node->leaf_hits[PREV_POS],node->leaf_hits[CURR_POS],
		node->flags, flags);

	/* update the timer */
	lock_get(timer_lock);
	if ( flags&NEW_NODE ) {
		/* put this node into the timer list and remove its
		   father only if this has one kid and is not a LEAF_NODE*/
		node->expires =  get_ticks() + timeout;
		append_to_timer( timer, &(node->timer_ll) );
		node->flags |= NODE_INTIMER_FLAG;
		if (father) {
			LM_DBG("father %p: flags=%d kids->next=%p\n",
				father,father->flags,father->kids->next);
			if (!(father->flags&NODE_IPLEAF_FLAG) && !father->kids->next){
				/* debug */
				assert( has_timer_set(&(father->timer_ll))
					&& (father->flags&(NODE_EXPIRED_FLAG|NODE_INTIMER_FLAG)) );
				/* if the node is maked as expired by timer, let the timer
				 * to finish and remove the node */
				if ( !(father->flags&NODE_EXPIRED_FLAG) ) {
					remove_from_timer( timer, &(father->timer_ll) );
					father->flags &= ~NODE_INTIMER_FLAG;
				} else {
					father->flags &= ~NODE_EXPIRED_FLAG;
				}
			}
		}
	} else {
		/* update the timer -> in timer can be only nodes
		 * as IP-leaf(complete address) or tree-leaf */
		if (node->flags&NODE_IPLEAF_FLAG || node->kids==0) {
			/* tree leafs which are not potential red nodes are not update in
			 * order to make them to expire */
			/* debug */
			assert( has_timer_set(&(node->timer_ll))
				&& (node->flags&(NODE_EXPIRED_FLAG|NODE_INTIMER_FLAG)) );
			/* if node exprired, ignore the current hit and let is
			 * expire in timer process */
			if ( !(flags&NO_UPDATE) && !(node->flags&NODE_EXPIRED_FLAG) ) {
				node->expires = get_ticks() + timeout;
				update_in_timer( timer, &(node->timer_ll) );
			}
		} else {
			/* debug */
			assert( !has_timer_set(&(node->timer_ll))
				&& !(node->flags&(NODE_INTIMER_FLAG|NODE_EXPIRED_FLAG)) );
			/* debug */
			assert( !(node->flags&NODE_IPLEAF_FLAG) && node->kids );
		}
	}
	/*print_timer_list( timer );*/ /* debug*/
	lock_release(timer_lock);

	unlock_tree_branch( ip->u.addr[0] );
	/*print_tree( 0 );*/ /* debug */

	if (flags&RED_NODE) {
		if (flags&NEWRED_NODE) {
			LM_GEN1( pike_log_level,
				"PIKE - BLOCKing ip %s, node=%p\n",ip_addr2a(ip),node);
			pike_raise_event(ip_addr2a(ip));
			return -2;
		}
		return -1;
	}
	return 1;
}
Esempio n. 30
0
void mapif_parse_accinfo2(bool success, int map_fd, int u_fd, int u_aid, int account_id, const char *userid, const char *user_pass, const char *email, const char *last_ip, const char *lastlogin, const char *pin_code, const char *birthdate, int group_id, int logincount, int state) {
	if (map_fd <= 0 || !session_isActive(map_fd))
		return; // check if we have a valid fd

	if(!success) {
		inter_msg_to_fd(map_fd, u_fd, u_aid, "No account with ID '%d' was found.", account_id);
		return;
	}

		inter_msg_to_fd(map_fd, u_fd, u_aid, read_message("Source.char.inter_parse_accinfo_s7"), account_id);
		inter_msg_to_fd(map_fd, u_fd, u_aid, read_message("Source.char.inter_parse_accinfo_s8"), userid, group_id, state);

		if(user_pass && *user_pass != '\0') { /* password is only received if your gm level is greater than the one you're searching for */
			if(pin_code && *pin_code != '\0')
				inter_msg_to_fd(map_fd, u_fd, u_aid, read_message("Source.char.inter_parse_accinfo_s17"), user_pass, pin_code);
			else
				inter_msg_to_fd(map_fd, u_fd, u_aid, read_message("Source.char.inter_parse_accinfo_s9"), user_pass);
			}

		inter_msg_to_fd(map_fd, u_fd, u_aid, read_message("Source.char.inter_parse_accinfo_s10"), email, birthdate);
		inter_msg_to_fd(map_fd, u_fd, u_aid, read_message("Source.char.inter_parse_accinfo_s11"), last_ip, geoip_getcountry(str2ip(last_ip)));
		inter_msg_to_fd(map_fd, u_fd, u_aid, read_message("Source.char.inter_parse_accinfo_s12"), logincount, lastlogin);
		inter_msg_to_fd(map_fd, u_fd, u_aid, read_message("Source.char.inter_parse_accinfo_s13"));


		if(SQL_ERROR == Sql_Query(sql_handle, "SELECT `char_id`, `name`, `char_num`, `class`, `base_level`, `job_level`, `online` "
	                                              "FROM `%s` WHERE `account_id` = '%d' ORDER BY `char_num` LIMIT %d", char_db, account_id, MAX_CHARS)
			|| Sql_NumRows(sql_handle) == 0) {

			if(Sql_NumRows(sql_handle) == 0) {
				inter_msg_to_fd(map_fd, u_fd, u_aid, read_message("Source.char.inter_parse_accinfo_s14"));
			} else {
				inter_msg_to_fd(map_fd, u_fd, u_aid, read_message("Source.char.inter_parse_accinfo_s15"));
				Sql_ShowDebug(sql_handle);
			}
		} else {
			while(SQL_SUCCESS == Sql_NextRow(sql_handle)) {
				char *data;
				int char_id, class_;
				short char_num, base_level, job_level, online;
				char name[NAME_LENGTH];

				Sql_GetData(sql_handle, 0, &data, NULL); char_id = atoi(data);
				Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name));
				Sql_GetData(sql_handle, 2, &data, NULL); char_num = atoi(data);
				Sql_GetData(sql_handle, 3, &data, NULL); class_ = atoi(data);
				Sql_GetData(sql_handle, 4, &data, NULL); base_level = atoi(data);
				Sql_GetData(sql_handle, 5, &data, NULL); job_level = atoi(data);
				Sql_GetData(sql_handle, 6, &data, NULL); online = atoi(data);

				inter_msg_to_fd(map_fd, u_fd, u_aid, read_message("Source.char.inter_parse_accinfo_s16"), char_num, char_id, name, job_name(class_), base_level, job_level, online?"On":"Off");
			}
		}
		Sql_FreeResult(sql_handle);

	return;
}