Fix sharkd compiling on Windows

Change-Id: I8c614189159f1263d9452d495cee34d1a2c1bfcb
Reviewed-on: https://code.wireshark.org/review/19790
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Michael Mann 2017-01-25 20:27:13 -05:00
parent eeab554cf2
commit 19028ebab4
2 changed files with 50 additions and 12 deletions

View File

@ -30,13 +30,40 @@
#include <stddef.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#include <sys/un.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifndef _WIN32
#include <sys/un.h>
#include <netinet/tcp.h>
#endif
/*
#if defined(_WIN32)
#ifdef HAVE_WINDOWS_H
#include <windows.h>
#endif
#include <ws2tcpip.h>
#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
#endif
#endif
*/
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#include <wsutil/strtoi.h>
@ -49,6 +76,7 @@ socket_init(char *path)
{
int fd = -1;
#ifndef _WIN32
if (!strncmp(path, "unix:", 5))
{
struct sockaddr_un s_un;
@ -79,8 +107,9 @@ socket_init(char *path)
}
}
#endif
#ifdef SHARKD_TCP_SUPPORT
else if (!strncmp(path, "tcp:", 4))
if (!strncmp(path, "tcp:", 4))
{
struct sockaddr_in s_in;
int one = 1;
@ -115,24 +144,28 @@ socket_init(char *path)
return -1;
}
}
#endif
else
{
#endif
return -1;
#ifdef SHARKD_TCP_SUPPORT
}
#endif
#ifndef _WIN32
if (listen(fd, SOMAXCONN))
{
close(fd);
return -1;
}
#endif
return fd;
}
int
sharkd_init(int argc, char **argv)
{
#ifndef _WIN32
int fd;
pid_t pid;
@ -168,12 +201,14 @@ sharkd_init(int argc, char **argv)
}
_server_fd = fd;
#endif
return 0;
}
int
sharkd_loop(void)
{
#ifndef _WIN32
while (1)
{
int fd;
@ -205,7 +240,7 @@ sharkd_loop(void)
close(fd);
}
#endif
return 0;
}

View File

@ -31,6 +31,7 @@
#include <glib.h>
#include <wsutil/wsjsmn.h>
#include <wsutil/ws_printf.h>
#include <file.h>
#include <epan/exceptions.h>
@ -655,7 +656,7 @@ sharkd_session_geoip_addr(address *addr, const char *suffix)
#ifdef HAVE_GEOIP
if (addr->type == AT_IPv4)
{
uint32_t ip = pntoh32(addr->data);
guint32 ip = pntoh32(addr->data);
guint num_dbs = geoip_db_num_dbs();
guint dbnum;
@ -960,7 +961,7 @@ sharkd_session_process_tap(char *buf, const jsmntok_t *tokens, int count)
taps_data[i] = NULL;
snprintf(tapbuf, sizeof(tapbuf), "tap%d", i);
ws_snprintf(tapbuf, sizeof(tapbuf), "tap%d", i);
tok_tap = json_find_attr(buf, tokens, count, tapbuf);
if (!tok_tap)
break;
@ -1360,7 +1361,7 @@ sharkd_session_process_intervals(char *buf, const jsmntok_t *tokens, int count)
for (framenum = 1; framenum <= cfile.count; framenum++)
{
frame_data *fdata = frame_data_sequence_find(cfile.frames, framenum);
int msec_rel;
time_t msec_rel;
int new_idx;
if (start_ts == NULL)
@ -1370,7 +1371,7 @@ sharkd_session_process_intervals(char *buf, const jsmntok_t *tokens, int count)
continue;
/* TODO, make it 64-bit, to avoid msec overflow after 24days */
msec_rel = ((fdata->abs_ts.secs - start_ts->secs) * 1000 + (fdata->abs_ts.nsecs - start_ts->nsecs) / 1000000);
msec_rel = (time_t)((fdata->abs_ts.secs - start_ts->secs) * 1000 + (fdata->abs_ts.nsecs - start_ts->nsecs) / 1000000);
new_idx = msec_rel / interval_ms;
if (idx != new_idx)
@ -1689,7 +1690,7 @@ sharkd_session_process_setconf(char *buf, const jsmntok_t *tokens, int count)
if (!tok_name || tok_name[0] == '\0' || !tok_value)
return;
snprintf(pref, sizeof(pref), "%s:%s", tok_name, tok_value);
ws_snprintf(pref, sizeof(pref), "%s:%s", tok_name, tok_value);
ret = prefs_set_pref(pref);
printf("{\"err\":%d}\n", ret);
@ -1874,7 +1875,7 @@ sharkd_session_process(char *buf, const jsmntok_t *tokens, int count)
else if (!strcmp(tok_req, "dumpconf"))
sharkd_session_process_dumpconf(buf, tokens, count);
else if (!strcmp(tok_req, "bye"))
_Exit(0);
exit(0);
else
fprintf(stderr, "::: req = %s\n", tok_req);
@ -1890,7 +1891,9 @@ sharkd_session_main(void)
int tokens_max = -1;
fprintf(stderr, "Hello in child!\n");
#ifndef _WIN32
setlinebuf(stdout);
#endif
while (fgets(buf, sizeof(buf), stdin))
{