forked from osmocom/wireshark
Remove inet_aton() usage everywhere
Including where it says not to in comments. Use IPv4 dotted-decimal notation. Change-Id: Iafe1f6fbd2bd5867c41642dc27411f47dff8ce6a Reviewed-on: https://code.wireshark.org/review/24044 Petri-Dish: João Valverde <j@v6e.pt> Tested-by: Petri Dish Buildbot Reviewed-by: João Valverde <j@v6e.pt>
This commit is contained in:
parent
c5529dd7f1
commit
90644c8372
|
@ -114,7 +114,6 @@ if(HAVE_GETOPT_LONG)
|
|||
endif()
|
||||
check_function_exists("getprotobynumber" HAVE_GETPROTOBYNUMBER)
|
||||
check_function_exists("getifaddrs" HAVE_GETIFADDRS)
|
||||
check_function_exists("inet_aton" HAVE_INET_ATON)
|
||||
check_function_exists("inet_ntop" HAVE_INET_NTOP)
|
||||
check_function_exists("inet_pton" HAVE_INET_PTON)
|
||||
check_function_exists("issetugid" HAVE_ISSETUGID)
|
||||
|
|
|
@ -104,9 +104,6 @@
|
|||
/* Define to use heimdal kerberos */
|
||||
#cmakedefine HAVE_HEIMDAL_KERBEROS 1
|
||||
|
||||
/* Define to 1 if you have the `inet_aton' function. */
|
||||
#cmakedefine HAVE_INET_ATON 1
|
||||
|
||||
/* Define to 1 if you have the `inet_ntop' function. */
|
||||
#cmakedefine HAVE_INET_NTOP 1
|
||||
|
||||
|
|
|
@ -2366,7 +2366,6 @@ if test "x$ac_cv_func_getopt_long" = xyes; then
|
|||
fi
|
||||
fi
|
||||
|
||||
AC_REPLACE_FUNCS(inet_aton)
|
||||
AC_REPLACE_FUNCS(inet_pton inet_ntop)
|
||||
AC_REPLACE_FUNCS(strptime)
|
||||
AC_REPLACE_FUNCS(popcount)
|
||||
|
|
|
@ -67,7 +67,6 @@ License: FSL-Kaz
|
|||
contain a copyright notice related to this source.
|
||||
|
||||
Files: epan/in_cksum.c
|
||||
wsutil/inet_aton.c
|
||||
Copyright: 1988, 1992, 1993 The Regents of the University of California.
|
||||
License: BSD-3-clause
|
||||
All rights reserved.
|
||||
|
|
|
@ -103,7 +103,6 @@
|
|||
#include <wsutil/report_message.h>
|
||||
#include <wsutil/file_util.h>
|
||||
#include <wsutil/pint.h>
|
||||
#include "wsutil/inet_aton.h"
|
||||
#include <wsutil/inet_addr.h>
|
||||
|
||||
#include <epan/strutil.h>
|
||||
|
@ -3122,7 +3121,7 @@ c_ares_ghi_cb(void *arg, int status, int timeouts _U_, struct hostent *hp) {
|
|||
gboolean
|
||||
get_host_ipaddr(const char *host, guint32 *addrp)
|
||||
{
|
||||
struct in_addr ipaddr;
|
||||
guint32 ipaddr;
|
||||
#ifdef HAVE_C_ARES
|
||||
struct timeval tv = { 0, GHI_TIMEOUT }, *tvp;
|
||||
int nfds;
|
||||
|
@ -3130,12 +3129,7 @@ get_host_ipaddr(const char *host, guint32 *addrp)
|
|||
async_hostent_t ahe;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* don't change it to inet_pton(AF_INET), they are not 100% compatible.
|
||||
* inet_pton(AF_INET) does not support hexadecimal notation nor
|
||||
* less-than-4 octet notation.
|
||||
*/
|
||||
if (!inet_aton(host, &ipaddr)) {
|
||||
if (!ws_inet_pton4(host, &ipaddr)) {
|
||||
|
||||
/* It's not a valid dotted-quad IP address; is it a valid
|
||||
* host name?
|
||||
|
@ -3185,7 +3179,7 @@ get_host_ipaddr(const char *host, guint32 *addrp)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
*addrp = ipaddr.s_addr;
|
||||
*addrp = ipaddr;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include <epan/conversation.h>
|
||||
#include <epan/exceptions.h>
|
||||
#include <epan/to_str.h>
|
||||
#include <wsutil/inet_aton.h>
|
||||
#include <wsutil/pint.h>
|
||||
|
||||
/* The Aeron protocol is defined at https://github.com/real-logic/Aeron/wiki/Protocol-Specification */
|
||||
|
|
|
@ -70,7 +70,6 @@
|
|||
#include <epan/packet.h>
|
||||
#include <epan/exceptions.h>
|
||||
#include <epan/addr_resolv.h>
|
||||
#include <wsutil/inet_aton.h>
|
||||
#include <epan/expert.h>
|
||||
#include <epan/prefs.h>
|
||||
#include "packet-dcerpc.h"
|
||||
|
@ -1785,7 +1784,7 @@ dissect_dcom_DUALSTRINGARRAY(tvbuff_t *tvb, gint offset, packet_info *pinfo,
|
|||
gboolean isPrintable;
|
||||
guint32 first_ip = 0;
|
||||
guint32 curr_ip = 0;
|
||||
struct in_addr ipaddr;
|
||||
guint32 ipaddr;
|
||||
proto_item *pi;
|
||||
|
||||
|
||||
|
@ -1818,7 +1817,7 @@ dissect_dcom_DUALSTRINGARRAY(tvbuff_t *tvb, gint offset, packet_info *pinfo,
|
|||
|
||||
/* convert ip address (if it is dotted decimal) */
|
||||
/* XXX - this conversion is ugly */
|
||||
if (inet_aton(szStr, &ipaddr)) {
|
||||
if (ws_inet_pton4(szStr, &ipaddr)) {
|
||||
if(get_host_ipaddr(szStr, &curr_ip)) {
|
||||
|
||||
/*expert_add_info_format(pinfo, NULL, PI_UNDECODED, PI_WARN, "DUALSTRINGARRAY: IP:%s",
|
||||
|
|
|
@ -94,7 +94,13 @@
|
|||
#endif
|
||||
#include <stddef.h>
|
||||
|
||||
#include <wsutil/inet_aton.h>
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
# include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINSOCK2_H
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
|
||||
typedef guint8 lbm_uint8_t;
|
||||
typedef guint16 lbm_uint16_t;
|
||||
|
@ -112,8 +118,8 @@ typedef guint64 lbm_uint64_t;
|
|||
#define UAT_IPV4_CB_DEF(basename,field_name,rec_t) \
|
||||
static gboolean basename ## _ ## field_name ## _chk_cb(void * u1 _U_, const char * strptr, unsigned len _U_, const void * u2 _U_, const void * u3 _U_, char ** err) \
|
||||
{ \
|
||||
struct in_addr addr; \
|
||||
if (inet_aton(strptr, &addr) == 0) \
|
||||
guint32 addr; \
|
||||
if (!ws_inet_pton4(strptr, &addr)) \
|
||||
{ \
|
||||
*err = g_strdup("invalid address"); \
|
||||
return (FALSE); \
|
||||
|
@ -122,12 +128,12 @@ typedef guint64 lbm_uint64_t;
|
|||
} \
|
||||
static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* u1 _U_, const void* u2 _U_) \
|
||||
{ \
|
||||
struct in_addr addr; \
|
||||
guint32 addr; \
|
||||
char* new_buf = g_strndup(buf,len); \
|
||||
g_free((((rec_t*)rec)->field_name)); \
|
||||
(((rec_t*)rec)->field_name) = new_buf; \
|
||||
inet_aton(new_buf, &addr); \
|
||||
(((rec_t*)rec)->field_name ## _val_h) = g_ntohl(addr.s_addr); \
|
||||
ws_inet_pton4(new_buf, &addr); \
|
||||
(((rec_t*)rec)->field_name ## _val_h) = g_ntohl(addr); \
|
||||
} \
|
||||
static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* u1 _U_, const void* u2 _U_) \
|
||||
{\
|
||||
|
@ -150,13 +156,13 @@ typedef guint64 lbm_uint64_t;
|
|||
#define UAT_IPV4_MC_CB_DEF(basename,field_name,rec_t) \
|
||||
static gboolean basename ## _ ## field_name ## _chk_cb(void * u1 _U_, const char * strptr, unsigned len _U_, const void * u2 _U_, const void * u3 _U_, char ** err) \
|
||||
{ \
|
||||
struct in_addr addr; \
|
||||
if (inet_aton(strptr, &addr) == 0) \
|
||||
guint32 addr; \
|
||||
if (!ws_inet_pton4(strptr, &addr)) \
|
||||
{ \
|
||||
*err = g_strdup("invalid address"); \
|
||||
return (FALSE); \
|
||||
} \
|
||||
if (!IN_MULTICAST(g_ntohl(addr.s_addr)) && (g_ntohl(addr.s_addr) != 0)) \
|
||||
if (!IN_MULTICAST(g_ntohl(addr)) && (g_ntohl(addr) != 0)) \
|
||||
{ \
|
||||
*err = g_strdup("invalid multicast address"); \
|
||||
return (FALSE); \
|
||||
|
@ -165,12 +171,12 @@ typedef guint64 lbm_uint64_t;
|
|||
} \
|
||||
static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* u1 _U_, const void* u2 _U_) \
|
||||
{ \
|
||||
struct in_addr addr; \
|
||||
guint32 addr; \
|
||||
char* new_buf = g_strndup(buf,len); \
|
||||
g_free((((rec_t*)rec)->field_name)); \
|
||||
(((rec_t*)rec)->field_name) = new_buf; \
|
||||
inet_aton(new_buf, &addr); \
|
||||
(((rec_t*)rec)->field_name ## _val_h) = g_ntohl(addr.s_addr); \
|
||||
ws_inet_pton4(new_buf, &addr); \
|
||||
(((rec_t*)rec)->field_name ## _val_h) = g_ntohl(addr); \
|
||||
} \
|
||||
static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* u1 _U_, const void* u2 _U_) \
|
||||
{\
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
#include <epan/expert.h>
|
||||
#include <epan/uat.h>
|
||||
#include <epan/to_str.h>
|
||||
#include <wsutil/inet_aton.h>
|
||||
#include <wsutil/pint.h>
|
||||
#include "packet-lbm.h"
|
||||
#include "packet-lbtru.h"
|
||||
|
@ -6503,7 +6502,7 @@ void proto_register_lbmr(void)
|
|||
{ &ei_lbmr_analysis_zero_len_option, { "lbmr.analysis.zero_len_option", PI_MALFORMED, PI_ERROR, "Zero-length LBMR option", EXPFILL } },
|
||||
};
|
||||
module_t * lbmr_module;
|
||||
struct in_addr addr;
|
||||
guint32 addr;
|
||||
uat_t * tag_uat;
|
||||
expert_module_t * expert_lbmr;
|
||||
|
||||
|
@ -6522,8 +6521,8 @@ void proto_register_lbmr(void)
|
|||
"Set the UDP port for incoming multicast topic resolution (context resolver_multicast_incoming_port)",
|
||||
10,
|
||||
&global_lbmr_mc_incoming_udp_port);
|
||||
inet_aton(LBMR_DEFAULT_MC_INCOMING_ADDRESS, &addr);
|
||||
lbmr_mc_incoming_address_host = g_ntohl(addr.s_addr);
|
||||
ws_inet_pton4(LBMR_DEFAULT_MC_INCOMING_ADDRESS, &addr);
|
||||
lbmr_mc_incoming_address_host = g_ntohl(addr);
|
||||
prefs_register_string_preference(lbmr_module,
|
||||
"mc_incoming_address",
|
||||
"Incoming multicast address (default " LBMR_DEFAULT_MC_INCOMING_ADDRESS ")",
|
||||
|
@ -6535,8 +6534,8 @@ void proto_register_lbmr(void)
|
|||
"Set the UDP port for outgoing multicast topic resolution (context resolver_multicast_outgoing_port)",
|
||||
10,
|
||||
&global_lbmr_mc_outgoing_udp_port);
|
||||
inet_aton(LBMR_DEFAULT_MC_OUTGOING_ADDRESS, &addr);
|
||||
lbmr_mc_outgoing_address_host = g_ntohl(addr.s_addr);
|
||||
ws_inet_pton4(LBMR_DEFAULT_MC_OUTGOING_ADDRESS, &addr);
|
||||
lbmr_mc_outgoing_address_host = g_ntohl(addr);
|
||||
prefs_register_string_preference(lbmr_module,
|
||||
"mc_outgoing_address",
|
||||
"Outgoing multicast address (default " LBMR_DEFAULT_MC_OUTGOING_ADDRESS ")",
|
||||
|
@ -6560,8 +6559,8 @@ void proto_register_lbmr(void)
|
|||
"Set the destination port for unicast topic resolution (context resolver_unicast_destination_port)",
|
||||
10,
|
||||
&global_lbmr_uc_dest_port);
|
||||
inet_aton(LBMR_DEFAULT_UC_ADDRESS, &addr);
|
||||
lbmr_uc_address_host = g_ntohl(addr.s_addr);
|
||||
ws_inet_pton4(LBMR_DEFAULT_UC_ADDRESS, &addr);
|
||||
lbmr_uc_address_host = g_ntohl(addr);
|
||||
prefs_register_string_preference(lbmr_module,
|
||||
"uc_address",
|
||||
"Unicast resolver address (default " LBMR_DEFAULT_UC_ADDRESS ")",
|
||||
|
@ -6686,7 +6685,7 @@ void proto_register_lbmr(void)
|
|||
void proto_reg_handoff_lbmr(void)
|
||||
{
|
||||
static gboolean already_registered = FALSE;
|
||||
struct in_addr addr;
|
||||
guint32 addr;
|
||||
|
||||
if (!already_registered)
|
||||
{
|
||||
|
@ -6697,11 +6696,11 @@ void proto_reg_handoff_lbmr(void)
|
|||
|
||||
lbmr_mc_incoming_udp_port = global_lbmr_mc_incoming_udp_port;
|
||||
lbmr_mc_outgoing_udp_port = global_lbmr_mc_outgoing_udp_port;
|
||||
inet_aton(global_lbmr_mc_incoming_address, &addr);
|
||||
lbmr_mc_incoming_address_host = g_ntohl(addr.s_addr);
|
||||
ws_inet_pton4(global_lbmr_mc_incoming_address, &addr);
|
||||
lbmr_mc_incoming_address_host = g_ntohl(addr);
|
||||
|
||||
inet_aton(global_lbmr_mc_outgoing_address, &addr);
|
||||
lbmr_mc_outgoing_address_host = g_ntohl(addr.s_addr);
|
||||
ws_inet_pton4(global_lbmr_mc_outgoing_address, &addr);
|
||||
lbmr_mc_outgoing_address_host = g_ntohl(addr);
|
||||
|
||||
/* Make sure the low port is <= the high port. If not, don't change them. */
|
||||
if (global_lbmr_uc_port_low <= global_lbmr_uc_port_high)
|
||||
|
@ -6710,8 +6709,8 @@ void proto_reg_handoff_lbmr(void)
|
|||
lbmr_uc_port_low = global_lbmr_uc_port_low;
|
||||
}
|
||||
lbmr_uc_dest_port = global_lbmr_uc_dest_port;
|
||||
inet_aton(global_lbmr_uc_address, &addr);
|
||||
lbmr_uc_address_host = g_ntohl(addr.s_addr);
|
||||
ws_inet_pton4(global_lbmr_uc_address, &addr);
|
||||
lbmr_uc_address_host = g_ntohl(addr);
|
||||
lbmr_use_tag = global_lbmr_use_tag;
|
||||
|
||||
already_registered = TRUE;
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#include <epan/tap.h>
|
||||
#include <epan/conversation.h>
|
||||
#include <epan/to_str.h>
|
||||
#include <wsutil/inet_aton.h>
|
||||
#include <wsutil/pint.h>
|
||||
#include "packet-lbm.h"
|
||||
#include "packet-lbtrm.h"
|
||||
|
@ -1721,7 +1720,7 @@ void proto_register_lbtrm(void)
|
|||
{ &ei_lbtrm_analysis_sm_dup, { "lbtrm.analysis.sm.dup", PI_SEQUENCE, PI_NOTE, "Duplicate SM", EXPFILL } },
|
||||
};
|
||||
module_t * lbtrm_module;
|
||||
struct in_addr addr;
|
||||
guint32 addr;
|
||||
uat_t * tag_uat;
|
||||
expert_module_t * expert_lbtrm;
|
||||
|
||||
|
@ -1734,16 +1733,16 @@ void proto_register_lbtrm(void)
|
|||
expert_register_field_array(expert_lbtrm, ei, array_length(ei));
|
||||
|
||||
lbtrm_module = prefs_register_protocol_subtree("29West", proto_lbtrm, proto_reg_handoff_lbtrm);
|
||||
inet_aton(LBTRM_DEFAULT_MC_ADDRESS_LOW, &addr);
|
||||
lbtrm_mc_address_low_host = g_ntohl(addr.s_addr);
|
||||
ws_inet_pton4(LBTRM_DEFAULT_MC_ADDRESS_LOW, &addr);
|
||||
lbtrm_mc_address_low_host = g_ntohl(addr);
|
||||
prefs_register_string_preference(lbtrm_module,
|
||||
"mc_address_low",
|
||||
"Multicast address range low (default " LBTRM_DEFAULT_MC_ADDRESS_LOW ")",
|
||||
"Set the low end of the LBT-RM multicast address range (context transport_lbtrm_multicast_address_low)",
|
||||
&global_lbtrm_mc_address_low);
|
||||
|
||||
inet_aton(LBTRM_DEFAULT_MC_ADDRESS_HIGH, &addr);
|
||||
lbtrm_mc_address_high_host = g_ntohl(addr.s_addr);
|
||||
ws_inet_pton4(LBTRM_DEFAULT_MC_ADDRESS_HIGH, &addr);
|
||||
lbtrm_mc_address_high_host = g_ntohl(addr);
|
||||
prefs_register_string_preference(lbtrm_module,
|
||||
"mc_address_high",
|
||||
"Multicast address range high (default " LBTRM_DEFAULT_MC_ADDRESS_HIGH ")",
|
||||
|
@ -1778,16 +1777,16 @@ void proto_register_lbtrm(void)
|
|||
10,
|
||||
&global_lbtrm_src_port_high);
|
||||
|
||||
inet_aton(MIM_DEFAULT_MC_INCOMING_ADDRESS, &addr);
|
||||
mim_incoming_mc_address_host = g_ntohl(addr.s_addr);
|
||||
ws_inet_pton4(MIM_DEFAULT_MC_INCOMING_ADDRESS, &addr);
|
||||
mim_incoming_mc_address_host = g_ntohl(addr);
|
||||
prefs_register_string_preference(lbtrm_module,
|
||||
"mim_incoming_address",
|
||||
"MIM incoming multicast address (default " MIM_DEFAULT_MC_INCOMING_ADDRESS ")",
|
||||
"Set the incoming MIM multicast address (context mim_incoming_address)",
|
||||
&global_mim_incoming_mc_address);
|
||||
|
||||
inet_aton(MIM_DEFAULT_MC_OUTGOING_ADDRESS, &addr);
|
||||
mim_outgoing_mc_address_host = g_ntohl(addr.s_addr);
|
||||
ws_inet_pton4(MIM_DEFAULT_MC_OUTGOING_ADDRESS, &addr);
|
||||
mim_outgoing_mc_address_host = g_ntohl(addr);
|
||||
prefs_register_string_preference(lbtrm_module,
|
||||
"mim_outgoing_address",
|
||||
"MIM outgoing multicast address (default " MIM_DEFAULT_MC_OUTGOING_ADDRESS ")",
|
||||
|
@ -1860,7 +1859,7 @@ void proto_register_lbtrm(void)
|
|||
void proto_reg_handoff_lbtrm(void)
|
||||
{
|
||||
static gboolean already_registered = FALSE;
|
||||
struct in_addr addr;
|
||||
guint32 addr;
|
||||
guint32 dest_addr_h_low;
|
||||
guint32 dest_addr_h_high;
|
||||
|
||||
|
@ -1873,10 +1872,10 @@ void proto_reg_handoff_lbtrm(void)
|
|||
}
|
||||
|
||||
/* Make sure the low MC address is <= the high MC address. If not, don't change them. */
|
||||
inet_aton(global_lbtrm_mc_address_low, &addr);
|
||||
dest_addr_h_low = g_ntohl(addr.s_addr);
|
||||
inet_aton(global_lbtrm_mc_address_high, &addr);
|
||||
dest_addr_h_high = g_ntohl(addr.s_addr);
|
||||
ws_inet_pton4(global_lbtrm_mc_address_low, &addr);
|
||||
dest_addr_h_low = g_ntohl(addr);
|
||||
ws_inet_pton4(global_lbtrm_mc_address_high, &addr);
|
||||
dest_addr_h_high = g_ntohl(addr);
|
||||
if (dest_addr_h_low <= dest_addr_h_high)
|
||||
{
|
||||
lbtrm_mc_address_low_host = dest_addr_h_low;
|
||||
|
@ -1898,10 +1897,10 @@ void proto_reg_handoff_lbtrm(void)
|
|||
}
|
||||
|
||||
/* Add the dissector hooks for the MIM MC groups. */
|
||||
inet_aton(global_mim_incoming_mc_address, &addr);
|
||||
mim_incoming_mc_address_host = g_htonl(addr.s_addr);
|
||||
inet_aton(global_mim_outgoing_mc_address, &addr);
|
||||
mim_outgoing_mc_address_host = g_htonl(addr.s_addr);
|
||||
ws_inet_pton4(global_mim_incoming_mc_address, &addr);
|
||||
mim_incoming_mc_address_host = g_htonl(addr);
|
||||
ws_inet_pton4(global_mim_outgoing_mc_address, &addr);
|
||||
mim_outgoing_mc_address_host = g_htonl(addr);
|
||||
|
||||
/* Add the dissector hooks for the MIM ports. */
|
||||
mim_incoming_dest_port = global_mim_incoming_dest_port;
|
||||
|
|
|
@ -18,7 +18,6 @@ epan/wmem/wmem_strutil.c
|
|||
extcap/*
|
||||
tools/lemon/*
|
||||
wsutil/file_util.h
|
||||
wsutil/inet_aton.c
|
||||
wsutil/inet_ntop.c
|
||||
wsutil/inet_pton.c
|
||||
wsutil/strptime.c
|
||||
|
|
|
@ -57,10 +57,6 @@ indent_size = tab
|
|||
indent_style = tab
|
||||
indent_size = tab
|
||||
|
||||
[inet_aton.[ch]]
|
||||
indent_style = tab
|
||||
indent_size = tab
|
||||
|
||||
[inet_ntop.[ch]]
|
||||
indent_style = tab
|
||||
indent_size = tab
|
||||
|
|
|
@ -213,10 +213,6 @@ if(NOT HAVE_GETOPT_LONG)
|
|||
list(APPEND WSUTIL_FILES getopt_long.c)
|
||||
endif()
|
||||
|
||||
if(NOT HAVE_INET_ATON)
|
||||
list(APPEND WSUTIL_FILES inet_aton.c)
|
||||
endif()
|
||||
|
||||
if(NOT HAVE_POPCOUNT)
|
||||
list(APPEND WSUTIL_FILES popcount.c)
|
||||
endif()
|
||||
|
|
|
@ -192,8 +192,6 @@ EXTRA_DIST = \
|
|||
file_util.h \
|
||||
getopt_long.c \
|
||||
getopt_long.h \
|
||||
inet_aton.c \
|
||||
inet_aton.h \
|
||||
inet_ntop.c \
|
||||
inet_pton.c \
|
||||
popcount.c \
|
||||
|
|
|
@ -1,155 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 1983, 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "inet_aton.h"
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef HAVE_SYS_PARAM_H
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Check whether "cp" is a valid ascii representation
|
||||
* of an Internet address and convert to a binary address.
|
||||
* Returns 1 if the address is valid, 0 if not.
|
||||
* This replaces inet_addr, the return value from which
|
||||
* cannot distinguish between failure and a local broadcast address.
|
||||
*/
|
||||
int
|
||||
inet_aton(cp_arg, addr)
|
||||
const char *cp_arg;
|
||||
struct in_addr *addr;
|
||||
{
|
||||
register const u_char *cp = cp_arg;
|
||||
register u_long val;
|
||||
register int base;
|
||||
register size_t n;
|
||||
register u_char c;
|
||||
u_int parts[4];
|
||||
register u_int *pp = parts;
|
||||
|
||||
for (;;) {
|
||||
/*
|
||||
* Collect number up to ``.''.
|
||||
* Values are specified as for C:
|
||||
* 0x=hex, 0=octal, other=decimal.
|
||||
*/
|
||||
val = 0; base = 10;
|
||||
if (*cp == '0') {
|
||||
if (*++cp == 'x' || *cp == 'X')
|
||||
base = 16, cp++;
|
||||
else
|
||||
base = 8;
|
||||
}
|
||||
while ((c = *cp) != '\0') {
|
||||
if (isascii(c) && isdigit(c)) {
|
||||
val = (val * base) + (c - '0');
|
||||
cp++;
|
||||
continue;
|
||||
}
|
||||
if (base == 16 && isascii(c) && isxdigit(c)) {
|
||||
val = (val << 4) +
|
||||
(c + 10 - (islower(c) ? 'a' : 'A'));
|
||||
cp++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (*cp == '.') {
|
||||
/*
|
||||
* Internet format:
|
||||
* a.b.c.d
|
||||
* a.b.c (with c treated as 16-bits)
|
||||
* a.b (with b treated as 24 bits)
|
||||
*/
|
||||
if (pp >= parts + 3 || val > 0xff)
|
||||
return (0);
|
||||
*pp++ = val, cp++;
|
||||
} else
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Check for trailing characters.
|
||||
*/
|
||||
if (*cp && (!isascii(*cp) || !isspace(*cp)))
|
||||
return (0);
|
||||
/*
|
||||
* Concoct the address according to
|
||||
* the number of parts specified.
|
||||
*/
|
||||
n = pp - parts + 1;
|
||||
switch (n) {
|
||||
|
||||
case 1: /* a -- 32 bits */
|
||||
break;
|
||||
|
||||
case 2: /* a.b -- 8.24 bits */
|
||||
if (val > 0xffffff)
|
||||
return (0);
|
||||
val |= parts[0] << 24;
|
||||
break;
|
||||
|
||||
case 3: /* a.b.c -- 8.8.16 bits */
|
||||
if (val > 0xffff)
|
||||
return (0);
|
||||
val |= (parts[0] << 24) | (parts[1] << 16);
|
||||
break;
|
||||
|
||||
case 4: /* a.b.c.d -- 8.8.8.8 bits */
|
||||
if (val > 0xff)
|
||||
return (0);
|
||||
val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
|
||||
break;
|
||||
}
|
||||
if (addr)
|
||||
addr->s_addr = htonl(val);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
||||
*
|
||||
* Local variables:
|
||||
* c-basic-offset: 8
|
||||
* tab-width: 8
|
||||
* indent-tabs-mode: t
|
||||
* End:
|
||||
*
|
||||
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
|
||||
* :indentSize=8:tabSize=8:noTabs=false:
|
||||
*/
|
|
@ -1,52 +0,0 @@
|
|||
/* inet_aton.h
|
||||
*
|
||||
* Wireshark - Network traffic analyzer
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Version of "inet_aton()", for the benefit of OSes that don't have it.
|
||||
*/
|
||||
|
||||
#ifndef __INET_ATON_H__
|
||||
#define __INET_ATON_H__
|
||||
|
||||
#include "ws_symbol_export.h"
|
||||
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h> /* needed to define AF_ values on UNIX */
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
# include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINSOCK2_H
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_INET_ATON
|
||||
struct in_addr;
|
||||
WS_DLL_PUBLIC int inet_aton(const char* cp_arg, struct in_addr *addr);
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue