irC

an attempt at writing an irc "client"
git clone git://bvnf.space/irC.git
Log | Files | Refs | README

commit 99532fb1b1030d24f49807e11a896b90af5e7cc7
parent dee986547578f20d4de344127c73112fe10312cc
Author: aabacchus <ben@bvnf.space>
Date:   Sun, 13 Mar 2022 02:52:37 +0000

irc_identify as nick in separate function

Diffstat:
MirC.c | 13++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/irC.c b/irC.c @@ -21,6 +21,7 @@ void usage(const char *); int sock_write(int sfd, char *msg, ...); int sock_read(int); int server_connect(char *nodename, char *servname); +int irc_identify(int sfd, char *nick); char *get_next_word(char *); int main(int argc, char *argv[]) { @@ -37,6 +38,7 @@ int main(int argc, char *argv[]) { if (sfd == -1) { return 1; } + irc_identify(sfd, nick); size_t linelen = 0; @@ -47,9 +49,6 @@ int main(int argc, char *argv[]) { fds[1].fd = sfd; fds[1].events = POLLIN | POLLWRBAND; - /* connect as nick */ - sock_write(sfd, "NICK %s\r\nUSER %s 8 x :%s\r\n", nick, nick, nick); - while (1) { pollret = poll(fds, 2, -1); if (pollret <= 0) { @@ -62,7 +61,7 @@ int main(int argc, char *argv[]) { int rec = sock_read(sfd); if (rec < 0) return 1; - else if (rec == 0) /* received EOF */ + else if (rec == 0) /* received FIN */ break; } if (fds[0].revents & POLLIN) { @@ -152,6 +151,11 @@ int server_connect(char *nodename, char *servname) { return sfd; } +int irc_identify(int sfd, char *nick) { + return sock_write(sfd, "NICK %s\r\nUSER %s 8 x :%s\r\n", nick, nick, nick); +} + + void usage(const char *argv0){ fprintf(stderr, "usage: %s host port nick\n", argv0); exit(1); @@ -186,7 +190,6 @@ int sock_read(int sfd){ perror("sock_read"); return -1; } - //printf("%s", buff); write(1, buff, ret); return ret; }