From: Guus Sliepen Date: Sat, 7 Nov 2009 15:09:56 +0000 (+0100) Subject: Small fixes to get really working control sockets on Windows. X-Git-Tag: release-1.1pre1~102 X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;h=c388527e341658dc915dd67c90bbc9b52b8539c0;p=tinc Small fixes to get really working control sockets on Windows. --- diff --git a/src/control.c b/src/control.c index 8493f254..b62e1439 100644 --- a/src/control.c +++ b/src/control.c @@ -217,8 +217,15 @@ bool init_control() { addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(0x7f000001); addr.sin_port = htons(55555); + int option = 1; control_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if(control_socket < 0) { + logger(LOG_ERR, "Creating control socket failed: %s", sockstrerror(sockerrno)); + goto bail; + } + + setsockopt(control_socket, SOL_SOCKET, SO_REUSEADDR, &option, sizeof option); #else struct sockaddr_un addr; char *lastslash; @@ -275,8 +282,8 @@ bool init_control() { result = bind(control_socket, (struct sockaddr *)&addr, sizeof addr); if(result < 0 && sockinuse(sockerrno)) { - result = connect(control_socket, (struct sockaddr *)&addr, sizeof addr); #ifndef HAVE_MINGW + result = connect(control_socket, (struct sockaddr *)&addr, sizeof addr); if(result < 0) { logger(LOG_WARNING, "Removing old control socket."); unlink(controlsocketname); diff --git a/src/tincctl.c b/src/tincctl.c index 7d82dc44..784c6a94 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -296,7 +296,7 @@ static int fullread(int fd, void *data, size_t datalen) { int rv, len = 0; while(len < datalen) { - rv = read(fd, data + len, datalen - len); + rv = recv(fd, data + len, datalen - len, 0); if(rv == -1 && errno == EINTR) continue; else if(rv == -1) @@ -478,8 +478,6 @@ int main(int argc, char *argv[], char *envp[]) { return 1; } - fprintf(stderr, "Got socket %d\n", fd); - unsigned long arg = 0; if(ioctlsocket(fd, FIONBIO, &arg) != 0) { @@ -529,8 +527,6 @@ int main(int argc, char *argv[], char *envp[]) { return 1; } - fprintf(stderr, "Connected!\n"); - if(fullread(fd, &greeting, sizeof greeting) == -1) { fprintf(stderr, "Cannot read greeting from control socket: %s\n", sockstrerror(sockerrno));