This commit is contained in:
plky 2026-01-16 16:14:43 -05:00
parent 910653f5e8
commit d71ddf70cc
2 changed files with 34 additions and 7 deletions

View File

@ -30,6 +30,10 @@ if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/openssl/Configure")
message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.") message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif() endif()
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/log.c/src/log.c")
message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif()
set(EXTERN "${PROJECT_SOURCE_DIR}/extern") set(EXTERN "${PROJECT_SOURCE_DIR}/extern")
add_executable(${PROJECT_NAME} add_executable(${PROJECT_NAME}

View File

@ -1,9 +1,11 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <errno.h> #include <errno.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <openssl/err.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <openssl/ssl3.h> #include <openssl/ssl.h>
#include <openssl/types.h>
#include <netdb.h> #include <netdb.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
@ -22,10 +24,23 @@ die(const char *errstr, ...) {
exit(1); exit(1);
} }
// Client connection void
die_ssl(const char *errstr, ...) {
va_list ap;
va_start(ap, errstr);
vfprintf(stderr, errstr, ap);
va_end(ap);
ERR_print_errors_fp(stderr);
exit(1);
}
typedef struct { typedef struct {
int fd; int fd;
} cconnection_t; SSL_CTX *ctx;
SSL *ssl;
} ClientConnection;
void* void*
get_in_addr(struct sockaddr *addr) { get_in_addr(struct sockaddr *addr) {
@ -36,9 +51,13 @@ get_in_addr(struct sockaddr *addr) {
return &((struct sockaddr_in6*)addr)->sin6_addr; return &((struct sockaddr_in6*)addr)->sin6_addr;
} }
enum { err_size = 512 };
char err[err_size];
// Returns error or nullptr // Returns error or nullptr
char* char*
connect_server(char *hostname, char *port, cconnection_t *connection) { connect_tcp(char *hostname, char *port, int *clientfd) {
int rv; int rv;
struct addrinfo hints, *res, *p; struct addrinfo hints, *res, *p;
@ -70,8 +89,6 @@ connect_server(char *hostname, char *port, cconnection_t *connection) {
} }
if (p == nullptr) { if (p == nullptr) {
ssize_t err_size = 512;
char *err = malloc(512);
snprintf(err, err_size, "Failed to connect to %s:%s", hostname, port); snprintf(err, err_size, "Failed to connect to %s:%s", hostname, port);
return err; return err;
} }
@ -82,8 +99,14 @@ connect_server(char *hostname, char *port, cconnection_t *connection) {
return nullptr; return nullptr;
} }
char*
bind_tcp(char *port) {
}
int int
main() { main() {
if(nullptr == NULL) return 1;
return 0; return 0;
} }