forked from osmocom/wireshark
Add a ws_posix_compat.h header
Currently used to define ssize_t on platforms that lack it. Fix some Windows build errors caused by moving the definition into a separate header. Fix some narrowing warnings on Windows x64 from changing the definition of ssize_t from long int to int64_t. The casts in dumpcap are ugly but necessary. The whole code needs to be rewritten for portability, or the warnings disabled.
This commit is contained in:
parent
36d5aad962
commit
4448b6494e
|
@ -3432,6 +3432,7 @@ set(SHARK_PUBLIC_HEADERS
|
||||||
include/ws_compiler_tests.h
|
include/ws_compiler_tests.h
|
||||||
include/ws_diag_control.h
|
include/ws_diag_control.h
|
||||||
include/ws_log_defs.h
|
include/ws_log_defs.h
|
||||||
|
include/ws_posix_compat.h
|
||||||
include/ws_symbol_export.h
|
include/ws_symbol_export.h
|
||||||
include/wireshark.h
|
include/wireshark.h
|
||||||
${CMAKE_BINARY_DIR}/ws_version.h
|
${CMAKE_BINARY_DIR}/ws_version.h
|
||||||
|
|
|
@ -306,10 +306,6 @@
|
||||||
/* Define to 1 if the 'ssize_t' type exists. */
|
/* Define to 1 if the 'ssize_t' type exists. */
|
||||||
#cmakedefine HAVE_SSIZE_T 1
|
#cmakedefine HAVE_SSIZE_T 1
|
||||||
|
|
||||||
#ifndef HAVE_SSIZE_T
|
|
||||||
# define ssize_t long int
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
# define strncasecmp strnicmp
|
# define strncasecmp strnicmp
|
||||||
# define popen _popen
|
# define popen _popen
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
#
|
#
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.1)
|
cmake_minimum_required(VERSION 3.12)
|
||||||
cmake_policy(SET CMP0048 NEW)
|
cmake_policy(SET CMP0048 NEW)
|
||||||
|
|
||||||
project(Hello VERSION 0.0.1 DESCRIPTION "Wireshark Hello Plugin" LANGUAGES C)
|
project(Hello VERSION 0.0.1 DESCRIPTION "Wireshark Hello Plugin" LANGUAGES C)
|
||||||
|
@ -18,12 +18,18 @@ if(NOT Wireshark_PLUGINS_ENABLED)
|
||||||
message(WARNING "Wireshark was compiled without support for plugins")
|
message(WARNING "Wireshark was compiled without support for plugins")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
include(CheckTypeSize)
|
||||||
|
check_type_size("ssize_t" SSIZE_T)
|
||||||
|
|
||||||
set(CMAKE_C_VISIBILITY_PRESET hidden)
|
set(CMAKE_C_VISIBILITY_PRESET hidden)
|
||||||
if (CMAKE_COMPILER_IS_GNUCC)
|
if (CMAKE_COMPILER_IS_GNUCC)
|
||||||
set(CMAKE_C_FLAGS "-Wall -Wextra ${CMAKE_C_FLAGS}")
|
set(CMAKE_C_FLAGS "-Wall -Wextra ${CMAKE_C_FLAGS}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_definitions(-DVERSION=\"${PROJECT_VERSION}\")
|
add_compile_definitions(
|
||||||
|
VERSION=\"${PROJECT_VERSION}\"
|
||||||
|
$<$<BOOL:${HAVE_SSIZE_T}>:HAVE_SSIZE_T>
|
||||||
|
)
|
||||||
|
|
||||||
add_library(hello MODULE hello.c)
|
add_library(hello MODULE hello.c)
|
||||||
set_target_properties(hello PROPERTIES PREFIX "" DEFINE_SYMBOL "")
|
set_target_properties(hello PROPERTIES PREFIX "" DEFINE_SYMBOL "")
|
||||||
|
|
14
dumpcap.c
14
dumpcap.c
|
@ -1260,7 +1260,7 @@ static void *cap_thread_read(void *arg)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bytes_read += b;
|
bytes_read += (DWORD)b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -1485,7 +1485,11 @@ cap_pipe_read_data_bytes(capture_src *pcap_src, char *errmsg, size_t errmsgl)
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#ifdef _WIN32
|
||||||
|
bytes_read += (DWORD)b;
|
||||||
|
#else
|
||||||
bytes_read += b;
|
bytes_read += b;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pcap_src->cap_pipe_bytes_read += bytes_read;
|
pcap_src->cap_pipe_bytes_read += bytes_read;
|
||||||
|
@ -2317,7 +2321,11 @@ pcap_pipe_dispatch(loop_data *ld, capture_src *pcap_src, char *errmsg, size_t er
|
||||||
result = PD_PIPE_ERR;
|
result = PD_PIPE_ERR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#ifdef _WIN32
|
||||||
|
pcap_src->cap_pipe_bytes_read += (DWORD)b;
|
||||||
|
#else
|
||||||
pcap_src->cap_pipe_bytes_read += b;
|
pcap_src->cap_pipe_bytes_read += b;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
else {
|
else {
|
||||||
|
@ -2374,7 +2382,11 @@ pcap_pipe_dispatch(loop_data *ld, capture_src *pcap_src, char *errmsg, size_t er
|
||||||
result = PD_PIPE_ERR;
|
result = PD_PIPE_ERR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#ifdef _WIN32
|
||||||
|
pcap_src->cap_pipe_bytes_read += (DWORD)b;
|
||||||
|
#else
|
||||||
pcap_src->cap_pipe_bytes_read += b;
|
pcap_src->cap_pipe_bytes_read += b;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include <ws_attributes.h>
|
#include <ws_attributes.h>
|
||||||
#include <ws_compiler_tests.h>
|
#include <ws_compiler_tests.h>
|
||||||
#include <ws_diag_control.h>
|
#include <ws_diag_control.h>
|
||||||
|
#include <ws_posix_compat.h>
|
||||||
#include <ws_symbol_export.h>
|
#include <ws_symbol_export.h>
|
||||||
|
|
||||||
#include <wsutil/ws_assert.h>
|
#include <wsutil/ws_assert.h>
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
/* ws_posix_compat.h
|
||||||
|
* Definitions for POSIX compatibility.
|
||||||
|
*
|
||||||
|
* Wireshark - Network traffic analyzer
|
||||||
|
* By Gerald Combs <gerald@wireshark.org>
|
||||||
|
* Copyright 1998 Gerald Combs
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __POSIX_COMPAT_H__
|
||||||
|
#define __POSIX_COMPAT_H__
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
#if !defined(SSIZE_MAX) && !defined(HAVE_SSIZE_T)
|
||||||
|
#if defined(_WIN64)
|
||||||
|
|
||||||
|
typedef int64_t ssize_t;
|
||||||
|
|
||||||
|
#define SSIZE_MAX INT64_MAX
|
||||||
|
|
||||||
|
#else /* !_WIN64 */
|
||||||
|
|
||||||
|
typedef signed long int ssize_t;
|
||||||
|
|
||||||
|
#define SSIZE_MAX LONG_MAX
|
||||||
|
|
||||||
|
#endif /* _WIN64 */
|
||||||
|
#endif /* !SSIZE_MAX && !HAVE_SSIZE_T */
|
||||||
|
|
||||||
|
#endif /* __POSIX_COMPAT_H__ */
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <wireshark.h>
|
||||||
#include <sbc/sbc.h>
|
#include <sbc/sbc.h>
|
||||||
|
|
||||||
#include "wsutil/codecs.h"
|
#include "wsutil/codecs.h"
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#ifndef __SYNC_PIPE_H__
|
#ifndef __SYNC_PIPE_H__
|
||||||
#define __SYNC_PIPE_H__
|
#define __SYNC_PIPE_H__
|
||||||
|
|
||||||
|
#include <ws_posix_compat.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Maximum length of sync pipe message data. Must be < 2^24, as the
|
* Maximum length of sync pipe message data. Must be < 2^24, as the
|
||||||
|
|
|
@ -275,7 +275,7 @@ buf_read(FILE_T state, struct wtap_reader_buf *buf)
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
state->eof = TRUE;
|
state->eof = TRUE;
|
||||||
state->raw_pos += ret;
|
state->raw_pos += ret;
|
||||||
buf->avail += ret;
|
buf->avail += (guint)ret;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2265,7 +2265,7 @@ gboolean
|
||||||
copy_file_binary_mode(const char *from_filename, const char *to_filename)
|
copy_file_binary_mode(const char *from_filename, const char *to_filename)
|
||||||
{
|
{
|
||||||
int from_fd, to_fd, err;
|
int from_fd, to_fd, err;
|
||||||
ssize_t nread, nwritten;
|
int nread, nwritten;
|
||||||
guint8 *pd = NULL;
|
guint8 *pd = NULL;
|
||||||
|
|
||||||
/* Copy the raw bytes of the file. */
|
/* Copy the raw bytes of the file. */
|
||||||
|
|
Loading…
Reference in New Issue