Skip to content

Commit 602575e

Browse files
committed
Add client-tls-http.c example
1 parent 9dde24d commit 602575e

File tree

1 file changed

+3
-28
lines changed

1 file changed

+3
-28
lines changed

tls/client-tls-http.c

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <stdlib.h>
2424
#include <stdio.h>
2525
#include <string.h>
26-
#include<stdint.h>
2726
#include<sys/types.h>
2827

2928
/* socket includes */
@@ -43,8 +42,6 @@
4342
int main(int argc, char** argv)
4443
{
4544
int sockfd;
46-
struct sockaddr_in servAddr;
47-
struct in_addr addr;
4845
struct addrinfo hints,*res;
4946
char buff[256];
5047
size_t len;
@@ -74,12 +71,6 @@ int main(int argc, char** argv)
7471
ret = -1;
7572
goto end;
7673
}
77-
78-
/* Assign server IP to in_addr struct */
79-
addr.s_addr = ((struct sockaddr_in *)(res->ai_addr))->sin_addr.s_addr;
80-
81-
/* Free a list pointed by res */
82-
freeaddrinfo(res);
8374

8475
/* Create a socket that uses an internet IPv4 address,
8576
* Sets the socket to be stream based (TCP),
@@ -89,31 +80,15 @@ int main(int argc, char** argv)
8980
ret = -1;
9081
goto end;
9182
}
92-
93-
/* Initialize the server address struct with zeros */
94-
memset(&servAddr, 0, sizeof(servAddr));
95-
96-
/* Fill in the server address */
97-
servAddr.sin_family = AF_INET; /* using IPv4 */
98-
servAddr.sin_port = htons(DEFAULT_PORT); /* on DEFAULT_PORT */
99-
100-
/* Get the server IPv4 address using adderinfo struct
101-
* convert bytes to const char* via inet_ntoa() */
102-
if (inet_pton(AF_INET, inet_ntoa(addr), &servAddr.sin_addr) != 1) {
103-
fprintf(stderr, "ERROR: invalid address\n");
104-
ret = -1;
105-
goto end;
106-
}
83+
/* Free a list pointed by res */
84+
freeaddrinfo(res);
10785

10886
/* Connect to the server */
109-
if ((ret = connect(sockfd, (struct sockaddr*) &servAddr, sizeof(servAddr)))
110-
== -1) {
87+
if ((ret = connect(sockfd, res->ai_addr, res->ai_addrlen)) == -1) {
11188
fprintf(stderr, "ERROR: failed to connect\n");
11289
goto end;
11390
}
11491

115-
116-
11792
/*---------------------------------*/
11893
/* Start of wolfSSL initialization and configuration */
11994
/*---------------------------------*/

0 commit comments

Comments
 (0)