/* * misc.c * GloveNet Version 2.0 */ #include #include #include #include #include #include #include #include #include "all-bot.h" int s; /* IRC socket */ char buf[MAXLEN]; /* global text data buffer */ char localhost[64]; /* the local machine's name */ /*===[ call_socket ]========================================================== Connect to port IRCPORT on host 'hostname', returning the socket value. Return -1 on any errors. ============================================================================*/ int call_socket(hostname) char *hostname; { struct sockaddr_in sa; struct hostent *hp; int a, s; #ifdef DBUG printf("Entered call_socket, hostname = %s\n", hostname); #endif if ((hp=gethostbyname(hostname))==NULL) { errno=ECONNREFUSED; return(-1); } bzero(&sa, sizeof(sa)); bcopy(hp->h_addr, (char *)&sa.sin_addr, hp->h_length); sa.sin_family = hp->h_addrtype; sa.sin_port = htons((u_short)IRCPORT); if((s=socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0) return(-1); if(connect(s, &sa, sizeof(sa)) < 0) { close(s); return(-1); } #ifdef DBUG printf("Exiting call_socket correctly, socket = %d\n", s); #endif return(s); } /*===[ readln ]======================================================= Read all characters from socket s until a newline. Put resulting string in buf, ignoring all after the MAXLEN'th character. ====================================================================*/ int readln(buf) char *buf; { int to=0; char c; #ifdef DBUG printf("Entering readln\n"); #endif do { if(read(s, &c, 1)<1) return(0); if((c >= ' ') || (c <= 126)) if(to