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 <sys/un.h>
-
#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;
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;
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
bail:
if(control_socket != -1) {
- close(control_socket);
+ closesocket(control_socket);
control_socket = -1;
}
return false;
void exit_control() {
event_del(&control_event);
- close(control_socket);
+ closesocket(control_socket);
unlink(controlsocketname);
}