aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Valverde <joao.valverde@tecnico.ulisboa.pt>2017-11-08 14:02:08 +0000
committerJoão Valverde <j@v6e.pt>2017-11-09 16:08:25 +0000
commit39967011836c1e23dff188ffaadb747d9dcda062 (patch)
tree768e37aa23b5ad8775a47543ce26f1fdb3f3269d
parent2ebc41050e43c508edbc8c0fa8cccb9797c463cf (diff)
Replace inet_addr() with our inet_pton() wrapper
Error checking omitted like in original code. Change-Id: If8b4181d30ddf5717951aaf7ec61db25c0bc5322 Reviewed-on: https://code.wireshark.org/review/24309 Petri-Dish: João Valverde <j@v6e.pt> Tested-by: Petri Dish Buildbot Reviewed-by: João Valverde <j@v6e.pt>
-rw-r--r--extcap/androiddump.c7
-rw-r--r--extcap/udpdump.c4
-rw-r--r--sharkd_daemon.c7
-rw-r--r--wsutil/inet_addr.h3
-rw-r--r--wsutil/inet_ipv4.h6
5 files changed, 15 insertions, 12 deletions
diff --git a/extcap/androiddump.c b/extcap/androiddump.c
index 9635dd5..9fa0e4c 100644
--- a/extcap/androiddump.c
+++ b/extcap/androiddump.c
@@ -33,6 +33,7 @@
#include <wsutil/strtoi.h>
#include <wsutil/filesystem.h>
#include <wsutil/cmdarg_err.h>
+#include <wsutil/inet_addr.h>
#include "ui/failure_message.h"
@@ -539,7 +540,7 @@ static socket_handle_t adb_connect(const char *server_ip, unsigned short *server
server.sin_family = AF_INET;
server.sin_port = GINT16_TO_BE(*server_tcp_port);
- server.sin_addr.s_addr = inet_addr(server_ip);
+ ws_inet_pton4(server_ip, &(server.sin_addr.s_addr));
if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) {
g_warning("Cannot open system TCP socket: %s", strerror(errno));
@@ -1680,7 +1681,7 @@ static int capture_android_bluetooth_external_parser(char *interface,
memset(&server, 0 , sizeof(server));
server.sin_family = AF_INET;
server.sin_port = GINT16_TO_BE(*bt_local_tcp_port);
- server.sin_addr.s_addr = inet_addr(bt_local_ip);
+ ws_inet_pton4(bt_local_ip, &(server.sin_addr.s_addr));
useSndTimeout(sock);
@@ -1755,7 +1756,7 @@ static int capture_android_bluetooth_external_parser(char *interface,
server.sin_family = AF_INET;
server.sin_port = GINT16_TO_BE(*bt_local_tcp_port);
- server.sin_addr.s_addr = inet_addr(bt_local_ip);
+ ws_inet_pton4(bt_local_ip, &(server.sin_addr.s_addr));
useSndTimeout(sock);
diff --git a/extcap/udpdump.c b/extcap/udpdump.c
index 88da1b8..30c30f7 100644
--- a/extcap/udpdump.c
+++ b/extcap/udpdump.c
@@ -81,7 +81,6 @@
#define EXP_PDU_TAG_DST_PORT 26
static gboolean run_loop = TRUE;
-static uint32_t localhost = 0;
enum {
EXTCAP_BASE_OPTIONS_ENUM,
@@ -284,7 +283,7 @@ static int dump_packet(const char* proto_name, const guint16 listenport, const c
add_proto_name(mbuf, &offset, proto_name);
add_ip_source_address(mbuf, &offset, clientaddr.sin_addr.s_addr);
- add_ip_dest_address(mbuf, &offset, localhost);
+ add_ip_dest_address(mbuf, &offset, WS_IN4_LOOPBACK);
add_udp_source_port(mbuf, &offset, clientaddr.sin_port);
add_udp_dst_port(mbuf, &offset, listenport);
add_end_options(mbuf, &offset);
@@ -329,7 +328,6 @@ static void run_listener(const char* fifo, const guint16 port, const char* proto
g_debug("Listener running on port %u", port);
buf = (char*)g_malloc(PKT_BUF_SIZE);
- localhost = inet_addr("127.0.0.1");
while(run_loop == TRUE) {
memset(buf, 0x0, PKT_BUF_SIZE);
diff --git a/sharkd_daemon.c b/sharkd_daemon.c
index c3dea96..f9b44cb 100644
--- a/sharkd_daemon.c
+++ b/sharkd_daemon.c
@@ -41,10 +41,7 @@
#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>
@@ -145,7 +142,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 = ':';
diff --git a/wsutil/inet_addr.h b/wsutil/inet_addr.h
index a3d45e2..27ad4f1 100644
--- a/wsutil/inet_addr.h
+++ b/wsutil/inet_addr.h
@@ -30,6 +30,7 @@
#endif
#include <glib.h>
+#include "inet_ipv4.h"
#include "inet_ipv6.h"
/*
@@ -83,7 +84,7 @@ WS_DLL_PUBLIC WS_RETNONNULL const gchar *
ws_inet_ntop6(gconstpointer src, gchar *dst, guint dst_size);
WS_DLL_PUBLIC gboolean
-ws_inet_pton4(const gchar *src, guint32 *dst);
+ws_inet_pton4(const gchar *src, ws_in4_addr *dst);
WS_DLL_PUBLIC gboolean
ws_inet_pton6(const gchar *src, ws_in6_addr *dst);
diff --git a/wsutil/inet_ipv4.h b/wsutil/inet_ipv4.h
index 9c1094f..f86ac6d 100644
--- a/wsutil/inet_ipv4.h
+++ b/wsutil/inet_ipv4.h
@@ -26,6 +26,12 @@
typedef guint32 ws_in4_addr; /* 32 bit IPv4 address, in network byte order */
+/*
+ * We define these in *network byte order*, unlike the C library. Therefore
+ * it uses a different prefix than INADDR_* to make the distinction more obvious.
+ */
+#define WS_IN4_LOOPBACK ((ws_in4_addr)GUINT32_TO_BE(0x7f000001))
+
/**
* Unicast Local
* Returns true if the address is in the 224.0.0.0/24 local network