这篇教程C++ str2ip函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中str2ip函数的典型用法代码示例。如果您正苦于以下问题:C++ str2ip函数的具体用法?C++ str2ip怎么用?C++ str2ip使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了str2ip函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: getnetinfo//get net interface infovoid 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);}
开发者ID:lostsnow,项目名称:C3-jzl,代码行数:31,
示例2: cmd_set_ipcmd_state_tcmd_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;}
开发者ID:AndreyMostovov,项目名称:asf,代码行数:32,
示例3: prober_config_loadint 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;}
开发者ID:shahifaqeer,项目名称:udpprobe,代码行数:32,
示例4: mk_net_str/** 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;}
开发者ID:alezzandro,项目名称:kamailio,代码行数:59,
示例5: HttpcStartProvBOOLEAN 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;}
开发者ID:AlexVangelov,项目名称:ar168l,代码行数:25,
示例6: naptr_sip_resolvehost/** 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;}
开发者ID:btriller,项目名称:kamailio,代码行数:72,
示例7: prober_config_loadint 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;}
开发者ID:AndrewJDR,项目名称:shaperprobe,代码行数:26,
示例8: login_lan_config_read/** * 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;}
开发者ID:AlmasB,项目名称:rathena,代码行数:52,
示例9: init_ping_infostatic 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;}
开发者ID:AndreyMostovov,项目名称:asf,代码行数:59,
示例10: lb_is_dst/* 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;}
开发者ID:NoamRom89,项目名称:opensips,代码行数:58,
示例11: mapif_accinfo_ack/** * 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);}
开发者ID:Lemongrass3110,项目名称:rathena,代码行数:58,
示例12: mapif_parse_accinfo2void 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;}
开发者ID:Baalberith6,项目名称:Hercules,代码行数:55,
示例13: dhcp_openER 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) { /* インタフェ C++ str2num函数代码示例 C++ str2int函数代码示例
|