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__) 80 struct sockaddr_in serv_addr;
81 struct hostent *server;
85 server = gethostbyname (hostname);
88 clib_warning (
"Couldn't translate server name %s", hostname);
93 sockfd = socket (AF_INET, SOCK_STREAM, 0);
101 bzero ((
char *) &serv_addr,
sizeof (serv_addr));
102 serv_addr.sin_family = AF_INET;
103 bcopy ((
char *) server->h_addr,
104 (
char *) &serv_addr.sin_addr.s_addr, server->h_length);
105 serv_addr.sin_port = htons (port);
107 if (connect (sockfd, (
const void *) &serv_addr,
sizeof (serv_addr)) < 0)
114 rv = ioctl (sockfd, FIONBIO, &one);
123 memset (rp, 0,
sizeof (*rp));
129 template.file_descriptor = sockfd;
133 rp->
name =
format (0,
"%s:%d", hostname, port);
136 mp->_vl_msg_id = ntohs (VL_API_SOCKCLNT_CREATE);
139 if (gethostname (my_hostname,
sizeof (my_hostname)) < 0)
142 strncpy (my_hostname,
"unknown!",
sizeof (my_hostname) - 1);
144 strncpy ((
char *) mp->
name, my_hostname, sizeof (mp->
name) - 1);
159 clib_warning (
"registration_pool index %d already free", index);
165 mp->_vl_msg_id = ntohs (VL_API_SOCKCLNT_DELETE);
181 #define foreach_sockclnt_api_msg \ 182 _(SOCKCLNT_CREATE_REPLY, sockclnt_create_reply) \ 183 _(SOCKCLNT_DELETE_REPLY, sockclnt_delete_reply) 190 vl_msg_api_set_handlers(VL_API_##N, #n, \ 191 vl_api_##n##_t_handler, \ 193 vl_api_##n##_t_endian, \ 194 vl_api_##n##_t_print, \ 195 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
void sockclnt_close_index(u32 index)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
clib_error_t * vl_socket_read_ready(struct unix_file *uf)
socket_main_t socket_main
void * vl_msg_api_alloc(int nbytes)
vl_registration_type_t registration_type
static clib_error_t * sockclnt_vlib_api_init(vlib_main_t *vm)
static uword unix_file_add(unix_main_t *um, unix_file_t *template)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
vl_api_registration_t * sockclnt_get_registration(u32 index)
#define clib_warning(format, args...)
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
void vl_free_socket_registration_index(u32 pool_index)
clib_error_t * vl_socket_write_ready(struct unix_file *uf)
u32 sockclnt_open_index(char *client_name, char *hostname, int port)
#define clib_unix_warning(format, args...)
u32 vl_api_registration_pool_index
void vl_msg_api_send(vl_api_registration_t *rp, u8 *elem)
static void unix_file_del(unix_main_t *um, unix_file_t *f)