2024-10-04 05:05:43 +00:00
|
|
|
// main.c
|
|
|
|
|
2024-10-05 08:58:16 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include "error.h"
|
|
|
|
#include "sock.h"
|
2024-10-04 05:05:43 +00:00
|
|
|
|
|
|
|
int main(void) {
|
2024-10-05 08:58:16 +00:00
|
|
|
enum error_t err = ERR_OK;
|
|
|
|
|
|
|
|
int sock;
|
|
|
|
err = sock_init(&sock);
|
|
|
|
if (err) goto handle_error;
|
|
|
|
|
|
|
|
char ibuf[1028] = { 0 };
|
|
|
|
char obuf[1028] = { 0 };
|
|
|
|
strcpy(obuf, "Hello, world!\n");
|
|
|
|
|
|
|
|
// Just echoing everything back for now
|
|
|
|
write(sock, obuf, 1028);
|
|
|
|
int rc = read(sock, ibuf, 1028);
|
|
|
|
|
|
|
|
if (rc > 0) printf("%s", ibuf);
|
|
|
|
|
|
|
|
close(sock);
|
|
|
|
return ERR_OK;
|
2024-10-04 05:05:43 +00:00
|
|
|
|
2024-10-05 08:58:16 +00:00
|
|
|
handle_error:
|
|
|
|
printf("ERROR: %s\n", ERROR_STRS[err]);
|
|
|
|
return err;
|
2024-10-04 05:05:43 +00:00
|
|
|
}
|