diff options
| author | cashmere <cashmere@autistici.org> | 2026-06-30 22:45:56 +0200 |
|---|---|---|
| committer | cashmere <cashmere@autistici.org> | 2026-06-30 22:45:56 +0200 |
| commit | 03ea2388a79dd428f20542380f22d64500659298 (patch) | |
| tree | 61f5fceed2306211a0485cef9ba6f8c550548179 | |
| parent | 9b1156e6735c5212b691069f0d9b3a0434fa7e9e (diff) | |
| download | telnet-03ea2388a79dd428f20542380f22d64500659298.tar.gz | |
src/main.c: add struct client
| -rw-r--r-- | src/main.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -4,6 +4,11 @@ #include <sys/socket.h> #include <unistd.h> +struct client { + char nickname[32]; + int has_nickname; +}; + // returns a socket file descriptor. // if connection could not be established, -1 gets returned int establish_connection(struct sockaddr_in addr) { @@ -61,8 +66,7 @@ int process_message(struct pollfd *fds, nfds_t *nfds) { (*nfds)--; /* size down the current array */ i--; return -1; - } - else { + } else { /* send every message bytes to the other clients */ for (nfds_t j = 1; j < *nfds; j++) { if (j != i) { @@ -80,6 +84,7 @@ int main() { addr.sin_family = AF_INET; /* IPv4 */ addr.sin_port = htons(8000); /* Port */ addr.sin_addr.s_addr = INADDR_ANY; /* equals to 0.0.0.0 */ + struct client clients[256]; struct pollfd fds[256]; int sfd = establish_connection(addr); if (sfd == -1) { |
