Removed Respond method so that code reads more linearly
parent
cc5286594d
commit
95461c350f
|
@ -36,31 +36,6 @@
|
||||||
#define LISTENQ 1024
|
#define LISTENQ 1024
|
||||||
#define SERV_PORT 11111
|
#define SERV_PORT 11111
|
||||||
|
|
||||||
/*
|
|
||||||
* Handles response to client.
|
|
||||||
*/
|
|
||||||
int Respond(WOLFSSL* ssl)
|
|
||||||
{
|
|
||||||
int n; /* length of string read */
|
|
||||||
char buf[MAXLINE]; /* string read from client */
|
|
||||||
char response[] = "I hear ya for shizzle";
|
|
||||||
memset(buf, 0, MAXLINE);
|
|
||||||
n = wolfSSL_read(ssl, buf, MAXLINE);
|
|
||||||
if (n > 0) {
|
|
||||||
printf("%s\n", buf);
|
|
||||||
if (wolfSSL_write(ssl, response, strlen(response)) > strlen(response)) {
|
|
||||||
printf("Fatal error : respond: write error\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (n < 0) {
|
|
||||||
printf("Fatal error :respond: read error\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Identify which psk key to use.
|
* Identify which psk key to use.
|
||||||
*/
|
*/
|
||||||
|
@ -84,10 +59,13 @@ static unsigned int my_psk_server_cb(WOLFSSL* ssl, const char* identity,
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
int n; /* length of string read */
|
||||||
int listenfd, connfd;
|
int listenfd, connfd;
|
||||||
int opt;
|
int opt;
|
||||||
struct sockaddr_in cliAddr, servAddr;
|
struct sockaddr_in cliAddr, servAddr;
|
||||||
char buff[MAXLINE];
|
char buff[MAXLINE];
|
||||||
|
char buf[MAXLINE]; /* string read from client */
|
||||||
|
char response[] = "I hear ya for shizzle";
|
||||||
socklen_t cliLen;
|
socklen_t cliLen;
|
||||||
WOLFSSL_CTX* ctx;
|
WOLFSSL_CTX* ctx;
|
||||||
|
|
||||||
|
@ -160,8 +138,25 @@ int main()
|
||||||
printf("Fatal error : wolfSSL_new error\n");
|
printf("Fatal error : wolfSSL_new error\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* sets the file descriptor of the socket for the ssl session */
|
||||||
wolfSSL_set_fd(ssl, connfd);
|
wolfSSL_set_fd(ssl, connfd);
|
||||||
if (Respond(ssl) != 0) {
|
|
||||||
|
/* making sure buffered to store data sent from client is emprty */
|
||||||
|
memset(buf, 0, MAXLINE);
|
||||||
|
|
||||||
|
/* reads and displays data sent by client if no errors occur */
|
||||||
|
n = wolfSSL_read(ssl, buf, MAXLINE);
|
||||||
|
if (n > 0) {
|
||||||
|
printf("%s\n", buf);
|
||||||
|
/* server response */
|
||||||
|
if (wolfSSL_write(ssl, response, strlen(response)) > strlen(response)) {
|
||||||
|
printf("Fatal error : respond: write error\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (n < 0) {
|
||||||
|
printf("Fatal error :respond: read error\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue