summaryrefslogtreecommitdiff
path: root/vchat-protocol.c
diff options
context:
space:
mode:
Diffstat (limited to 'vchat-protocol.c')
-rwxr-xr-xvchat-protocol.c35
1 files changed, 32 insertions, 3 deletions
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;
83 83
84/* connects to server */ 84/* connects to server */
85int 85int
86vcconnect (unsigned char *server, unsigned int port) 86vcconnect (unsigned char *server, unsigned char *port)
87{ 87{
88 /* used for tilde expansion of cert & key filenames */ 88 /* used for tilde expansion of cert & key filenames */
89 unsigned char *tildex = NULL; 89 unsigned char *tildex = NULL;
@@ -98,10 +98,16 @@ vcconnect (unsigned char *server, unsigned int port)
98 EVP_PKEY *certpubkey = NULL; 98 EVP_PKEY *certpubkey = NULL;
99 /* temporary result */ 99 /* temporary result */
100 int result; 100 int result;
101#ifndef EXPERIMENTAL_IPV6
101 /* servers hostentry */ 102 /* servers hostentry */
102 struct hostent *serverhe; 103 struct hostent *serverhe;
103 /* servers sockaddr */ 104 /* servers sockaddr */
104 struct sockaddr_in serversi; 105 struct sockaddr_in serversi;
106 int portnr = strtoul(port,NULL,10);
107#else
108 /* protocol independent server addresses */
109 struct addrinfo hints, *addr, *tmpaddr;
110#endif
105 /* SSL-context */ 111 /* SSL-context */
106 SSL_CTX *sslctx = NULL; 112 SSL_CTX *sslctx = NULL;
107 /* SSL server certificate */ 113 /* SSL server certificate */
@@ -115,6 +121,7 @@ vcconnect (unsigned char *server, unsigned int port)
115 /* variable for verify return */ 121 /* variable for verify return */
116 long verify; 122 long verify;
117 123
124#ifndef EXPERIMENTAL_IPV6
118 /* get host-entry for server */ 125 /* get host-entry for server */
119 if ((serverhe = gethostbyname (server)) == NULL) 126 if ((serverhe = gethostbyname (server)) == NULL)
120 return 0; 127 return 0;
@@ -125,13 +132,35 @@ vcconnect (unsigned char *server, unsigned int port)
125 132
126 /* initialize datastructure for connect */ 133 /* initialize datastructure for connect */
127 serversi.sin_family = AF_INET; 134 serversi.sin_family = AF_INET;
128 serversi.sin_port = htons (port); 135 serversi.sin_port = htons(portnr);
129 serversi.sin_addr = *((struct in_addr *) serverhe->h_addr); 136 serversi.sin_addr = *((struct in_addr *) serverhe->h_addr);
130 memset (&(serversi.sin_zero), 0, 8); 137 memset (&(serversi.sin_zero), 0, 8);
131 138
132 /* attempt connect */ 139 /* attempt connect */
133 if (connect (serverfd, (struct sockaddr *) &serversi, sizeof (struct sockaddr)) == -1) 140 if (connect (serverfd, (struct sockaddr *) &serversi, sizeof (struct sockaddr)) == -1)
134 return 0; 141 return 0;
142#else
143 memset( &hints, 0, sizeof(hints));
144 /* Expect v4 and v6 */
145 hints.ai_family = PF_UNSPEC;
146 hints.ai_socktype = SOCK_STREAM;
147 if( getaddrinfo( server, port, &hints, &addr ))
148 return 0;
149 for( tmpaddr = addr; addr; addr = addr->ai_next )
150 {
151 if( (serverfd = socket( addr->ai_family, addr->ai_socktype, addr->ai_protocol)) < 0)
152 continue;
153 if( connect( serverfd, addr->ai_addr, addr->ai_addrlen ) < 0)
154 {
155 close( serverfd );
156 continue;
157 }
158 break;
159 }
160 if( serverfd < 0 )
161 return 0;
162 freeaddrinfo( tmpaddr );
163#endif
135 164
136 /* inform user */ 165 /* inform user */
137 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_CONNECTED), server, port); 166 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_CONNECTED), server, port);
@@ -537,7 +566,7 @@ justloggedin (unsigned char *message)
537 setstroption(CF_NICK,str1); 566 setstroption(CF_NICK,str1);
538 567
539 /* show change in console window */ 568 /* show change in console window */
540 snprintf (consolestr, CONSOLESTRSIZE, getformatstr(FS_CONSOLE), nick, getstroption (CF_SERVERHOST), getintoption (CF_SERVERPORT)); 569 snprintf (consolestr, CONSOLESTRSIZE, getformatstr(FS_CONSOLE), nick, getstroption (CF_SERVERHOST), getstroption (CF_SERVERPORT));
541 consoleline (NULL); 570 consoleline (NULL);
542 571
543 /* announce login as servermessage */ 572 /* announce login as servermessage */