From dc6e7bc1160c777a0464de1985501a4e4a046b1e Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Sat, 13 Dec 2003 11:44:33 +0000 Subject: Experimental V6 support --- Makefile | 16 ++++++++++++++-- sample-count.fmt | 4 ++-- sample-devlog.fmt | 4 ++-- sample-erdgeist.fmt | 4 ++-- sample-mAsq.fmt | 4 ++-- sample-oldstyle.fmt | 2 +- sample-xzivi.fmt | 4 ++-- vchat-client.c | 8 ++++---- vchat-config.h | 6 +++--- vchat-protocol.c | 35 ++++++++++++++++++++++++++++++++--- vchat.h | 2 +- 11 files changed, 65 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 0342b47..5e14ccd 100755 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ CFLAGS = -Wall -Os ## use this line when you've got an readline before 4.(x|2) #CFLAGS += -DOLDREADLINE -CFLAGS += $(OLDREADLINE) +CFLAGS += $(OLDREADLINE) $(EXPERIMENTAL_IPV6) ## you might need one or more of these: #CFLAGS += -I/usr/local/ssl/include -L/usr/local/ssl/lib @@ -39,6 +39,19 @@ OBJS = vchat-client.o vchat-ui.o vchat-protocol.o vchat-user.o vchat-commands. all: vchat-client #vchat-client.1 + @echo " ***************************************" + @echo " ** **" + @echo " ** W A R N I N G **" + @echo " ** **" + @echo " ** Internal representation of server **" + @echo " ** port has changed. If you have got **" + @echo " ** a ~/.vchat/formats laying around, **" + @echo " ** please verify, that FS_CONNECTED **" + @echo " ** and FS_CONSOLE both don't contain **" + @echo " ** '%d' and, if they do, please **" + @echo " ** change those '%d' to '%s'. **" + @echo " ** **" + @echo " ***************************************" install: vchat-client vchat-keygen vchatrc.ex install -d $(DESTDIR)/etc @@ -49,7 +62,6 @@ install: vchat-client vchat-keygen vchatrc.ex # install -m 0644 ./vchat-client.1 $(DESTDIR)$(PREFIX)/share/man/man1 install -m 0644 ./vchatrc.ex $(DESTDIR)/etc/vchatrc - uninstall: rm -f $(DESTDIR)$(PREFIX)/bin/vchat-client rm -f $(DESTDIR)$(PREFIX)/bin/vchat-keygen diff --git a/sample-count.fmt b/sample-count.fmt index d008991..bab9751 100755 --- a/sample-count.fmt +++ b/sample-count.fmt @@ -42,8 +42,8 @@ FS_IDLE = "^8%s" FS_TIME = "^5[%H:%M]-- ^0" FS_TOPICW = "[ Channel %d: %s" FS_NOTOPICW = "[ Channel %d has no topic" -FS_CONSOLE = "%s@%s:%d, use .h to get help" -FS_CONNECTED = "^2# Connected to '^6%s^2', port ^6%d^2 ..." +FS_CONSOLE = "%s@%s:%s, use .h to get help" +FS_CONNECTED = "^2# Connected to '^6%s^2', port ^6%s^2 ..." FS_TOPIC = "^2# Channel ^6%d^2 topic is: '^0%s^2'" FS_NOTOPIC = "^2# Channel ^6%d^2 has no topic" FS_CHGTOPIC = "^2# ^6%s^2 changes topic to: '^0%s^2'" diff --git a/sample-devlog.fmt b/sample-devlog.fmt index e70364d..ac30551 100755 --- a/sample-devlog.fmt +++ b/sample-devlog.fmt @@ -47,8 +47,8 @@ FS_IDLE = "^8%s" FS_TIME = "^2[%H:%M]^0 " FS_TOPICW = "[ Channel %d: %s" FS_NOTOPICW = "[ Channel %d has no topic" -FS_CONSOLE = "%s@%s:%d, use .h to get help" -FS_CONNECTED = "^2# Connected to '^0%s^2', port ^0%d^2 ..." +FS_CONSOLE = "%s@%s:%s, use .h to get help" +FS_CONNECTED = "^2# Connected to '^0%s^2', port ^0%s^2 ..." FS_TOPIC = "^1# Channel ^6%d^2 topic is: '^0%s^2'" FS_NOTOPIC = "^1# Channel ^6%d^2 has no topic" FS_CHGTOPIC = "^1# ^4%s^1 changes topic to: '^0%s^1'" diff --git a/sample-erdgeist.fmt b/sample-erdgeist.fmt index 5fc87e1..7545d3d 100755 --- a/sample-erdgeist.fmt +++ b/sample-erdgeist.fmt @@ -42,8 +42,8 @@ FS_TIME = "^9[%H:%M]^0 " FS_CONSOLETIME = "[%H:%M] " FS_TOPICW = "[ Channel %d: %s" FS_NOTOPICW = "[ Channel %d has no topic" -FS_CONSOLE = "%s@%s:%d, use .h to get help" -FS_CONNECTED = "^2# Connected to '^0%s^2', port ^0%d^2 ..." +FS_CONSOLE = "%s@%s:%s, use .h to get help" +FS_CONNECTED = "^2# Connected to '^0%s^2', port ^0%s^2 ..." FS_TOPIC = "^1# Channel ^6%d^2 topic is: '^0%s^2'" FS_NOTOPIC = "^1# Channel ^6%d^2 has no topic" FS_CHGTOPIC = "^1# ^4%s^1 changes topic to: '^0%s^1'" diff --git a/sample-mAsq.fmt b/sample-mAsq.fmt index 9bed139..af001d7 100755 --- a/sample-mAsq.fmt +++ b/sample-mAsq.fmt @@ -42,8 +42,8 @@ FS_IDLE = "^8%s" FS_TIME = "^5%H:%M^0 " FS_TOPICW = "[ Channel %d: %s" FS_NOTOPICW = "[ Channel %d has no topic" -FS_CONSOLE = "%s@%s:%d, use .h to get help" -FS_CONNECTED = "^2*^0C^2* Connected to '^6%s^2', port ^6%d^2 ..." +FS_CONSOLE = "%s@%s:%s, use .h to get help" +FS_CONNECTED = "^2*^0C^2* Connected to '^6%s^2', port ^6%s^2 ..." FS_TOPIC = "^2*^0T^2* Channel ^6%d^2 topic is: '^0%s^2'" FS_NOTOPIC = "^2*^0T^2* Channel ^6%d^2 has no topic" FS_CHGTOPIC = "^5*^0T^2* ^6%s^2 changes topic to: '^0%s^2'" diff --git a/sample-oldstyle.fmt b/sample-oldstyle.fmt index a1b0eb5..d0d8f17 100755 --- a/sample-oldstyle.fmt +++ b/sample-oldstyle.fmt @@ -43,7 +43,7 @@ FS_TIME = "^0%H:%M " FS_TOPICW = "Channel %d: %s" FS_NOTOPICW = "Channel %d has no topic" FS_CONSOLE = "-=- VChat V0.1 -=- type .h for help -=-" -FS_CONNECTED = "^0* Connected to '%s', port %d ..." +FS_CONNECTED = "^0* Connected to '%s', port %s ..." FS_TOPIC = "^0* Channel %d topic is: '%s'" FS_NOTOPIC = "^0* Channel %d has no topic" FS_CHGTOPIC = "^0* %s changed the channel topic to '%s'" diff --git a/sample-xzivi.fmt b/sample-xzivi.fmt index f839366..dbbf2b4 100755 --- a/sample-xzivi.fmt +++ b/sample-xzivi.fmt @@ -41,8 +41,8 @@ FS_IDLE = "^1^b%s^B" FS_TIME = "^4[%H:%M]^0 " FS_TOPICW = "Channel %d: %s" FS_NOTOPICW = "Channel %d has no topic" -FS_CONSOLE = "%s@%s:%d" -FS_CONNECTED = "# Connected to %s:%d ..." +FS_CONSOLE = "%s@%s:%s" +FS_CONNECTED = "# Connected to %s:%s ..." FS_TOPIC = "# Channel %d topic is: ^6%s" FS_NOTOPIC = "# Channel %d has no topic" FS_CHGTOPIC = "# ^b%s^B changes topic to: ^6%s" diff --git a/vchat-client.c b/vchat-client.c index a3e7fd2..f30e1c0 100755 --- a/vchat-client.c +++ b/vchat-client.c @@ -458,7 +458,7 @@ void usage(unsigned char *name) { puts (" -l local connect (no SSL + connects localhost:2323)"); puts (" -z don't use certificate files"); printf (" -s set server (default \"%s\")\n",getstroption(CF_SERVERHOST)); - printf (" -p set port (default %d)\n",getintoption(CF_SERVERPORT)); + printf (" -p set port (default %s)\n",getstroption(CF_SERVERPORT)); printf (" -c set channel (default %d)\n",getintoption(CF_CHANNEL)); if (nick) printf(" -n set nickname (default \"%s\")\n",nick); @@ -499,7 +499,7 @@ main (int argc, char **argv) case 'l': setintoption(CF_USESSL,0); break; case 'z': setintoption(CF_USECERT,0); break; case 's': setstroption(CF_SERVERHOST,optarg); break; - case 'p': setintoption(CF_SERVERPORT,strtol(optarg,NULL,10)); break; + case 'p': setstroption(CF_SERVERPORT,optarg); break; case 'c': setintoption(CF_CHANNEL,strtol(optarg,NULL,10)); break; case 'n': setstroption(CF_NICK,optarg); break; case 'f': setstroption(CF_FROM,optarg); break; @@ -518,7 +518,7 @@ main (int argc, char **argv) if (!getintoption(CF_USESSL)) { setstroption(CF_SERVERHOST,"localhost"); - setintoption(CF_SERVERPORT,2323); + setstroption(CF_SERVERPORT,"2323"); } else { SSL_library_init (); SSL_load_error_strings (); @@ -535,7 +535,7 @@ main (int argc, char **argv) initui (); /* attempt connection */ - if (!vcconnect (getstroption(CF_SERVERHOST), getintoption(CF_SERVERPORT))) + if (!vcconnect (getstroption(CF_SERVERHOST), getstroption(CF_SERVERPORT))) { snprintf (tmpstr, TMPSTRSIZE, "Could not connect to server, %s.", sys_errlist[errno]); diff --git a/vchat-config.h b/vchat-config.h index 856b00c..f011a4c 100755 --- a/vchat-config.h +++ b/vchat-config.h @@ -32,7 +32,7 @@ static volatile configoption configoptions[] = { {CF_NICK, CO_STR, "nick", NULL, NULL, { .pstr = &nick } }, {CF_FROM, CO_STR, "from", "vc-alpha-0.16", NULL, { NULL } }, {CF_SERVERHOST, CO_STR, "host", "pulse.flatline.de",NULL, { NULL } }, - {CF_SERVERPORT, CO_INT, "port", (char *) 2325, (char *)-1, { NULL } }, + {CF_SERVERPORT, CO_STR, "port", "2325", NULL, { NULL } }, {CF_CIPHERSUITE, CO_STR, "ciphers", "HIGH:MEDIUM", NULL, { NULL } }, {CF_CONFIGFILE, CO_STR, "conffile", "~/.vchat/config", NULL, { NULL } }, {CF_CERTFILE, CO_STR, "certfile", "~/.vchat/cert", NULL, { NULL } }, @@ -96,8 +96,8 @@ static formatstring formatstrings[] = { FE( FS_CONSOLETIME, "[%H:%M] "), FE( FS_TOPICW, "[ Channel %d: %s"), FE( FS_NOTOPICW, "[ Channel %d has no topic"), - FE( FS_CONSOLE, "%s@%s:%d, use .h to get help "), - FE( FS_CONNECTED, "\0012# Connected to '\0016%s\0012', port \0016%d\0012 ..."), + FE( FS_CONSOLE, "%s@%s:%s, use .h to get help "), + FE( FS_CONNECTED, "\0012# Connected to '\0016%s\0012', port \0016%s\0012 ..."), FE( FS_TOPIC, "\0012# Channel \0016%d\0012 topic is: '\0010%s\0012'"), FE( FS_NOTOPIC, "\0012# Channel \0016%d\0012 has no topic"), FE( FS_CHGTOPIC, "\0012# \0016%s\0012 changes topic to: '\0010%s\0012'"), diff --git a/vchat-protocol.c b/vchat-protocol.c index f1e8b5c..03161e0 100755 --- a/vchat-protocol.c +++ b/vchat-protocol.c @@ -83,7 +83,7 @@ unsigned char *encoding; /* connects to server */ int -vcconnect (unsigned char *server, unsigned int port) +vcconnect (unsigned char *server, unsigned char *port) { /* used for tilde expansion of cert & key filenames */ unsigned char *tildex = NULL; @@ -98,10 +98,16 @@ vcconnect (unsigned char *server, unsigned int port) EVP_PKEY *certpubkey = NULL; /* temporary result */ int result; +#ifndef EXPERIMENTAL_IPV6 /* servers hostentry */ struct hostent *serverhe; /* servers sockaddr */ struct sockaddr_in serversi; + int portnr = strtoul(port,NULL,10); +#else + /* protocol independent server addresses */ + struct addrinfo hints, *addr, *tmpaddr; +#endif /* SSL-context */ SSL_CTX *sslctx = NULL; /* SSL server certificate */ @@ -115,6 +121,7 @@ vcconnect (unsigned char *server, unsigned int port) /* variable for verify return */ long verify; +#ifndef EXPERIMENTAL_IPV6 /* get host-entry for server */ if ((serverhe = gethostbyname (server)) == NULL) return 0; @@ -125,13 +132,35 @@ vcconnect (unsigned char *server, unsigned int port) /* initialize datastructure for connect */ serversi.sin_family = AF_INET; - serversi.sin_port = htons (port); + serversi.sin_port = htons(portnr); serversi.sin_addr = *((struct in_addr *) serverhe->h_addr); memset (&(serversi.sin_zero), 0, 8); /* attempt connect */ if (connect (serverfd, (struct sockaddr *) &serversi, sizeof (struct sockaddr)) == -1) return 0; +#else + memset( &hints, 0, sizeof(hints)); + /* Expect v4 and v6 */ + hints.ai_family = PF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + if( getaddrinfo( server, port, &hints, &addr )) + return 0; + for( tmpaddr = addr; addr; addr = addr->ai_next ) + { + if( (serverfd = socket( addr->ai_family, addr->ai_socktype, addr->ai_protocol)) < 0) + continue; + if( connect( serverfd, addr->ai_addr, addr->ai_addrlen ) < 0) + { + close( serverfd ); + continue; + } + break; + } + if( serverfd < 0 ) + return 0; + freeaddrinfo( tmpaddr ); +#endif /* inform user */ snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_CONNECTED), server, port); @@ -537,7 +566,7 @@ justloggedin (unsigned char *message) setstroption(CF_NICK,str1); /* show change in console window */ - snprintf (consolestr, CONSOLESTRSIZE, getformatstr(FS_CONSOLE), nick, getstroption (CF_SERVERHOST), getintoption (CF_SERVERPORT)); + snprintf (consolestr, CONSOLESTRSIZE, getformatstr(FS_CONSOLE), nick, getstroption (CF_SERVERHOST), getstroption (CF_SERVERPORT)); consoleline (NULL); /* announce login as servermessage */ diff --git a/vchat.h b/vchat.h index ec5da02..fcae04f 100755 --- a/vchat.h +++ b/vchat.h @@ -181,7 +181,7 @@ void clearfilters ( char colour ); extern unsigned char *vchat_io_version; /* connect/disconnect */ -int vcconnect (unsigned char *server, unsigned int port); +int vcconnect (unsigned char *server, unsigned char *port); void vcdisconnect (); /* network I/O */ -- cgit v1.2.3