- int result;
- struct sockaddr_un addr;
-
- if(strlen(controlsocketname) >= sizeof addr.sun_path) {
- logger(LOG_ERR, _("Control socket filename too long!"));
- return false;
- }
-
- memset(&addr, 0, sizeof addr);
- addr.sun_family = AF_UNIX;
- strncpy(addr.sun_path, controlsocketname, sizeof addr.sun_path - 1);
-
- control_socket = socket(PF_UNIX, SOCK_STREAM, 0);
-
- if(control_socket < 0) {
- logger(LOG_ERR, _("Creating UNIX socket failed: %s"), strerror(errno));
- return false;
- }
-
- //unlink(controlsocketname);
- result = bind(control_socket, (struct sockaddr *)&addr, sizeof addr);
-
- if(result < 0 && errno == EADDRINUSE) {
- 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 {
- close(control_socket);
- if(netname)
- logger(LOG_ERR, _("Another tincd is already running for net `%s'."), netname);
- else
- logger(LOG_ERR, _("Another tincd is already running."));
- return false;
- }
- }
-
- if(result < 0) {
- logger(LOG_ERR, _("Can't bind to %s: %s\n"), controlsocketname, strerror(errno));
- close(control_socket);
- return false;
- }
+ randomize(controlcookie, sizeof controlcookie / 2);
+ bin2hex(controlcookie, controlcookie, sizeof controlcookie / 2);
+ controlcookie[sizeof controlcookie - 1] = 0;