diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-10-24 23:10:31 +0200 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-10-24 23:10:31 +0200 |
commit | f37cce374cc9da243fc2babbea9a7051f15db80a (patch) | |
tree | 7a6b0e5f7bd38cbd39ba1e1f43689ca6be92c53e /send.c | |
parent | c7687f88bc5cb4d25304b0ee19789c37aebd7b6d (diff) |
Archive code into v1/ directory
The code was written too fast and I deemed that it would be better to
make a new draft.
Diffstat (limited to 'send.c')
-rw-r--r-- | send.c | 55 |
1 files changed, 0 insertions, 55 deletions
@@ -1,55 +0,0 @@ -// minimal client implementation -#include "common.h" -#include <arpa/inet.h> -#include <errno.h> -#include <signal.h> -#include <string.h> -#include <time.h> -#include <unistd.h> - -u32 serverfd; - -// NOTE: Errno could be unset and contain an error for a previous command -void debug_panic(const char *msg) -{ - writef("%s errno: %d\n", msg, errno); - raise(SIGINT); -} - -// get current time in timestamp string -void timestamp(char timestamp[MESSAGE_TIMESTAMP_LEN]) -{ - time_t now; - struct tm *ltime; - time(&now); - ltime = localtime(&now); - strftime(timestamp, MESSAGE_TIMESTAMP_LEN, "%H:%M:%S", ltime); -} - -int main(void) -{ - serverfd = socket(AF_INET, SOCK_STREAM, 0); - if (serverfd == -1) - debug_panic("Error while getting socket."); - - const struct sockaddr_in address = { - AF_INET, - htons(PORT), - {0}, - }; - - if (connect(serverfd, (struct sockaddr *)&address, sizeof(address))) - debug_panic("Error while connecting."); - - struct message input = { - .author = "Friendship", - }; - input.text = "Hello from send"; - input.len = str_len(input.text); - printf("input.len: %d\n", input.len); - timestamp(input.timestamp); - - send_message(input, serverfd); - - return 0; -} |