X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fcontrol.c;h=b62e1439744d3a651dbad6310434c1fbda1f008d;hb=c388527e341658dc915dd67c90bbc9b52b8539c0;hp=738521425e4d3ea01b14042c73de9ba319d01110;hpb=07a560eab66b575f382428a956550817697e25e2;p=tinc diff --git a/src/control.c b/src/control.c index 73852142..b62e1439 100644 --- a/src/control.c +++ b/src/control.c @@ -12,21 +12,18 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - $Id$ + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include - #include "system.h" #include "conf.h" #include "control.h" #include "control_common.h" #include "graph.h" #include "logger.h" +#include "utils.h" #include "xalloc.h" static int control_socket = -1; @@ -213,6 +210,23 @@ static int control_compare(const struct event *a, const struct event *b) { bool init_control() { int result; + +#ifdef HAVE_MINGW + struct sockaddr_in addr; + memset(&addr, 0, sizeof addr); + 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; @@ -263,16 +277,20 @@ bool init_control() { logger(LOG_ERR, "Control socket directory ownership/permissions insecure."); goto bail; } +#endif result = bind(control_socket, (struct sockaddr *)&addr, sizeof addr); - if(result < 0 && errno == EADDRINUSE) { + if(result < 0 && sockinuse(sockerrno)) { +#ifndef HAVE_MINGW result = connect(control_socket, (struct sockaddr *)&addr, sizeof addr); if(result < 0) { logger(LOG_WARNING, "Removing old control socket."); unlink(controlsocketname); result = bind(control_socket, (struct sockaddr *)&addr, sizeof addr); - } else { + } else +#endif + { if(netname) logger(LOG_ERR, "Another tincd is already running for net `%s'.", netname); else @@ -299,7 +317,7 @@ bool init_control() { bail: if(control_socket != -1) { - close(control_socket); + closesocket(control_socket); control_socket = -1; } return false; @@ -307,6 +325,6 @@ bail: void exit_control() { event_del(&control_event); - close(control_socket); + closesocket(control_socket); unlink(controlsocketname); }