anntp

a nntp implementation in pure C99
Log | Files | Refs | README | LICENSE

commit 9d48529167584efb233efa581dcdab6b52f961a6
parent 0828d8d9f708e72016d48dba85f5b62511961a8c
Author: Mario Rosell R. Martinez <mario@mariorosell.es>
Date:   Wed, 18 Mar 2026 19:24:36 +0100

Add some stuff

Diffstat:
A.gitignore | 6++++++
Manntp.h | 16++++++----------
Dtest.c | 2--
3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,6 @@ +test.c +*.o +a.out +thumbs.db +.DS_Store + diff --git a/anntp.h b/anntp.h @@ -67,7 +67,7 @@ struct anntp_connection { size_t read_len; /* current length of data in buffer */ }; -ANNTP_API AnntpConnection* anntp_mkconn(const char* host, int port); +ANNTP_API AnntpConnection* anntp_mkconn(const char* host, char* port, Bool tls); ANNTP_API void anntp_freeconn(AnntpConnection* conn); ANNTP_API int anntp_connect(AnntpConnection* conn); ANNTP_API ssize_t anntp_read(AnntpConnection* conn, uchar_t* buf, size_t bufsize); @@ -86,20 +86,20 @@ anntp_init(void) } AnntpConnection* -anntp_mkconn(const char* host, Bool tls) +anntp_mkconn(const char* host, char* port, Bool tls) { /* do some initting */ AnntpConnection* cv = (AnntpConnection*)ANNTP_MALLOC(sizeof(AnntpConnection)); if (!cv) return NULL; /* check errno */ - memset(cv, 0, sizeof(cv)); + memset(cv, 0, sizeof(*cv)); cv->host = strdup(host); cv->use_tls = tls; cv->state = ANS_OFF; /* first, we get a nice nonblocking two-way socket over TCP from the kernel... */ - cv->fd = socket(AF_INET, SOCK_STREAM, SOCK_NONBLOCK); + cv->fd = socket(AF_INET, SOCK_STREAM, 0); if (cv->fd < 0) { perror("anntp - making connection socket"); goto cleanup; @@ -112,7 +112,7 @@ anntp_mkconn(const char* host, Bool tls) hints.ai_socktype = SOCK_STREAM; /* look mom! i made go in c! */ - int err = getaddrinfo(host, NULL, &hints, &res); + int err = getaddrinfo(host, port, &hints, &res); if (err != 0) { fprintf(stderr, "anntp - cant resolve host `%s': %s", host, gai_strerror(err)); /* if you find whoever made this function of *HELL*, tell him how much i hate him */ close(cv->fd); @@ -121,9 +121,7 @@ anntp_mkconn(const char* host, Bool tls) if (res) { struct sockaddr_in* sa = (struct sockaddr_in*)res->ai_addr; - /* store info */ - memcpy(&cv->host_he->h_addr_list, &sa->sin_addr, sizeof(struct in_addr)); - cv->host_he->h_name = strdup(host); + cv->addr = sa->sin_addr; } freeaddrinfo(res); @@ -137,7 +135,5 @@ cleanup: return NULL; } - - #endif /* ANNTP_IMPLEMENTATION */ diff --git a/test.c b/test.c @@ -1,2 +0,0 @@ -#define ANNTP_IMPLEMENTATION -#include "anntp.h"