summaryrefslogtreecommitdiff
path: root/sic.c
diff options
context:
space:
mode:
authorAnselm R. Garbe <arg@10kloc.org>2006-09-04 08:54:14 +0200
committerAnselm R. Garbe <arg@10kloc.org>2006-09-04 08:54:14 +0200
commitc2fcf48e6d334234859c5e015ec6cc816bca451b (patch)
tree80901316cf45f1836b0cb03a6c0bf013e6d41bc1 /sic.c
parentee77b8efaef863413e87c2484021b0b1199b1eff (diff)
downloadcic-c2fcf48e6d334234859c5e015ec6cc816bca451b.tar.gz
applied Adriens patch
Diffstat (limited to 'sic.c')
-rw-r--r--sic.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/sic.c b/sic.c
index 99007d1..8d65809 100644
--- a/sic.c
+++ b/sic.c
@@ -11,6 +11,7 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
+#include <unistd.h>
#include <sys/socket.h>
#include <sys/time.h>
@@ -20,7 +21,7 @@
enum { Tnick, Tuser, Tcmd, Tchan, Targ, Ttext, Tlast };
static char *server = "irc.oftc.net";
-static int port = 6667;
+static unsigned short port = 6667;
static char *nick = NULL;
static char *fullname = NULL;
static char *password = NULL;
@@ -241,7 +242,7 @@ main(int argc, char *argv[])
int i;
struct timeval tv;
struct hostent *hp;
- struct sockaddr_in addr = { 0 };
+ static struct sockaddr_in addr; /* initially filled with 0's */
char ping[256];
fd_set rd;
@@ -257,7 +258,7 @@ main(int argc, char *argv[])
server = argv[++i];
break;
case 'p':
- port = atoi(argv[++i]);
+ port = (unsigned short)atoi(argv[++i]);
break;
case 'n':
nick = argv[++i];
@@ -280,10 +281,13 @@ main(int argc, char *argv[])
fprintf(stderr, "sic: cannot connect server '%s'\n", server);
exit(EXIT_FAILURE);
}
- hp = gethostbyname(server);
+ if (NULL == (hp = gethostbyname(server))) {
+ fprintf(stderr, "sic: cannot resolve hostname '%s'\n", server);
+ exit(EXIT_FAILURE);
+ }
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
- bcopy(hp->h_addr, &addr.sin_addr, hp->h_length);
+ memcpy(&addr.sin_addr, hp->h_addr, hp->h_length);
if(connect(srv, (struct sockaddr *) &addr, sizeof(struct sockaddr_in))) {
close(srv);
fprintf(stderr, "sic: cannot connect server '%s'\n", server);