+static int dc_connect2(char *host, struct qcmd **cnctcmd)
+{
+ struct addrinfo *ai;
+ struct qcmd *qcmd;
+ int ret;
+
+ if(host == dc_srv_local)
+ ai = getlocalai();
+ else if(!host || !*host)
+ ai = defaulthost();
+ else
+ ai = resolvhost(host);
+ if(ai == NULL)
+ return(-1);
+ ret = dc_connectai(ai, &qcmd);
+ if((ret >= 0) && (cnctcmd != NULL))
+ *cnctcmd = qcmd;
+ return(ret);
+}
+
+int dc_connect(char *host)
+{
+ return(dc_connect2(host, NULL));
+}
+
+int dc_connectsync(char *host, struct dc_response **respbuf)
+{
+ int ret;
+ struct qcmd *cc;
+ struct dc_response *resp;
+
+ if((ret = dc_connect2(host, &cc)) < 0)
+ return(-1);
+ resp = dc_gettaggedrespsync(cc->tag);
+ if(resp == NULL) {
+ dc_disconnect();
+ return(-1);
+ }
+ if(respbuf == NULL)
+ dc_freeresp(resp);
+ else
+ *respbuf = resp;
+ return(ret);
+}
+
+int dc_connectsync2(char *host, int rev)
+{
+ int ret;
+ struct dc_response *resp;
+
+ if((ret = dc_connectsync(host, &resp)) < 0)
+ return(-1);
+ if(dc_checkprotocol(resp, rev))
+ {
+ dc_freeresp(resp);
+ dc_disconnect();
+ errno = EPROTONOSUPPORT;
+ return(-1);
+ }
+ dc_freeresp(resp);
+ return(ret);
+}
+