Update sic/util.c to match sic.c tip.
This commit is contained in:
parent
2b85380411
commit
7f1961d4c6
@ -18,7 +18,7 @@ typedef unsigned short ushort;
|
|||||||
#define PINGTIMEOUT 300
|
#define PINGTIMEOUT 300
|
||||||
|
|
||||||
static char* host = "irc.oftc.net";
|
static char* host = "irc.oftc.net";
|
||||||
static ushort port = 6667;
|
static char* port = "ircd";
|
||||||
static char* password;
|
static char* password;
|
||||||
static char nick[32];
|
static char nick[32];
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ main(int argc, char *argv[]) {
|
|||||||
if(++i < argc) host = argv[i];
|
if(++i < argc) host = argv[i];
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
if(++i < argc) port = atoi(argv[i]);
|
if(++i < argc) port = argv[i];
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
if(++i < argc) strlcpy(nick, argv[i], sizeof nick);
|
if(++i < argc) strlcpy(nick, argv[i], sizeof nick);
|
||||||
|
34
kris/util.c
34
kris/util.c
@ -21,21 +21,27 @@ eprint(const char *fmt, ...) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
dial(char *host, int port) {
|
dial(char *host, char *port) {
|
||||||
struct hostent *hp;
|
static struct addrinfo hints;
|
||||||
static struct sockaddr_in addr;
|
struct addrinfo *res, *r;
|
||||||
int i;
|
int srv;
|
||||||
|
|
||||||
if((i = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
memset(&hints, 0, sizeof hints);
|
||||||
eprint("sic: cannot connect host '%s':", host);
|
hints.ai_family = AF_UNSPEC;
|
||||||
if(nil == (hp = gethostbyname(host)))
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
eprint("sic: cannot resolve hostname '%s': %s\n", host, hstrerror(h_errno));
|
if(getaddrinfo(host, port, &hints, &res) != 0)
|
||||||
addr.sin_family = AF_INET;
|
eprint("error: cannot resolve hostname '%s':", host);
|
||||||
addr.sin_port = htons(port);
|
for(r = res; r; r = r->ai_next) {
|
||||||
memcpy(&addr.sin_addr, hp->h_addr, hp->h_length);
|
if((srv = socket(r->ai_family, r->ai_socktype, r->ai_protocol)) == -1)
|
||||||
if(connect(i, (struct sockaddr*)&addr, sizeof(struct sockaddr_in)))
|
continue;
|
||||||
eprint("sic: cannot connect host '%s':", host);
|
if(connect(srv, r->ai_addr, r->ai_addrlen) == 0)
|
||||||
return i;
|
break;
|
||||||
|
close(srv);
|
||||||
|
}
|
||||||
|
freeaddrinfo(res);
|
||||||
|
if(!r)
|
||||||
|
eprint("error: cannot connect to host '%s'\n", host);
|
||||||
|
return srv;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define strlcpy _strlcpy
|
#define strlcpy _strlcpy
|
||||||
|
Loading…
Reference in New Issue
Block a user