sic

simple irc client
git clone git://git.suckless.org/sic
Log | Files | Refs | README | LICENSE

commit ca6ba9a64a1332bf2bb4fac4b08030812dc3ff07
parent f3827eec2a299cb0a556f9db12206e97d0f6e390
Author: a@null <unknown>
Date:   Sat, 14 Feb 2009 11:53:47 +0000

applied Jeroen Schot's patch
Diffstat:
LICENSE | 4+++-
sic.1 | 2+-
sic.c | 36+++++++++++++++++++-----------------
3 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -1,6 +1,8 @@ MIT/X Consortium License -© 2005-2008 Anselm R Garbe <garbeam at gmail dot com> + +© 2005-2009 Anselm R Garbe <garbeam at gmail dot com> +© 2008-2009 Jeroen Schot <schot at a-eskwadraat dot nl> © 2005 Nico Golde <nico at ngolde dot de> Permission is hereby granted, free of charge, to any person obtaining a diff --git a/sic.1 b/sic.1 @@ -17,7 +17,7 @@ different channel buffers, that's actually a feature. .SH OPTIONS .TP .B \-h <host> -Overrides the default host (irc.oftc.net) +Overrides the default host (irc6.oftc.net) .TP .B \-p <port> Overrides the default port (6667) diff --git a/sic.c b/sic.c @@ -1,6 +1,4 @@ -/* © 2005-2008 Anselm R Garbe <garbeam at gmail dot com> - * © 2005 Nico Golde <nico at ngolde dot de> - * See LICENSE file for license details. */ +/* See LICENSE file for license details. */ #include <errno.h> #include <netdb.h> #include <netinet/in.h> @@ -23,8 +21,8 @@ static void parsein(char *msg); static void parsesrv(char *msg); static int readl(int fd, unsigned int len, char *buf); -static char *host = "irc.oftc.net"; -static unsigned short port = 6667; +static char *host = "irc6.oftc.net"; +static char *port = "6667"; static char *password = NULL; static char nick[32]; @@ -161,8 +159,7 @@ int main(int argc, char *argv[]) { int i; struct timeval tv; - struct hostent *hp; - static struct sockaddr_in addr; /* initially filled with 0's */ + static struct addrinfo hints, *res, *r; char ping[256]; fd_set rd; @@ -172,7 +169,7 @@ main(int argc, char *argv[]) { if(++i < argc) host = argv[i]; } else if(!strncmp(argv[i], "-p", 3)) { - if(++i < argc) port = (unsigned short)atoi(argv[i]); + if(++i < argc) port = argv[i]; } else if(!strncmp(argv[i], "-n", 3)) { if(++i < argc) strncpy(nick, argv[i], sizeof nick); @@ -181,22 +178,27 @@ main(int argc, char *argv[]) { if(++i < argc) password = argv[i]; } else if(!strncmp(argv[i], "-v", 3)) - die("sic-"VERSION", © 2005-2008 Anselm R Garbe, Nico Golde\n"); + die("sic-"VERSION", © 2005-2009 sic engineers\n"); else die("usage: sic [-h host] [-p port] [-n nick] [-k keyword] [-v]\n"); /* init */ - if((srv = socket(AF_INET, SOCK_STREAM, 0)) < 0) - die("error: cannot connect host '%s'\n", host); - if(NULL == (hp = gethostbyname(host))) + memset(&hints, 0, sizeof hints); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + if(getaddrinfo(host, port, &hints, &res) != 0) die("error: cannot resolve hostname '%s'\n", host); - addr.sin_family = AF_INET; - addr.sin_port = htons(port); - memcpy(&addr.sin_addr, hp->h_addr, hp->h_length); - if(connect(srv, (struct sockaddr *) &addr, sizeof(struct sockaddr_in))) { + for(ri = res; r; r = r->ai_next) { + if((srv = socket(r->ai_family, r->ai_socktype, r->ai_protocol)) == -1) + continue; + if(connect(srv, r->ai_addr, r->ai_addrlen) == 0) + break; close(srv); - die("error: cannot connect host '%s'\n", host); } + freeaddrinfo(res); + if(!r) + die("error: cannot connect to host '%s'\n", host); + /* login */ if(password) snprintf(bufout, sizeof bufout,