fixing again little stuff.

master
Steffen Pohle 4 weeks ago
parent f733a563c9
commit 5f35e868d5

@ -61,13 +61,16 @@ using namespace std;
* global functions needed for networking * global functions needed for networking
* *
*/ */
extern int UDPTCPNetwork_init;
int dns_filladdr (string host, string port, int ai_family, int dns_filladdr (string host, string port, int ai_family,
struct sockaddr_storage *sAddr); struct sockaddr_storage *sAddr);
char *itoa(char* buffer, int number, int size); char *itoa(char* buffer, int number, int size);
void UDPTCPNetwork_Startup(); void UDPTCPNetwork_Startup();
extern int UDPTCPNetwork_init;
#define UDPTCPNetwork() if(UDPTCPNetwork_init == 0) UDPTCPNetwork_Startup() #define UDPTCPNetwork() if(UDPTCPNetwork_init == 0) UDPTCPNetwork_Startup()
int file_is_readable (const char *fname);
/************************************************************************ /************************************************************************
* *
* udp related functions * udp related functions

@ -1,7 +1,11 @@
/*
*
*/
#include "UDPTCPNetwork.h" #include "UDPTCPNetwork.h"
#include <stdio.h> #include <stdio.h>
#include <fcntl.h>
#include <unistd.h> /* close() */ #include <unistd.h> /* close() */
#include <string.h> /* memset() */ #include <string.h> /* memset() */
@ -39,7 +43,7 @@ int dns_filladdr (string host, string port, int ai_family, struct sockaddr_stora
char* itoa(char* buffer, int number, int size) { char* itoa(char* buffer, int number, int size) {
snprintf (buffer, size, "%d", number); snprintf (buffer, size, "%d", number);
return buffer; return buffer;
} };
void UDPTCPNetwork_Startup() { void UDPTCPNetwork_Startup() {
@ -65,4 +69,16 @@ void UDPTCPNetwork_Startup() {
} }
#endif #endif
UDPTCPNetwork_init = 1; UDPTCPNetwork_init = 1;
} };
int file_is_readable (const char *fname) {
int f;
if ((f = open(fname, O_RDONLY)) == -1) return 0;
close (f);
return 1;
};

@ -101,8 +101,8 @@ int SSLSocket::SetCertificat(string certf, string keyf) {
certfile = certf; certfile = certf;
keyfile = keyf; keyfile = keyf;
if (access (certf.c_str(), R_OK) != 0) return 0; if (!file_is_readable(certf.c_str())) return 0;
if (access (keyf.c_str(), R_OK) != 0) return 0; if (!file_is_readable(keyf.c_str())) return 0;
return 1; return 1;
}; };

@ -30,7 +30,7 @@ void server () {
// //
// init SSL // init SSL
printf ("server: setting up certificates\n"); printf ("server: setting up certificates\n");
if (ssl.SetCertificat("cert.pem", "privkey.pem") != 0) { if (ssl.SetCertificat("cert.pem", "privkey.pem") != 1) {
printf ("server: SetCertificat error:%s\n", strerror(errno)); printf ("server: SetCertificat error:%s\n", strerror(errno));
exit (1); exit (1);
} }

Loading…
Cancel
Save