changeset: 102:ec556de589a3
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Wed Sep 23 12:52:13 2009 -0400
files: kris/sic.c kris/util.c
description:
Update sic/util.c to match sic.c tip.
diff -r 0cfd0578723c -r ec556de589a3 kris/sic.c
--- a/kris/sic.c Wed Sep 23 11:26:48 2009 -0400
+++ b/kris/sic.c Wed Sep 23 12:52:13 2009 -0400
@@ -18,7 +18,7 @@
#define PINGTIMEOUT 300
static char* host = "irc.oftc.net";
-static ushort port = 6667;
+static char* port = "ircd";
static char* password;
static char nick[32];
@@ -150,7 +150,7 @@
if(++i < argc) host = argv[i];
break;
case 'p':
- if(++i < argc) port = atoi(argv[i]);
+ if(++i < argc) port = argv[i];
break;
case 'n':
if(++i < argc) strlcpy(nick, argv[i], sizeof nick);
diff -r 0cfd0578723c -r ec556de589a3 kris/util.c
--- a/kris/util.c Wed Sep 23 11:26:48 2009 -0400
+++ b/kris/util.c Wed Sep 23 12:52:13 2009 -0400
@@ -21,21 +21,27 @@
}
static int
-dial(char *host, int port) {
- struct hostent *hp;
- static struct sockaddr_in addr;
- int i;
+dial(char *host, char *port) {
+ static struct addrinfo hints;
+ struct addrinfo *res, *r;
+ int srv;
- if((i = socket(AF_INET, SOCK_STREAM, 0)) < 0)
- eprint("sic: cannot connect host '%s':", host);
- if(nil == (hp = gethostbyname(host)))
- eprint("sic: cannot resolve hostname '%s': %s\n", host, hstrerror(h_errno));
- addr.sin_family = AF_INET;
- addr.sin_port = htons(port);
- memcpy(&addr.sin_addr, hp->h_addr, hp->h_length);
- if(connect(i, (struct sockaddr*)&addr, sizeof(struct sockaddr_in)))
- eprint("sic: cannot connect host '%s':", host);
- return i;
+ memset(&hints, 0, sizeof hints);
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ if(getaddrinfo(host, port, &hints, &res) != 0)
+ eprint("error: cannot resolve hostname '%s':", host);
+ for(r = 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);
+ }
+ freeaddrinfo(res);
+ if(!r)
+ eprint("error: cannot connect to host '%s'\n", host);
+ return srv;
}
#define strlcpy _strlcpy
Received on Wed Sep 23 2009 - 16:52:20 UTC
This archive was generated by hypermail 2.2.0 : Wed Sep 23 2009 - 17:00:11 UTC