int check_ip_ops() { int i , ret = 1; char ip_buf[128]; ci_ip_t *ip1 = ci_ip_ops.dup("192.168.1.1/255.255.255.248", default_allocator); for (i = 1; i < 8 && ret; ++i) { snprintf(ip_buf, sizeof(ip_buf), "192.168.1.%d", i); ci_ip_t *ip2 = ci_ip_ops.dup(ip_buf, default_allocator); printf("IP network address: %s\n", str_ip(ip1)); printf("IP check address: %s\n", str_ip(ip2)); ret = ci_ip_ops.equal(ip1, ip2); printf("Check result: %d\n\n", ret); ci_ip_ops.free(ip2, default_allocator); } for (i = 8; i < 16 && ret; ++i) { snprintf(ip_buf, sizeof(ip_buf), "192.168.1.%d", i); ci_ip_t *ip2 = ci_ip_ops.dup(ip_buf, default_allocator); printf("IP network address: %s\n", str_ip(ip1)); printf("IP check address: %s\n", str_ip(ip2)); ret = ci_ip_ops.equal(ip1, ip2); printf("Check result: %d\n\n", ret); ret = !ret; ci_ip_ops.free(ip2, default_allocator); } ci_ip_ops.free(ip1, default_allocator); return ret; }
int main(int argc, char* argv[]) { net_lib_initial(); session session_inst; string str_ip("192.168.50.174"); while(true) { ip_port addr(str_ip,23456); if(session_inst.connect(addr,"admin","123",default_authentication_protocol_id)) break; cout<<"·þÎñÆ÷ip:"; cin>>str_ip; } time_t last_time=time(NULL); msg_fix_string msg_out; while(true) { auto_ptr_m<msg_int> ap_msg_in=msg_call<msg_int>(&session_inst,&msg_out); if(!ap_msg_in.get()) return 0; if((ap_msg_in->count%10000)==0) { time_t current_time=time(NULL); printf("after %lld sec recv_msg.count=%d\n",long long(current_time-last_time),ap_msg_in->count); last_time=current_time; } }
int add_configfs_node(int nodeid, char *addr, int addrlen, int local) { char path[PATH_MAX]; char padded_addr[sizeof(struct sockaddr_storage)]; char buf[32]; int rv, fd; log_debug("set_configfs_node %d %s local %d", nodeid, str_ip(addr), local); /* * create comm dir for this node */ memset(path, 0, PATH_MAX); snprintf(path, PATH_MAX, "%s/%d", COMMS_DIR, nodeid); rv = create_path(path); if (rv) return -1; /* * set the nodeid */ memset(path, 0, PATH_MAX); snprintf(path, PATH_MAX, "%s/%d/nodeid", COMMS_DIR, nodeid); fd = open(path, O_WRONLY); if (fd < 0) { log_error("%s: open failed: %d", path, errno); return -1; } memset(buf, 0, sizeof(buf)); snprintf(buf, 32, "%d", nodeid); rv = do_write(fd, buf, strlen(buf)); if (rv < 0) { log_error("%s: write failed: %d, %s", path, errno, buf); close(fd); return -1; } close(fd); /* * set the address */ memset(padded_addr, 0, sizeof(padded_addr)); memcpy(padded_addr, addr, addrlen); memset(path, 0, PATH_MAX); snprintf(path, PATH_MAX, "%s/%d/addr", COMMS_DIR, nodeid); fd = open(path, O_WRONLY); if (fd < 0) { log_error("%s: open failed: %d", path, errno); return -1; } rv = do_write(fd, padded_addr, sizeof(struct sockaddr_storage)); if (rv < 0) { log_error("%s: write failed: %d %d", path, errno, rv); close(fd); return -1; } close(fd); /* * set local */ if (!local) goto out; memset(path, 0, PATH_MAX); snprintf(path, PATH_MAX, "%s/%d/local", COMMS_DIR, nodeid); fd = open(path, O_WRONLY); if (fd < 0) { log_error("%s: open failed: %d", path, errno); return -1; } rv = do_write(fd, (void *)"1", strlen("1")); if (rv < 0) { log_error("%s: write failed: %d", path, errno); close(fd); return -1; } close(fd); out: return 0; }