summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcashmere <cashmere@autistici.org>2026-06-30 22:47:06 +0200
committercashmere <cashmere@autistici.org>2026-06-30 22:47:06 +0200
commiteb050ea4a53d750125eedb27ec3e84356cb1b88d (patch)
treee61cbaeb11d4086fa18d05c793e17560e9a05b78
parent03ea2388a79dd428f20542380f22d64500659298 (diff)
downloadtelnet-eb050ea4a53d750125eedb27ec3e84356cb1b88d.tar.gz
src/main.c: include struct client into handle_new_connection
-rw-r--r--src/main.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index 4847bab..761ef9b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -33,18 +33,21 @@ int establish_connection(struct sockaddr_in addr) {
// handles new telnet connections.
// returns 0 on success and -1 on failure.
-int handle_new_connection(int sfd, struct pollfd *fds, nfds_t *nfds) {
+int handle_new_connection(int sfd, struct pollfd *fds, nfds_t *nfds,
+ struct client *clients) {
int conn = accept(sfd, NULL, NULL);
if (conn == -1)
return -1;
fds[*nfds].fd = conn;
fds[*nfds].events = POLLIN;
+ clients[*nfds].has_nickname = 0;
(*nfds)++;
return 0;
}
// process message to all the connected clients.
// returns 0 on success and -1 on failure.
+// TODO: add struct client *clients
int process_message(struct pollfd *fds, nfds_t *nfds) {
for (nfds_t i = 1; i < *nfds; i++) {
/* if client has something to say */
@@ -104,7 +107,7 @@ int main() {
return 1;
}
if (fds[0].revents & POLLIN) {
- if (handle_new_connection(sfd, fds, &nfds) == -1) {
+ if (handle_new_connection(sfd, fds, &nfds, clients) == -1) {
perror("could not accept connection");
continue;
}