int main(int argc, char **argv) { int max_fd; fd_set rfds; struct timeval time_out; ipmi_json_ipc_header_t header; unsigned char ipmi_data[] = "1"; int fd_client = -1; fd_client = create_udp_listen(INADDR_LOOPBACK, rmm_cfg_get_port(IPMIJSONRPC_IPMID_PORT)+2, 0, 1); if (fd_client == -1) { printf("Failed to init socket to app!\n"); return -1; } if (0) { header.ip = inet_addr("127.0.0.1"); header.json_ipc_id = 2; memcpy(header.method, "rmcp_req", sizeof("rmcp_req")); header.port = (uint16)rmm_cfg_get_port(IPMIJSONRPC_SERVER_PORT); jrpc_rmcp_req_send(fd_client, header, ipmi_data, 5); } else { header.ip = inet_addr("127.0.0.1"); header.json_ipc_id = 2; memcpy(header.method, "serial_req", sizeof("serial_req")); header.port = (uint16)rmm_cfg_get_port(IPMIJSONRPC_SERVER_PORT); jrpc_serial_req_send(fd_client, header, ipmi_data, 5); } return 0; }
static void create_listen_socket(int *fd) { int port; port = rmm_cfg_get_port(ASSETD_PORT); if (port == 0) { rmm_log(ERROR, "Fail to call port.\n"); exit(-1); } *fd = create_udp_listen(INADDR_LOOPBACK, port, 0, 0); if (*fd < 0) { rmm_log(ERROR, "create udp on port %d error: %s\n", port, strerror(errno)); exit(-1); } return; }
int main(int argc, char **argv) { int rc; int fd = -1; fd_set fds; struct sockaddr_in addr; socklen_t addr_len = sizeof(addr); char buff[1024] = {0}; int port; port = rmm_cfg_get_port(IPMIJSONRPC_SERVER_PORT); printf("port is %d\n", port); if (port == 0) { printf("Failed to call rmm_cfg_get_ipmi_json_rpc_server_port!\n"); exit(-1); } fd = create_udp_listen(INADDR_LOOPBACK, port, 0, 1); if(fd == -1) { printf("Failed to init socket to app!\n"); return -1; } for (;;) { FD_ZERO(&fds); FD_SET(fd, &fds); rc = select(fd + 1, &fds, NULL, NULL, NULL); if (rc < 0) continue; if (FD_ISSET(fd, &fds))/*receive from app*/ rc = recvfrom(fd, buff, 1024, 0, (struct sockaddr *)&addr, &addr_len); if (rc <= 0) continue; printf("test json ipmid: rcv msg is %s\n", buff); } close(fd); return 0; }