VCL API for external callback for listener/connect event
[vpp.git] / src / vcl / test_vcl_listener_client.c
1 /*
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:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15
16 #include <stdio.h>
17 #include <sys/socket.h>
18 #include <netinet/in.h>
19 #include <string.h>
20 #include <arpa/inet.h>
21 #include <unistd.h>
22 #include <vcl/vppcom.h>
23
24 int main(){
25   int client_session;
26   char buffer[1024];
27   struct sockaddr_in server_address;
28   vppcom_endpt_t endpt;
29   int rv;
30
31   rv = vppcom_app_create ("test_vcl_listener_client");
32   if (rv) return rv;
33
34   client_session = vppcom_session_create(VPPCOM_PROTO_TCP, 0);
35
36   memset(&server_address, 0, sizeof(server_address));
37   server_address.sin_family = AF_INET;
38   server_address.sin_port = htons(9995);
39   server_address.sin_addr.s_addr = inet_addr("127.0.0.1");
40
41   endpt.is_ip4 = (server_address.sin_family == AF_INET);
42   endpt.ip = (uint8_t *) & server_address.sin_addr;
43   endpt.port = (uint16_t) server_address.sin_port;
44
45
46   vppcom_session_connect(client_session, &endpt);
47
48   /*---- Read the message from the server into the buffer ----*/
49   vppcom_session_read (client_session, buffer, 1024);
50
51   /*---- Print the received message ----*/
52   printf("Data received: %s",buffer);
53
54   printf("Press ENTER key to Continue\n");
55   getchar();
56
57   return 0;
58 }