Skip to content

Commit 970d2fc

Browse files
Ron EldorRon Eldor
Ron Eldor
authored and
Ron Eldor
committed
Separate server_name to server_addr and server_name
Seperate the server_name into the `server_addr` which is the address to connect, and to `server_name` which is the server host_name. Sometimes these are not the same
1 parent bb6e65d commit 970d2fc

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

tls-client/HelloHttpsClient.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,18 @@ const char *HelloHttpsClient::HTTP_HELLO_STR = "Hello world!";
7070
const char *HelloHttpsClient::HTTP_OK_STR = "200 OK";
7171

7272
HelloHttpsClient::HelloHttpsClient(const char *in_server_name,
73+
const char *in_server_addr,
7374
const uint16_t in_server_port,
7475
mbedtls_platform_context* in_platform_ctx) :
7576
socket(),
7677
server_name(in_server_name),
78+
server_addr(in_server_addr),
7779
server_port(in_server_port),
7880
/* The platform context is passed just in case any crypto calls need it.
7981
* Please refer to https://github.com/ARMmbed/mbedtls/issues/1200 for more
8082
* information. */
8183
platform_ctx(in_platform_ctx)
84+
8285
{
8386
mbedtls_entropy_init(&entropy);
8487
mbedtls_ctr_drbg_init(&ctr_drbg);
@@ -114,12 +117,12 @@ int HelloHttpsClient::run()
114117
return ret;
115118

116119
/* Start a connection to the server */
117-
if ((ret = socket.connect(server_name, server_port)) != NSAPI_ERROR_OK) {
120+
if ((ret = socket.connect(server_addr, server_port)) != NSAPI_ERROR_OK) {
118121
mbedtls_printf("socket.connect() returned %d\n", ret);
119122
return ret;
120123
}
121124
mbedtls_printf("Successfully connected to %s at port %u\n",
122-
server_name, server_port);
125+
server_addr, server_port);
123126

124127
/* Start the TLS handshake */
125128
mbedtls_printf("Starting the TLS handshake...\n");

tls-client/HelloHttpsClient.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,14 @@ class HelloHttpsClient
5656
* Construct an HelloHttpsClient instance
5757
*
5858
* \param[in] in_server_name
59+
* The server host name
60+
* \param[in] in_server_addr
5961
* The server domain/IP address
6062
* \param[in] in_server_port
6163
* The server port
6264
*/
6365
HelloHttpsClient(const char *in_server_name,
66+
const char *in_server_addr,
6467
const uint16_t in_server_port,
6568
mbedtls_platform_context* in_platform_ctx);
6669

@@ -192,9 +195,14 @@ class HelloHttpsClient
192195
TCPSocket socket;
193196

194197
/**
195-
* The domain/IP address of the server to contact
198+
* The server host name to contact
196199
*/
197200
const char *server_name;
201+
202+
/**
203+
* The domain/IP address of the server to contact
204+
*/
205+
const char *server_addr;
198206
/**
199207
* The port number to use in the connection
200208
*/

tls-client/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
/* Domain/IP address of the server to contact */
4242
const char SERVER_NAME[] = "os.mbed.com";
43+
const char SERVER_ADDR[] = "os.mbed.com";
4344

4445
/* Port used to connect to the server */
4546
const int SERVER_PORT = 443;
@@ -73,8 +74,9 @@ int main()
7374
#endif /* MBEDTLS_MAJOR_VERSION */
7475

7576
/* Allocate a HTTPS client */
76-
client = new (std::nothrow) HelloHttpsClient(SERVER_NAME, SERVER_PORT,
77+
client = new (std::nothrow) HelloHttpsClient(SERVER_NAME, SERVER_ADDR, SERVER_PORT,
7778
&platform_ctx);
79+
7880
if (client == NULL) {
7981
mbedtls_printf("Failed to allocate HelloHttpsClient object\n"
8082
"\nFAIL\n");

0 commit comments

Comments
 (0)