1010
1111#include "../src/proxy_protocol.h"
1212
13- int main ()
13+ int main (void )
1414{
15- /* Create a v1 PROXY protocol header */
15+ int32_t error = ERR_NULL ;
16+ int32_t rc ;
17+
1618 pp_info_t pp_info_in_v1 = {
17- .address_family = ADDR_FAMILY_INET ,
18- .transport_protocol = TRANSPORT_PROTOCOL_STREAM ,
19- .src_addr = "172.22.32.1" ,
20- .dst_addr = "172.22.33.1" ,
21- .src_port = 4040 ,
22- .dst_port = 443
19+ ADDR_FAMILY_INET ,
20+ TRANSPORT_PROTOCOL_STREAM ,
21+ "172.22.32.1" ,
22+ "172.22.33.1" ,
23+ 4040 ,
24+ 443 ,
25+ { 0 }
2326 };
24- uint16_t pp1_hdr_len ;
25- int32_t error ;
26- uint8_t * pp1_hdr = pp_create_hdr (1 , & pp_info_in_v1 , & pp1_hdr_len , & error );
27+ uint8_t * pp1_hdr = NULL ;
28+ uint16_t pp1_hdr_len = 0 ;
29+
30+ pp_info_t pp_info_in_v2 = {
31+ ADDR_FAMILY_INET ,
32+ TRANSPORT_PROTOCOL_STREAM ,
33+ "192.168.10.100" ,
34+ "192.168.11.90" ,
35+ 42332 ,
36+ 8080 ,
37+ { 0 }
38+ };
39+ uint8_t * pp2_hdr = NULL ;
40+ uint16_t pp2_hdr_len = 0 ;
41+
42+ pp_info_t pp_info_out = { 0 };
43+
44+ /* Create a v1 PROXY protocol header */
45+ pp1_hdr = pp_create_hdr (1 , & pp_info_in_v1 , & pp1_hdr_len , & error );
2746 /* Clear the pp_info passed in pp_create_hdr(). Not really needed for v1 but good to do out of principle */
2847 pp_info_clear (& pp_info_in_v1 );
2948 if (error != ERR_NULL )
@@ -33,8 +52,7 @@ int main()
3352 }
3453
3554 /* Parse a v1 PROXY protocol header */
36- pp_info_t pp_info_out ;
37- int32_t rc = pp_parse_hdr (pp1_hdr , pp1_hdr_len , & pp_info_out );
55+ rc = pp_parse_hdr (pp1_hdr , pp1_hdr_len , & pp_info_out );
3856 free (pp1_hdr );
3957 if (!rc )
4058 {
@@ -57,27 +75,16 @@ int main()
5775 pp_info_clear (& pp_info_out );
5876
5977 /* Create a v2 PROXY protocol header with some TLVs */
60- pp_info_t pp_info_in_v2 = {
61- .address_family = ADDR_FAMILY_INET ,
62- .transport_protocol = TRANSPORT_PROTOCOL_STREAM ,
63- .src_addr = "192.168.10.100" ,
64- .dst_addr = "192.168.11.90" ,
65- .src_port = 42332 ,
66- .dst_port = 8080 ,
67- .pp2_info = {
68- .crc32c = 1 , /* Add crc32c checksum */
69- .pp2_ssl_info = { /* Add SSL information */
70- .ssl = 1 ,
71- .cert_in_connection = 1 ,
72- .cert_in_session = 1 ,
73- .cert_verified = 1 ,
74- }
75- }
76- };
77- uint16_t pp2_hdr_len ;
78+ /* Add crc32c checksum */
79+ pp_info_in_v2 .pp2_info .crc32c = 1 ;
80+ /* Add SSL information */
81+ pp_info_in_v2 .pp2_info .pp2_ssl_info .ssl = 1 ;
82+ pp_info_in_v2 .pp2_info .pp2_ssl_info .cert_in_connection = 1 ;
83+ pp_info_in_v2 .pp2_info .pp2_ssl_info .cert_in_session = 1 ;
84+ pp_info_in_v2 .pp2_info .pp2_ssl_info .cert_verified = 1 ;
7885 /* Add SSL TLVs */
7986 /* IMPORTANT: Always clear the pp_info to be passed in pp_create_hdr() because TLVs are allocated in heap. Otherwise memory will be leaked */
80- if (!pp_info_add_ssl (& pp_info_in_v2 , "TLSv1.2" , "ECDHE-RSA-AES128-GCM-SHA256" , "SHA256" , "RSA2048" , (uint8_t * ) "example.com" , 11 ))
87+ if (!pp_info_add_ssl (& pp_info_in_v2 , "TLSv1.2" , "ECDHE-RSA-AES128-GCM-SHA256" , "SHA256" , "RSA2048" , (const uint8_t * ) "example.com" , 11 ))
8188 {
8289 fprintf (stderr , "pp_info_add_ssl() failed\n" );
8390 pp_info_clear (& pp_info_in_v2 );
@@ -90,7 +97,7 @@ int main()
9097 pp_info_clear (& pp_info_in_v2 );
9198 return EXIT_FAILURE ;
9299 }
93- uint8_t * pp2_hdr = pp_create_hdr (2 , & pp_info_in_v2 , & pp2_hdr_len , & error );
100+ pp2_hdr = pp_create_hdr (2 , & pp_info_in_v2 , & pp2_hdr_len , & error );
94101 pp_info_clear (& pp_info_in_v2 );
95102 if (error != ERR_NULL )
96103 {
@@ -114,10 +121,10 @@ int main()
114121 else
115122 {
116123 uint16_t length , cn_length ;
117- const uint8_t * azure_linkid = pp_info_get_azure_linkid (& pp_info_out , & length );
118124 uint32_t linkid ;
119- memcpy ( & linkid , azure_linkid , length );
125+ const uint8_t * azure_linkid = pp_info_get_azure_linkid ( & pp_info_out , & length );
120126 const uint8_t * cn = pp_info_get_ssl_cn (& pp_info_out , & cn_length );
127+ memcpy (& linkid , azure_linkid , length );
121128 printf ("%d bytes PROXY protocol header:\n"
122129 "\tAzure Link ID: %u\n"
123130 "\tCRC32C checksum: %s\n"
0 commit comments