2 * Copyright (c) 2018 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
22 #include <netinet/in.h>
23 #include <arpa/inet.h>
24 #include <sys/socket.h>
27 #include <vcl/vppcom.h>
30 char MESSAGE[] = "Hello, World!\n";
32 static const int PORT = 9995;
35 listener_cb (uint32_t new_session_index, vppcom_endpt_t *ep, void *stuff)
38 vppcom_session_write (new_session_index, &MESSAGE, sizeof (MESSAGE));
39 printf ("\n Heard from port: %d\n", ep->port);
43 typedef struct vppcomm_listener_main_
49 } vppcomm_listener_main_t;
51 vppcomm_listener_main_t _vlm_main;
52 vppcomm_listener_main_t *vlm = &_vlm_main;
56 main (int argc, char **argv)
60 struct sockaddr_in sin;
65 memset (&sin, 0, sizeof (sin));
66 sin.sin_family = AF_INET;
67 sin.sin_port = htons (PORT);
68 //sin.sin_addr.s_addr = inet_addr("127.0.0.1");
70 endpt.is_ip4 = (sin.sin_family == AF_INET);
71 endpt.ip = (uint8_t *) & sin.sin_addr;
72 endpt.port = (uint16_t) sin.sin_port;
75 rv = vppcom_app_create ("test_vcl_listener_server");
78 listen_fd = vppcom_session_create (VPPCOM_PROTO_TCP,
79 0 /* is_nonblocking */ );
81 rv = vppcom_session_bind (listen_fd, &endpt);
83 //Make a listener and dispatch
84 rv = vppcom_session_register_listener (listen_fd, listener_cb, 0,
89 fprintf (stderr, "Could not create a listener!\n");