Bugfixes of ASTERIX I034
[metze/wireshark/wip.git] / sharkd_daemon.c
index d97e347f493e924c0b58726cb18e6c9c3254da66..89af1ebcb5c1e53f7345e142b99f4c2951c1a5c1 100644 (file)
@@ -6,19 +6,7 @@
  * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
 #include <config.h>
 #endif
 
 #include <wsutil/socket.h>
-
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
+#include <wsutil/inet_addr.h>
 
 #ifndef _WIN32
 #include <sys/un.h>
@@ -52,6 +37,7 @@
 #endif
 
 #include <wsutil/strtoi.h>
+#include <wsutil/win32-utils.h>
 
 #include "sharkd.h"
 
@@ -145,7 +131,7 @@ socket_init(char *path)
                        return INVALID_SOCKET;
 
                s_in.sin_family = AF_INET;
-               s_in.sin_addr.s_addr = inet_addr(path);
+               ws_inet_pton4(path, &(s_in.sin_addr.s_addr));
                s_in.sin_port = g_htons(port);
                *port_sep = ':';
 
@@ -247,7 +233,6 @@ sharkd_loop(void)
                PROCESS_INFORMATION pi;
                STARTUPINFO si;
                char *exename;
-               gunichar2 *commandline;
 #endif
                socket_handle_t fd;
 
@@ -263,6 +248,7 @@ sharkd_loop(void)
                pid = fork();
                if (pid == 0)
                {
+                       closesocket(_server_fd);
                        /* redirect stdin, stdout to socket */
                        dup2(fd, 0);
                        dup2(fd, 1);
@@ -287,11 +273,10 @@ sharkd_loop(void)
                si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
 
                exename = g_strdup_printf("%s\\%s", get_progfile_dir(), "sharkd.exe");
-               commandline = g_utf8_to_utf16("sharkd.exe -", -1, NULL, NULL, NULL);
 
-               if (!CreateProcess(utf_8to16(exename), commandline, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi))
+               if (!win32_create_process(exename, "sharkd.exe -", NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi))
                {
-                       fprintf(stderr, "CreateProcess(%s) failed\n", exename);
+                       fprintf(stderr, "win32_create_process(%s) failed\n", exename);
                }
                else
                {
@@ -299,7 +284,6 @@ sharkd_loop(void)
                }
 
                g_free(exename);
-               g_free(commandline);
 #endif
 
                closesocket(fd);