diff options
author | erdgeist <> | 2003-12-16 14:20:27 +0000 |
---|---|---|
committer | erdgeist <> | 2003-12-16 14:20:27 +0000 |
commit | 125923fecd991e0ca24ac601b5882f3661f711c4 (patch) | |
tree | 21048bfb659ca4a118ce7abad92fe3a2e66e0810 /vchat-protocol.c | |
parent | 05436b145c80a67efa5f79d4bc28f9f2cd2858b2 (diff) |
v6 support default now
Diffstat (limited to 'vchat-protocol.c')
-rwxr-xr-x | vchat-protocol.c | 49 |
1 files changed, 18 insertions, 31 deletions
diff --git a/vchat-protocol.c b/vchat-protocol.c index 0dfcf25..4d1f333 100755 --- a/vchat-protocol.c +++ b/vchat-protocol.c | |||
@@ -70,6 +70,7 @@ static void serverlogin (unsigned char *message); | |||
70 | static void idleprompt (unsigned char *message); | 70 | static void idleprompt (unsigned char *message); |
71 | static void topicchange (unsigned char *message); | 71 | static void topicchange (unsigned char *message); |
72 | static void pmnotsent (unsigned char *message); | 72 | static void pmnotsent (unsigned char *message); |
73 | static int getportnum(unsigned char *port); | ||
73 | 74 | ||
74 | /* declaration of server message array */ | 75 | /* declaration of server message array */ |
75 | #include "vchat-messages.h" | 76 | #include "vchat-messages.h" |
@@ -98,16 +99,8 @@ vcconnect (unsigned char *server, unsigned char *port) | |||
98 | EVP_PKEY *certpubkey = NULL; | 99 | EVP_PKEY *certpubkey = NULL; |
99 | /* temporary result */ | 100 | /* temporary result */ |
100 | int result; | 101 | int result; |
101 | #ifndef EXPERIMENTAL_IPV6 | ||
102 | /* servers hostentry */ | ||
103 | struct hostent *serverhe; | ||
104 | /* servers sockaddr */ | ||
105 | struct sockaddr_in serversi; | ||
106 | int portnr = strtoul(port,NULL,10); | ||
107 | #else | ||
108 | /* protocol independent server addresses */ | 102 | /* protocol independent server addresses */ |
109 | struct addrinfo hints, *addr, *tmpaddr; | 103 | struct addrinfo hints, *addr, *tmpaddr; |
110 | #endif | ||
111 | /* SSL-context */ | 104 | /* SSL-context */ |
112 | SSL_CTX *sslctx = NULL; | 105 | SSL_CTX *sslctx = NULL; |
113 | /* SSL server certificate */ | 106 | /* SSL server certificate */ |
@@ -121,25 +114,6 @@ vcconnect (unsigned char *server, unsigned char *port) | |||
121 | /* variable for verify return */ | 114 | /* variable for verify return */ |
122 | long verify; | 115 | long verify; |
123 | 116 | ||
124 | #ifndef EXPERIMENTAL_IPV6 | ||
125 | /* get host-entry for server */ | ||
126 | if ((serverhe = gethostbyname (server)) == NULL) | ||
127 | return 0; | ||
128 | |||
129 | /* get socket */ | ||
130 | if ((serverfd = socket (AF_INET, SOCK_STREAM, 0)) == -1) | ||
131 | return 0; | ||
132 | |||
133 | /* initialize datastructure for connect */ | ||
134 | serversi.sin_family = AF_INET; | ||
135 | serversi.sin_port = htons(portnr); | ||
136 | serversi.sin_addr = *((struct in_addr *) serverhe->h_addr); | ||
137 | memset (&(serversi.sin_zero), 0, 8); | ||
138 | |||
139 | /* attempt connect */ | ||
140 | if (connect (serverfd, (struct sockaddr *) &serversi, sizeof (struct sockaddr)) == -1) | ||
141 | return 0; | ||
142 | #else | ||
143 | memset( &hints, 0, sizeof(hints)); | 117 | memset( &hints, 0, sizeof(hints)); |
144 | /* Expect v4 and v6 */ | 118 | /* Expect v4 and v6 */ |
145 | hints.ai_family = PF_UNSPEC; | 119 | hints.ai_family = PF_UNSPEC; |
@@ -160,10 +134,9 @@ vcconnect (unsigned char *server, unsigned char *port) | |||
160 | if( serverfd < 0 ) | 134 | if( serverfd < 0 ) |
161 | return 0; | 135 | return 0; |
162 | freeaddrinfo( tmpaddr ); | 136 | freeaddrinfo( tmpaddr ); |
163 | #endif | ||
164 | 137 | ||
165 | /* inform user */ | 138 | /* inform user */ |
166 | snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_CONNECTED), server, strtoul(port,NULL,10)); | 139 | snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_CONNECTED), server, getportnum(port)); |
167 | writechan (tmpstr); | 140 | writechan (tmpstr); |
168 | 141 | ||
169 | usessl = getintoption(CF_USESSL); | 142 | usessl = getintoption(CF_USESSL); |
@@ -391,6 +364,20 @@ vcdisconnect () | |||
391 | serverfd = -1; | 364 | serverfd = -1; |
392 | } | 365 | } |
393 | 366 | ||
367 | /* lookup a port number by service string */ | ||
368 | static int getportnum (unsigned char *port) | ||
369 | { | ||
370 | char *endpt = NULL; | ||
371 | struct servent *service = getservbyname(port, "tcp"); | ||
372 | int dport = strtoul( port, &endpt, 10); | ||
373 | |||
374 | if( service ) | ||
375 | return htons( service->s_port ); | ||
376 | if( (*endpt == 0) && ((char *)port != endpt) ) | ||
377 | return dport; | ||
378 | return -1; | ||
379 | } | ||
380 | |||
394 | /* handle a pm not sent error | 381 | /* handle a pm not sent error |
395 | * format: 412 %s */ | 382 | * format: 412 %s */ |
396 | static void | 383 | static void |
@@ -566,7 +553,7 @@ justloggedin (unsigned char *message) | |||
566 | setstroption(CF_NICK,str1); | 553 | setstroption(CF_NICK,str1); |
567 | 554 | ||
568 | /* show change in console window */ | 555 | /* show change in console window */ |
569 | snprintf (consolestr, CONSOLESTRSIZE, getformatstr(FS_CONSOLE), nick, getstroption (CF_SERVERHOST), strtoul(getstroption (CF_SERVERPORT),NULL,10)); | 556 | snprintf (consolestr, CONSOLESTRSIZE, getformatstr(FS_CONSOLE), nick, getstroption (CF_SERVERHOST), getportnum(getstroption (CF_SERVERPORT))); |
570 | consoleline (NULL); | 557 | consoleline (NULL); |
571 | 558 | ||
572 | /* announce login as servermessage */ | 559 | /* announce login as servermessage */ |
@@ -608,7 +595,7 @@ ownnickchange (unsigned char *newnick) | |||
608 | setstroption(CF_NICK,newnick); | 595 | setstroption(CF_NICK,newnick); |
609 | 596 | ||
610 | /* show change in console window */ | 597 | /* show change in console window */ |
611 | snprintf (consolestr, CONSOLESTRSIZE, getformatstr(FS_CONSOLE), nick, getstroption (CF_SERVERHOST), strtoul(getstroption (CF_SERVERPORT),NULL,10)); | 598 | snprintf (consolestr, CONSOLESTRSIZE, getformatstr(FS_CONSOLE), nick, getstroption (CF_SERVERHOST), getportnum(getstroption (CF_SERVERPORT))); |
612 | consoleline (NULL); | 599 | consoleline (NULL); |
613 | } | 600 | } |
614 | 601 | ||