20 #include <sys/types.h> 21 #include <sys/socket.h> 23 #include <netinet/in.h> 24 #include <sys/ioctl.h> 41 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) 79 struct sockaddr_in serv_addr;
80 struct hostent *server;
84 server = gethostbyname(hostname);
86 clib_warning(
"Couldn't translate server name %s", hostname);
91 sockfd = socket(AF_INET, SOCK_STREAM, 0);
98 bzero((
char *) &serv_addr,
sizeof(serv_addr));
99 serv_addr.sin_family = AF_INET;
100 bcopy((
char *)server->h_addr,
101 (
char *)&serv_addr.sin_addr.s_addr,
103 serv_addr.sin_port = htons(port);
105 if (connect(sockfd,(
const void *)&serv_addr,
sizeof(serv_addr)) < 0) {
111 rv = ioctl (sockfd, FIONBIO, &one);
118 memset(rp, 0,
sizeof(*rp));
124 template.file_descriptor = sockfd;
128 rp->
name =
format(0,
"%s:%d", hostname, port);
131 mp->_vl_msg_id = ntohs(VL_API_SOCKCLNT_CREATE);
134 if (gethostname(my_hostname,
sizeof (my_hostname)) < 0) {
136 strncpy (my_hostname,
"unknown!",
sizeof(my_hostname)-1);
138 strncpy ((
char *)mp->
name, my_hostname, sizeof (mp->
name)-1);
151 clib_warning (
"registration_pool index %d already free", index);
157 mp->_vl_msg_id = ntohs(VL_API_SOCKCLNT_DELETE);
172 #define foreach_sockclnt_api_msg \ 173 _(SOCKCLNT_CREATE_REPLY, sockclnt_create_reply) \ 174 _(SOCKCLNT_DELETE_REPLY, sockclnt_delete_reply) 181 vl_msg_api_set_handlers(VL_API_##N, #n, \ 182 vl_api_##n##_t_handler, \ 184 vl_api_##n##_t_endian, \ 185 vl_api_##n##_t_print, \ 186 sizeof(vl_api_##n##_t), 1);
static void vl_api_sockclnt_delete_reply_t_handler(vl_api_sockclnt_delete_reply_t *mp)
static void vl_api_sockclnt_create_reply_t_handler(vl_api_sockclnt_create_reply_t *mp)
VLIB_API_INIT_FUNCTION(sockclnt_vlib_api_init)
vl_api_registration_t * registration_pool
#define foreach_sockclnt_api_msg
vl_api_registration_t * current_rp
always_inline uword unix_file_add(unix_main_t *um, unix_file_t *template)
void sockclnt_close_index(u32 index)
clib_error_t * vl_socket_read_ready(struct unix_file *uf)
socket_main_t socket_main
#define clib_warning(format, args...)
vl_registration_type_t registration_type
static clib_error_t * sockclnt_vlib_api_init(vlib_main_t *vm)
#define pool_elt_at_index(p, i)
vl_api_registration_t * sockclnt_get_registration(u32 index)
void * vl_msg_api_alloc(int nbytes)
#define clib_unix_warning(format, args...)
#define pool_is_free_index(P, I)
always_inline void unix_file_del(unix_main_t *um, unix_file_t *f)
void vl_free_socket_registration_index(u32 pool_index)
clib_error_t * vl_socket_write_ready(struct unix_file *uf)
void vl_msg_api_send(vl_api_registration_t *rp, u8 *elem)
u32 sockclnt_open_index(char *client_name, char *hostname, int port)
u32 vl_api_registration_pool_index