void search_name( const char* hostname ) { struct sockaddr_in server; cout << "hostname is " << hostname << endl; struct hostent* he = gethostbyname( hostname ); for (int i = 0; (he != NULL) && (he->h_addr_list[i] != NULL); ++i ) { memcpy( &server.sin_addr, he->h_addr_list[i], he->h_length); const char* adstr = inet_ntoa( (struct in_addr)server.sin_addr ); cout << "address: " << adstr << endl; if (strncmp( adstr, "192.168.", 8 ) == 0 || strncmp( adstr, "10.", 3 ) == 0 || strncmp( adstr, "172.16.", 7 ) == 0 || strncmp( adstr, "172.32.", 7 ) == 0 ) { if (!lanaddr_str[0]) set_lan_address( adstr ); } else if (strncmp( adstr, "127.", 4 ) == 0) { ; } else { if (!ipaddr_str[0]) set_ip_address( adstr ); } } }
int SetWlanESSID(const char *pcWlanID) { int rt; int fd; struct iwreq wrq; char ac[64]; // diag_printf("_net_init = %x\n", &_net_init); //set_ip_address("wlan0", inet_addr("10.130.249.144"),inet_addr("255.255.0.0")); if ((fd = socket(AF_INET,SOCK_DGRAM,0)) < 0) return FALSE; memset(&wrq, 0, sizeof(wrq)); strcpy(wrq.ifr_name, "wlan0"); if (pcWlanID == NULL) {//essid: any ac[0] = '\0'; wrq.u.essid.flags = 0; } else { strncpy(ac, pcWlanID, sizeof(ac)); wrq.u.essid.flags = 1; } wrq.u.essid.pointer = (caddr_t)ac; wrq.u.essid.length = strlen(ac) + 1; if((rt = ioctl(fd, SIOCSIWESSID, &wrq)) < 0) { diag_printf("scan ESSID TP_LINK failed\n"); } diag_printf("set ssid finished\n"); if((rt = ioctl(fd, SIOCGIWRATE, &wrq)) < 0) { diag_printf("get Tx rate failed\n"); } else diag_printf("get Tx rate %x\n", wrq.u.bitrate); close(fd); //init_all_network_interfaces(); set_ip_address("wlan0", inet_addr("10.130.249.111"),inet_addr("255.255.0.0")); return (rt >= 0 ? TRUE : FALSE); }
int set_route(const sai_unicast_route_entry_t* route_entry, struct __next_hop* next_hop){ int netmask_bits, ret; sai_ip4_t destination = route_entry->destination.addr.ip4; struct __rocker_vlan* target_interface; target_interface = (struct __rocker_vlan*)(get_vlan(next_hop->interface_id)->data_plane_attributes); // Set route for this subnet, to the next hop // The below functions does the exactly the same as // ip addr add destination/netmask_bits dev next_hop->br_name // which introduces an appropriate ip route automatically // (What if the routing is comlex like connecting two virtual routers??) netmask_bits = make_netmask_bits(route_entry->destination.mask.ip4); ret = set_ip_address(next_hop->interface_ip, netmask_bits, target_interface->br_name); return ret; }
SocketAddress::SocketAddress(const char *addr, uint16_t port) { _ip_address[0] = '\0'; set_ip_address(addr); set_port(port); }