Move common definitions to dtls-common.h

pull/323/head
Juliusz Sosinowicz 2022-06-28 12:19:43 +02:00
parent 109e07ae4d
commit 88cf4e3e5e
4 changed files with 15 additions and 25 deletions

View File

@ -39,11 +39,6 @@
#include "dtls-common.h"
#define MAXLINE 4096
#define SERV_PORT 11111
#define LOOP_LIMIT 5
#define SFD_TIMEOUT 1
int main (int argc, char** argv)
{
/* standard variables used in a dtls client*/
@ -55,7 +50,6 @@ int main (int argc, char** argv)
struct sockaddr_in servAddr;
WOLFSSL* ssl = NULL;
WOLFSSL_CTX* ctx = NULL;
char* certs = "../certs/ca-cert.pem";
char sendLine[MAXLINE];
char recvLine[MAXLINE - 1];
@ -80,9 +74,9 @@ int main (int argc, char** argv)
}
/* Load certificates into ctx variable */
if (wolfSSL_CTX_load_verify_locations(ctx, certs, 0)
if (wolfSSL_CTX_load_verify_locations(ctx, caCertLoc, 0)
!= SSL_SUCCESS) {
fprintf(stderr, "Error loading %s, please check the file.\n", certs);
fprintf(stderr, "Error loading %s, please check the file.\n", caCertLoc);
goto cleanup;
}

View File

@ -24,7 +24,16 @@
#ifndef DTLS_COMMON_H_
#define DTLS_COMMON_H_
#define INVALID_SOCKET (-1)
#define INVALID_SOCKET -1
#define MAXLINE 4096
#define SERV_PORT 11111
#define LOOP_LIMIT 5
#define SFD_TIMEOUT 1
/* Loc short for "location" */
const char caCertLoc[] = "../certs/ca-cert.pem";
const char servCertLoc[] = "../certs/server-cert.pem";
const char servKeyLoc[] = "../certs/server-key.pem";
void showConnInfo(WOLFSSL* ssl) {
printf("New connection established using %s %s\n",

View File

@ -1,4 +1,4 @@
/* server-dtls13.c
/* server-dtls13-event.c
*
* Copyright (C) 2006-2022 wolfSSL Inc.
*
@ -45,8 +45,6 @@
#include "dtls-common.h"
#define SERV_PORT 11111 /* define our server port number */
#define MSGLEN 4096
#define QUICK_MULT 4 /* Our quick timeout multiplier */
#define CHGOODCB_E (-1000) /* An error outside the range of wolfSSL
* errors */
@ -80,10 +78,6 @@ static void conn_ctx_free(conn_ctx* connCtx);
int main(int argc, char** argv)
{
/* Loc short for "location" */
char caCertLoc[] = "../certs/ca-cert.pem";
char servCertLoc[] = "../certs/server-cert.pem";
char servKeyLoc[] = "../certs/server-key.pem";
int exitVal = 1;
/* Initialize wolfSSL before assigning ctx */

View File

@ -39,9 +39,6 @@
#include "dtls-common.h"
#define SERV_PORT 11111 /* define our server port number */
#define MSGLEN 4096
WOLFSSL_CTX* ctx = NULL;
WOLFSSL* ssl = NULL;
int listenfd = INVALID_SOCKET; /* Initialize our socket */
@ -52,9 +49,6 @@ void free_resources(void);
int main(int argc, char** argv)
{
/* Loc short for "location" */
char caCertLoc[] = "../certs/ca-cert.pem";
char servCertLoc[] = "../certs/server-cert.pem";
char servKeyLoc[] = "../certs/server-key.pem";
int exitVal = 1;
struct sockaddr_in servAddr; /* our server's address */
struct sockaddr_in cliaddr; /* the client's address */
@ -62,8 +56,7 @@ int main(int argc, char** argv)
int err;
int recvLen = 0; /* length of message */
socklen_t cliLen;
unsigned char b[MSGLEN]; /* watch for incoming messages */
char buff[MSGLEN]; /* the incoming message */
char buff[MAXLINE]; /* the incoming message */
char ack[] = "I hear you fashizzle!\n";
/* Initialize wolfSSL before assigning ctx */
@ -124,7 +117,7 @@ int main(int argc, char** argv)
printf("Awaiting client connection on port %d\n", SERV_PORT);
cliLen = sizeof(cliaddr);
ret = (int)recvfrom(listenfd, (char *)&b, sizeof(b), MSG_PEEK,
ret = (int)recvfrom(listenfd, (char *)&buff, sizeof(buff), MSG_PEEK,
(struct sockaddr*)&cliaddr, &cliLen);
if (ret < 0) {