From 9d245ff3ca503416f98b35ea2a5f5d5ab7e7a5d9 Mon Sep 17 00:00:00 2001 From: Gisle Vanem Date: Sat, 3 Oct 2020 15:09:39 +0200 Subject: [PATCH] Added IANA support: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Handle IANA's "IPv4 Address Space Registry" and the "IPv6 Global Unicast Address Assignments". With a '[IANA] enable = 1' in the 'wsock-trace' config file, print informtion on the network block in all Winsock functions handling IPv4 or IPv6 addresses. Like this in 'recvfrom()' : * 0.189 sec: src/lib/ares_process.c(132) (processfds+1945): recvfrom (688, 0x00EFE4B4, 4097, 0, 1.1.1.1:53) --> 59 bytes. 0000: 4F 85 81 80 00 01 00 02 00 00 00 00 03 77 77 77 OàüÇ.........www 0010: 02 76 67 02 6E 6F 00 00 01 00 01 C0 0C 00 01 00 .vg.no.....+.... 0020: 01 00 00 00 3D 00 04 C3 58 37 10 C0 0C 00 01 00 ....=..+X7.+.... 0030: 01 00 00 00 3D 00 04 C3 58 36 10 ....=..+X6. geo-IP: US - United States, Los Angeles/California IANA: 001/8, APNIC, 2010-01, whois.apnic.net, https://rdap.apnic.net/, ALLOCATED Or for IPv6 in 'getnameinfo()': * 0.422 sec: test.c(337) (test_getnameinfo+845): getnameinfo ([2a00:1450:4010:c07::63]:80, ..., NI_DGRAM) --> No error. name: lf-in-x63.1e100.net, serv: NULL geo-IP: FI - Finland, Lappeenranta/Etela-Karjala IANA: 2a00::/12, RIPE NCC, 2006-10-03, whois.ripe.net, https://rdap.db.ripe.net/, ALLOCATED --- README.md | 2 + appveyor-script.bat | 122 +++++++++--------- ipv4-address-space.csv | 47 +++---- src/Makefile.CygWin | 4 +- src/Makefile.MingW | 16 ++- src/Makefile.Watcom | 9 +- src/Makefile.vc6 | 30 +++-- src/Wsock-trace.vcxproj | 1 + src/backtrace.c | 2 + src/dump.c | 111 +++++++++++++++- src/dump.h | 4 + src/init.c | 276 ++++++++++++++++++++++------------------ src/init.h | 7 + src/wsock_trace.c | 54 ++++++++ wsock_trace | 13 ++ 15 files changed, 467 insertions(+), 231 deletions(-) diff --git a/README.md b/README.md index 63d10033..22240de5 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,8 @@ There is currently no `install.bat` file for Wsock-trace. So you should copy the drop.txt edrop.txt dropv6.txt + ipv4-address-space.csv + ipv6-unicast-address-assignments.csv ``` These environment variables are on the form: diff --git a/appveyor-script.bat b/appveyor-script.bat index 9e4cfd22..9e736531 100644 --- a/appveyor-script.bat +++ b/appveyor-script.bat @@ -17,65 +17,69 @@ exit /b 1 :: The "CPU" and "BUILDER" agnostic init-stage. :: echo Generating %CD%\wsock_trace.appveyor... -echo # > wsock_trace.appveyor -echo # This file was generated from %0. >> wsock_trace.appveyor -echo # >> wsock_trace.appveyor -echo [core] >> wsock_trace.appveyor -echo trace_level = %%WSOCK_TRACE_LEVEL%% >> wsock_trace.appveyor -echo trace_indent = 2 >> wsock_trace.appveyor -echo trace_caller = 1 >> wsock_trace.appveyor -echo trace_report = %%WSOCK_TRACE_LEVEL%% >> wsock_trace.appveyor -echo trace_time = relative >> wsock_trace.appveyor -echo trace_max_len = %%COLUMNS%% >> wsock_trace.appveyor -echo callee_level = 1 >> wsock_trace.appveyor -echo cpp_demangle = 1 >> wsock_trace.appveyor -echo short_errors = 1 >> wsock_trace.appveyor -echo use_full_path = 1 >> wsock_trace.appveyor -echo use_toolhlp32 = 1 >> wsock_trace.appveyor -echo dump_modules = 0 >> wsock_trace.appveyor -echo dump_select = 1 >> wsock_trace.appveyor -echo dump_hostent = 1 >> wsock_trace.appveyor -echo dump_protoent = 1 >> wsock_trace.appveyor -echo dump_servent = 1 >> wsock_trace.appveyor -echo dump_nameinfo = 1 >> wsock_trace.appveyor -echo dump_wsaprotocol_info = 1 >> wsock_trace.appveyor -echo dump_wsanetwork_events = 1 >> wsock_trace.appveyor -echo dump_data = 1 >> wsock_trace.appveyor -echo max_data = 5000 >> wsock_trace.appveyor -echo max_displacement = 1000 >> wsock_trace.appveyor -echo exclude = htons,htonl,inet_addr >> wsock_trace.appveyor -echo hosts_file = %CD%\appveyor-hosts >> wsock_trace.appveyor -echo use_winhttp = 0 >> wsock_trace.appveyor -echo [geoip] >> wsock_trace.appveyor -echo enable = 1 >> wsock_trace.appveyor -echo use_generated = 0 >> wsock_trace.appveyor -echo max_days = 10 >> wsock_trace.appveyor -echo geoip4_file = %CD%\geoip >> wsock_trace.appveyor -echo geoip6_file = %CD%\geoip6 >> wsock_trace.appveyor -echo ip2location_bin_file = %CD%\IP46-COUNTRY.BIN >> wsock_trace.appveyor -echo [idna] >> wsock_trace.appveyor -echo enable = 1 >> wsock_trace.appveyor -echo [lua] >> wsock_trace.appveyor -echo enable = %%USE_LUA%% >> wsock_trace.appveyor -echo trace_level = 1 >> wsock_trace.appveyor -echo lua_init = %CD%\src\wsock_trace_init.lua >> wsock_trace.appveyor -echo lua_exit = %CD%\src\wsock_trace_exit.lua >> wsock_trace.appveyor -echo [dnsbl] >> wsock_trace.appveyor -echo enable = 1 >> wsock_trace.appveyor -echo test = %%TEST_DNSBL%% >> wsock_trace.appveyor -echo max_days = 1 >> wsock_trace.appveyor -echo drop_file = %CD%\drop.txt >> wsock_trace.appveyor -echo edrop_file = %CD%\edrop.txt >> wsock_trace.appveyor -echo dropv6_file = %CD%\dropv6.txt >> wsock_trace.appveyor -echo drop_url = http://www.spamhaus.org/drop/drop.txt >> wsock_trace.appveyor -echo edrop_url = http://www.spamhaus.org/drop/edrop.txt >> wsock_trace.appveyor -echo dropv6_url = http://www.spamhaus.org/drop/dropv6.txt >> wsock_trace.appveyor -echo [firewall] >> wsock_trace.appveyor -echo enable = 0 >> wsock_trace.appveyor -echo show_ipv4 = 1 >> wsock_trace.appveyor -echo show_ipv6 = 0 >> wsock_trace.appveyor -echo show_all = 0 >> wsock_trace.appveyor -echo api_level = 3 >> wsock_trace.appveyor +echo # > wsock_trace.appveyor +echo # This file was generated from %0. >> wsock_trace.appveyor +echo # >> wsock_trace.appveyor +echo [core] >> wsock_trace.appveyor +echo trace_level = %%WSOCK_TRACE_LEVEL%% >> wsock_trace.appveyor +echo trace_indent = 2 >> wsock_trace.appveyor +echo trace_caller = 1 >> wsock_trace.appveyor +echo trace_report = %%WSOCK_TRACE_LEVEL%% >> wsock_trace.appveyor +echo trace_time = relative >> wsock_trace.appveyor +echo trace_max_len = %%COLUMNS%% >> wsock_trace.appveyor +echo callee_level = 1 >> wsock_trace.appveyor +echo cpp_demangle = 1 >> wsock_trace.appveyor +echo short_errors = 1 >> wsock_trace.appveyor +echo use_full_path = 1 >> wsock_trace.appveyor +echo use_toolhlp32 = 1 >> wsock_trace.appveyor +echo dump_modules = 0 >> wsock_trace.appveyor +echo dump_select = 1 >> wsock_trace.appveyor +echo dump_hostent = 1 >> wsock_trace.appveyor +echo dump_protoent = 1 >> wsock_trace.appveyor +echo dump_servent = 1 >> wsock_trace.appveyor +echo dump_nameinfo = 1 >> wsock_trace.appveyor +echo dump_wsaprotocol_info = 1 >> wsock_trace.appveyor +echo dump_wsanetwork_events = 1 >> wsock_trace.appveyor +echo dump_data = 1 >> wsock_trace.appveyor +echo max_data = 5000 >> wsock_trace.appveyor +echo max_displacement = 1000 >> wsock_trace.appveyor +echo exclude = htons,htonl,inet_addr >> wsock_trace.appveyor +echo hosts_file = %CD%\appveyor-hosts >> wsock_trace.appveyor +echo use_winhttp = 0 >> wsock_trace.appveyor +echo [geoip] >> wsock_trace.appveyor +echo enable = 1 >> wsock_trace.appveyor +echo use_generated = 0 >> wsock_trace.appveyor +echo max_days = 10 >> wsock_trace.appveyor +echo geoip4_file = %CD%\geoip >> wsock_trace.appveyor +echo geoip6_file = %CD%\geoip6 >> wsock_trace.appveyor +echo ip2location_bin_file = %CD%\IP46-COUNTRY.BIN >> wsock_trace.appveyor +echo [iana] >> wsock_trace.appveyor +echo enable = 1 >> wsock_trace.appveyor +echo ip4_file = %CD%\ipv4-address-space.csv >> wsock_trace.appveyor +echo ip6_file = %CD%\ipv6-address-space.csv >> wsock_trace.appveyor +echo [idna] >> wsock_trace.appveyor +echo enable = 1 >> wsock_trace.appveyor +echo [lua] >> wsock_trace.appveyor +echo enable = %%USE_LUA%% >> wsock_trace.appveyor +echo trace_level = 1 >> wsock_trace.appveyor +echo lua_init = %CD%\src\wsock_trace_init.lua >> wsock_trace.appveyor +echo lua_exit = %CD%\src\wsock_trace_exit.lua >> wsock_trace.appveyor +echo [dnsbl] >> wsock_trace.appveyor +echo enable = 1 >> wsock_trace.appveyor +echo test = %%TEST_DNSBL%% >> wsock_trace.appveyor +echo max_days = 1 >> wsock_trace.appveyor +echo drop_file = %CD%\drop.txt >> wsock_trace.appveyor +echo edrop_file = %CD%\edrop.txt >> wsock_trace.appveyor +echo dropv6_file = %CD%\dropv6.txt >> wsock_trace.appveyor +echo drop_url = http://www.spamhaus.org/drop/drop.txt >> wsock_trace.appveyor +echo edrop_url = http://www.spamhaus.org/drop/edrop.txt >> wsock_trace.appveyor +echo dropv6_url = http://www.spamhaus.org/drop/dropv6.txt >> wsock_trace.appveyor +echo [firewall] >> wsock_trace.appveyor +echo enable = 0 >> wsock_trace.appveyor +echo show_ipv4 = 1 >> wsock_trace.appveyor +echo show_ipv6 = 0 >> wsock_trace.appveyor +echo show_all = 0 >> wsock_trace.appveyor +echo api_level = 3 >> wsock_trace.appveyor :: :: Windows-Defender thinks generating a 'hosts' file is suspicious. diff --git a/ipv4-address-space.csv b/ipv4-address-space.csv index 8d95e710..16e9172b 100644 --- a/ipv4-address-space.csv +++ b/ipv4-address-space.csv @@ -1,10 +1,11 @@ Prefix,Designation,Date,WHOIS,RDAP,Status [1],Note -038/8,"PSINet, Inc.",1994-09,whois.arin.net, "https://rdap.arin.net/registry http://rdap.arin.net/registry", LEGACY, -000/8,IANA - Local Identification, 1981-09,,,RESERVED,[2] +000/8,IANA - Local Identification,1981-09,,,RESERVED,[2] 001/8,APNIC,2010-01,whois.apnic.net,https://rdap.apnic.net/,ALLOCATED, 002/8,RIPE NCC,2009-09,whois.ripe.net,https://rdap.db.ripe.net/,ALLOCATED, -003/8, Administered by ARIN, 1994-05, whois.arin.net, "https://rdap.arin.net/registry http://rdap.arin.net/registry",LEGACY, -004/8, Administered by ARIN,1992-12,whois.arin.net,"https://rdap.arin.net/registry http://rdap.arin.net/registry", LEGACY, +003/8,Administered by ARIN,1994-05,whois.arin.net,"https://rdap.arin.net/registry +http://rdap.arin.net/registry",LEGACY, +004/8,Administered by ARIN,1992-12,whois.arin.net,"https://rdap.arin.net/registry +http://rdap.arin.net/registry",LEGACY, 005/8,RIPE NCC,2010-11,whois.ripe.net,https://rdap.db.ripe.net/,ALLOCATED, 006/8,Army Information Systems Center,1994-02,whois.arin.net,"https://rdap.arin.net/registry http://rdap.arin.net/registry",LEGACY, @@ -63,6 +64,8 @@ http://rdap.arin.net/registry",LEGACY, http://rdap.arin.net/registry",LEGACY, 036/8,APNIC,2010-10,whois.apnic.net,https://rdap.apnic.net/,ALLOCATED, 037/8,RIPE NCC,2010-11,whois.ripe.net,https://rdap.db.ripe.net/,ALLOCATED, +038/8,"PSINet, Inc.",1994-09,whois.arin.net,"https://rdap.arin.net/registry +http://rdap.arin.net/registry",LEGACY, 039/8,APNIC,2011-01,whois.apnic.net,https://rdap.apnic.net/,ALLOCATED, 040/8,Administered by ARIN,1994-06,whois.arin.net,"https://rdap.arin.net/registry http://rdap.arin.net/registry",LEGACY, @@ -126,24 +129,6 @@ http://rdap.arin.net/registry",ALLOCATED, http://rdap.arin.net/registry",ALLOCATED, 076/8,ARIN,2005-06,whois.arin.net,"https://rdap.arin.net/registry http://rdap.arin.net/registry",ALLOCATED, -238/8,Multicast,1981-09,,,RESERVED,[13] -239/8,Multicast,1981-09,,,RESERVED,[13][15] -240/8,Future use,1981-09,,,RESERVED,[16] -241/8,Future use,1981-09,,,RESERVED,[16] -242/8,Future use,1981-09,,,RESERVED,[16] -243/8,Future use,1981-09,,,RESERVED,[16] -244/8,Future use,1981-09,,,RESERVED,[16] -245/8,Future use,1981-09,,,RESERVED,[16] -246/8,Future use,1981-09,,,RESERVED,[16] -247/8,Future use,1981-09,,,RESERVED,[16] -248/8,Future use,1981-09,,,RESERVED,[16] -249/8,Future use,1981-09,,,RESERVED,[16] -250/8,Future use,1981-09,,,RESERVED,[16] -251/8,Future use,1981-09,,,RESERVED,[16] -252/8,Future use,1981-09,,,RESERVED,[16] -253/8,Future use,1981-09,,,RESERVED,[16] -254/8,Future use,1981-09,,,RESERVED,[16] -255/8,Future use,1981-09,,,RESERVED,[16][17] 077/8,RIPE NCC,2006-08,whois.ripe.net,https://rdap.db.ripe.net/,ALLOCATED, 078/8,RIPE NCC,2006-08,whois.ripe.net,https://rdap.db.ripe.net/,ALLOCATED, 079/8,RIPE NCC,2006-08,whois.ripe.net,https://rdap.db.ripe.net/,ALLOCATED, @@ -369,3 +354,21 @@ http://rdap.arin.net/registry",ALLOCATED, 235/8,Multicast,1981-09,,,RESERVED,[13] 236/8,Multicast,1981-09,,,RESERVED,[13] 237/8,Multicast,1981-09,,,RESERVED,[13] +238/8,Multicast,1981-09,,,RESERVED,[13] +239/8,Multicast,1981-09,,,RESERVED,[13][15] +240/8,Future use,1981-09,,,RESERVED,[16] +241/8,Future use,1981-09,,,RESERVED,[16] +242/8,Future use,1981-09,,,RESERVED,[16] +243/8,Future use,1981-09,,,RESERVED,[16] +244/8,Future use,1981-09,,,RESERVED,[16] +245/8,Future use,1981-09,,,RESERVED,[16] +246/8,Future use,1981-09,,,RESERVED,[16] +247/8,Future use,1981-09,,,RESERVED,[16] +248/8,Future use,1981-09,,,RESERVED,[16] +249/8,Future use,1981-09,,,RESERVED,[16] +250/8,Future use,1981-09,,,RESERVED,[16] +251/8,Future use,1981-09,,,RESERVED,[16] +252/8,Future use,1981-09,,,RESERVED,[16] +253/8,Future use,1981-09,,,RESERVED,[16] +254/8,Future use,1981-09,,,RESERVED,[16] +255/8,Future use,1981-09,,,RESERVED,[16][17] diff --git a/src/Makefile.CygWin b/src/Makefile.CygWin index 2a596786..fff91f3a 100644 --- a/src/Makefile.CygWin +++ b/src/Makefile.CygWin @@ -59,7 +59,7 @@ EX_LIBS += -lole32 -ladvapi32 SOURCES = wsock_trace.c wsock_trace_lua.c hosts.c idna.c inet_util.c init.c \ common.c cpu.c dnsbl.c dump.c firewall.c geoip.c geoip-gen4.c geoip-gen6.c \ - in_addr.c ip2loc.c overlap.c smartlist.c stkwalk.c bfd_gcc.c + iana.c in_addr.c ip2loc.c overlap.c smartlist.c stkwalk.c bfd_gcc.c OBJECTS = $(addprefix $(OBJ_DIR)/, $(SOURCES:.c=.o) wsock_trace.res) NON_EXPORT_OBJ = $(OBJ_DIR)/non-export.o @@ -107,7 +107,7 @@ idna.exe: idna.c common.c smartlist.c $(WSOCK_TRACE_A) $(CC) -o $@ $(CFLAGS) $(LDFLAGS) -DTEST_IDNA $^ -lole32 > idna.map @echo -firewall_test.exe: common.c dnsbl.c firewall.c geoip.c geoip-gen4.c geoip-gen6.c idna.c in_addr.c inet_util.c init.c ip2loc.c smartlist.c +firewall_test.exe: common.c dnsbl.c firewall.c geoip.c geoip-gen4.c geoip-gen6.c iana.c idna.c in_addr.c inet_util.c init.c ip2loc.c smartlist.c $(CC) -o $@ $(CFLAGS) $(LDFLAGS) -DTEST_FIREWALL -DTEST_GEOIP $^ -lws2_32 -lole32 -ladvapi32 -lwinmm > firewall_test.map @echo diff --git a/src/Makefile.MingW b/src/Makefile.MingW index b45d14b1..7a346766 100644 --- a/src/Makefile.MingW +++ b/src/Makefile.MingW @@ -46,9 +46,9 @@ else X_SUFFIX = endif -CFLAGS = -Wall -m$(BITS) -DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0600 -Wno-unused-variable -Wno-unused-function -LDFLAGS = -m$(BITS) -Wl,--print-map,--sort-common -t -RCFLAGS = -O COFF -DDEBUG=$(USE_CRT_DEBUG) -D__MINGW32__ -DBITNESS=$(BITS) +CFLAGS = -Wall -m$(BITS) -DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0600 -Wno-unused-variable -Wno-unused-function +LDFLAGS = -m$(BITS) -Wl,--print-map,--sort-common -t +RCFLAGS += -O COFF -DDEBUG=$(USE_CRT_DEBUG) -D__MINGW32__ -DBITNESS=$(BITS) ifeq ($(USE_LUA),1) CFLAGS += -DUSE_LUA -I$(LUAJIT_ROOT)/src @@ -78,13 +78,13 @@ EX_LIBS += -lole32 -ladvapi32 SOURCES = wsock_trace.c wsock_trace_lua.c hosts.c idna.c inet_util.c init.c \ common.c cpu.c dnsbl.c dump.c geoip.c geoip-gen4.c geoip-gen6.c \ - overlap.c in_addr.c ip2loc.c smartlist.c stkwalk.c bfd_gcc.c \ + overlap.c iana.c in_addr.c ip2loc.c smartlist.c stkwalk.c bfd_gcc.c \ firewall.c OBJECTS = $(addprefix $(OBJ_DIR)/, $(SOURCES:.c=.o) wsock_trace.res) NON_EXPORT_OBJ = $(OBJ_DIR)/non-export.o -GEOIP_SRC = geoip.c common.c dnsbl.c idna.c inet_util.c init.c in_addr.c ip2loc.c smartlist.c +GEOIP_SRC = geoip.c common.c dnsbl.c iana.c idna.c inet_util.c init.c in_addr.c ip2loc.c smartlist.c GEOIP_OBJ = $(GEOIP_SRC:.c=.o) all: message $(OBJ_DIR) libwsock_trace.a geoip.exe test.exe idna.exe firewall_test.exe @@ -122,11 +122,15 @@ test.exe: $(OBJ_DIR)/test.o libwsock_trace.a $(CC) -o $@ $(LDFLAGS) $^ > test.map @echo +iana.exe: common.c dnsbl.c geoip.c geoip-null.c iana.c idna.c in_addr.c inet_util.c init.c smartlist.c + $(CC) -o $@ $(CFLAGS) $(LDFLAGS) -DTEST_IANA $^ -lws2_32 -lole32 -ladvapi32 > iana.map + @echo + idna.exe: idna.c common.c smartlist.c libwsock_trace.a $(CC) -o $@ $(CFLAGS) $(LDFLAGS) -DTEST_IDNA $^ -lole32 > idna.map @echo -firewall_test.exe: common.c dnsbl.c firewall.c geoip.c geoip-gen4.c geoip-gen6.c idna.c in_addr.c inet_util.c init.c ip2loc.c smartlist.c +firewall_test.exe: common.c dnsbl.c firewall.c geoip.c geoip-gen4.c geoip-gen6.c iana.c idna.c in_addr.c inet_util.c init.c ip2loc.c smartlist.c $(CC) -o $@ $(CFLAGS) $(LDFLAGS) -DTEST_FIREWALL -DTEST_GEOIP $^ -lws2_32 -lole32 -ladvapi32 -lwinmm > firewall_test.map @echo diff --git a/src/Makefile.Watcom b/src/Makefile.Watcom index 44ef72da..18927ed6 100644 --- a/src/Makefile.Watcom +++ b/src/Makefile.Watcom @@ -22,6 +22,7 @@ LINK_ARG = $(OBJ_DIR)\wlink.arg WSOCK_TRACE_OBJS = $(OBJ_DIR)\wsock_trace.obj & $(OBJ_DIR)\wsock_trace_lua.obj & $(OBJ_DIR)\hosts.obj & + $(OBJ_DIR)\iana.obj & $(OBJ_DIR)\idna.obj & $(OBJ_DIR)\init.obj & $(OBJ_DIR)\in_addr.obj & @@ -44,6 +45,7 @@ GEOIP_OBJ = $(OBJ_DIR)\geoip.obj & $(OBJ_DIR)\geoip-null.obj & $(OBJ_DIR)\common.obj & $(OBJ_DIR)\dnsbl.obj & + $(OBJ_DIR)\iana.obj & $(OBJ_DIR)\idna.obj & $(OBJ_DIR)\in_addr.obj & $(OBJ_DIR)\init.obj & @@ -84,6 +86,7 @@ vclean realclean: clean .SYMBOLIC $(WSOCK_DLL) $(WSOCK_LIB): $(WSOCK_TRACE_OBJS) $(OBJ_DIR)\wsock_trace.res $(NON_EXPORT_OBJ) $(LINK_ARG) wlink system nt dll name $(WSOCK_DLL) @$(LINK_ARG) wlib -q -b -c $(WSOCK_LIB) +-$(NON_EXPORT_OBJ) + @echo. $(OBJ_DIR)\wsock_trace.res: wsock_trace.rc wrc -dDEBUG=0 -D__WATCOMC__ -q -r -zm -fo=$@ $[@ @@ -112,14 +115,14 @@ geoip.exe: geoip.c init.c $(GEOIP_OBJ) *$(CC) $(CFLAGS) -DTEST_GEOIP -fo=$(OBJ_DIR)\init.obj init.c wlink $(LDFLAGS) name $@ file { $(GEOIP_OBJ) } & library clib3$(STACK_OR_REG).lib, ws2_32.lib - rm -f $(OBJ_DIR)\init.obj $(OBJ_DIR)\geoip.obj + rm -f $(OBJ_DIR)/init.obj $(OBJ_DIR)/geoip.obj @echo. idna.exe: idna.c $(OBJ_DIR)\getopt.obj $(OBJ_DIR)\common.obj $(OBJ_DIR)\smartlist.obj $(WSOCK_LIB) *$(CC) $(CFLAGS) -DTEST_IDNA -fo=$(OBJ_DIR)\idna.obj idna.c wlink $(LDFLAGS) name $@ file { $(OBJ_DIR)\idna.obj $(OBJ_DIR)\getopt.obj $(OBJ_DIR)\common.obj $(OBJ_DIR)\smartlist.obj } & library clib3$(STACK_OR_REG).lib,$(WSOCK_LIB) - rm -f $(OBJ_DIR)\idna.obj + rm -f $(OBJ_DIR)/idna.obj @echo. run_test: test.exe .SYMBOLIC @@ -130,6 +133,7 @@ $(LINK_ARG): $(__MAKEFILES__) @%append $^@ option implib=$(WSOCK_LIB), map, verbose, quiet, @%append $^@ caseexact, map=$(WSOCK_DLL:.dll=.map), res=$(OBJ_DIR)\wsock_trace.res @%append $^@ file { $(WSOCK_TRACE_OBJS) } library clib3$(STACK_OR_REG).lib + @echo. # @@ -144,6 +148,7 @@ $(OBJ_DIR)\hosts.obj: hosts.c common.h init.h smartlist.h in_addr.h hosts. $(OBJ_DIR)\geoip.obj: geoip.c common.h inet_util.h smartlist.h init.h in_addr.h geoip.h $(OBJ_DIR)\geoip-gen4.obj: geoip-gen4.c geoip.h common.h smartlist.h $(OBJ_DIR)\geoip-gen6.obj: geoip-gen6.c geoip.h common.h smartlist.h +$(OBJ_DIR)\iana.obj: iana.c common.h init.h inet_util.h in_addr.h smartlist.h iana.h $(OBJ_DIR)\idna.obj: idna.c common.h init.h smartlist.h idna.h $(OBJ_DIR)\inet_util.obj: inet_util.c inet_util.h common.h init.h in_addr.h wsock_defs.h $(OBJ_DIR)\init.obj: init.c common.h wsock_trace.h wsock_trace_lua.h & diff --git a/src/Makefile.vc6 b/src/Makefile.vc6 index 877ad330..51b15eb3 100644 --- a/src/Makefile.vc6 +++ b/src/Makefile.vc6 @@ -106,6 +106,7 @@ WSOCK_TRACE_OBJ = $(OBJ_DIR)\common.obj \ $(OBJ_DIR)\geoip.obj \ $(OBJ_DIR)\geoip-gen4.obj \ $(OBJ_DIR)\geoip-gen6.obj \ + $(OBJ_DIR)\iana.obj \ $(OBJ_DIR)\idna.obj \ $(OBJ_DIR)\ip2loc.obj \ $(OBJ_DIR)\inet_util.obj \ @@ -135,6 +136,7 @@ FIREWALL_TEST_OBJ = $(OBJ_DIR)\common.obj \ $(OBJ_DIR)\geoip-gen4.obj \ $(OBJ_DIR)\geoip-gen6.obj \ $(OBJ_DIR)\getopt.obj \ + $(OBJ_DIR)\iana.obj \ $(OBJ_DIR)\idna.obj \ $(OBJ_DIR)\in_addr.obj \ $(OBJ_DIR)\inet_util.obj \ @@ -152,7 +154,7 @@ IDNA_OBJ = $(OBJ_DIR)\idna_1.obj \ # # Source and .obj-files for 'geoip.exe'. # -GEOIP_SRC = geoip.c common.c dnsbl.c idna.c inet_util.c init.c in_addr.c ip2loc.c getopt.c smartlist.c +GEOIP_SRC = geoip.c common.c dnsbl.c iana.c idna.c inet_util.c init.c in_addr.c ip2loc.c getopt.c smartlist.c GEOIP_OBJ = $(GEOIP_SRC:.c=.obj) all: $(OBJ_DIR) compile_luajit_$(USE_LUA) $(WSOCK_TRACE_DLL) $(WSOCK_TRACE_LIB) geoip.exe test.exe idna.exe firewall_test.exe @@ -172,9 +174,9 @@ install: all copy wsock_trace$(X_SUFFIX).pdb "$(BIN_TARGET)" uninstall: - -del "$(LIB_TARGET)\$(WSOCK_TRACE_LIB)" - -del "$(BIN_TARGET)\$(WSOCK_TRACE_DLL)" - -del "$(BIN_TARGET)\wsock_trace$(X_SUFFIX).pdb" + - del "$(LIB_TARGET)\$(WSOCK_TRACE_LIB)" + - del "$(BIN_TARGET)\$(WSOCK_TRACE_DLL)" + - del "$(BIN_TARGET)\wsock_trace$(X_SUFFIX).pdb" geoip-gen4.c: geoip-null.exe @echo Generating $@. @@ -224,19 +226,19 @@ compile_luajit_1: copy lua51.lib lua51_static.lib ) clean: - -del link.tmp vc1*.pdb geoip-null.obj geoip-gen4.obj geoip-gen6.obj $(OBJ_DIR)\*.obj \ - $(OBJ_DIR)\wsock_trace.res test.map test.lib wsock_trace.appveyor + - del link.tmp vc1*.pdb geoip-null.obj geoip-gen4.obj geoip-gen6.obj $(OBJ_DIR)\*.obj \ + $(OBJ_DIR)\wsock_trace.res test.map test.lib wsock_trace.appveyor vclean realclean: clean - -del wsock_trace.lib wsock_trace.dll wsock_trace.map wsock_trace.pdb - -del wsock_trace_x64.lib wsock_trace_x64.dll wsock_trace_x64.map wsock_trace_x64.pdb - -del geoip.exe geoip.map geoip.pdb geoip-gen4.c geoip-gen6.c - -del geoip-null.exe geoip-null.map geoip-null.pdb - -del idna.exe idna.map idna.pdb test.exe test.pdb - -del firewall_test.exe firewall_test.map firewall_test.pdb - -rd $(OBJ_DIR) + - del wsock_trace.lib wsock_trace.dll wsock_trace.map wsock_trace.pdb + - del wsock_trace_x64.lib wsock_trace_x64.dll wsock_trace_x64.map wsock_trace_x64.pdb + - del geoip.exe geoip.map geoip.pdb geoip-gen4.c geoip-gen6.c + - del geoip-null.exe geoip-null.map geoip-null.pdb + - del idna.exe idna.map idna.pdb test.exe test.pdb + - del firewall_test.exe firewall_test.map firewall_test.pdb + - rd $(OBJ_DIR) !if "$(USE_LUA)" == "1" - -del $(LUAJIT_ROOT)\src\lua51*.lib + - del $(LUAJIT_ROOT)\src\lua51*.lib !endif help: diff --git a/src/Wsock-trace.vcxproj b/src/Wsock-trace.vcxproj index d5771569..93d40b14 100644 --- a/src/Wsock-trace.vcxproj +++ b/src/Wsock-trace.vcxproj @@ -105,6 +105,7 @@ + diff --git a/src/backtrace.c b/src/backtrace.c index f84b0db8..c0bc6a1b 100644 --- a/src/backtrace.c +++ b/src/backtrace.c @@ -543,6 +543,8 @@ DO_NOTHING (ip2loc_num_ipv6_entries) DO_NOTHING (hosts_file_exit) DO_NOTHING (DNSBL_exit) DO_NOTHING (DNSBL_test) +DO_NOTHING (iana_init) +DO_NOTHING (iana_exit) void DNSBL_init (BOOL update) { diff --git a/src/dump.c b/src/dump.c index 999a4faf..8729a172 100644 --- a/src/dump.c +++ b/src/dump.c @@ -15,6 +15,7 @@ #include "in_addr.h" #include "init.h" #include "geoip.h" +#include "iana.h" #include "idna.h" #include "hosts.h" #include "wsock_trace.h" @@ -2108,8 +2109,8 @@ void dump_countries (int type, const char **addresses) trace_puts (", "); } if (i == 0) - trace_puts ("None!?~0\n"); - else trace_puts ("~0\n"); + trace_puts ("None!?"); + trace_puts ("~0\n"); WSAERROR_POP(); } @@ -2191,12 +2192,114 @@ void dump_countries_addrinfo (const struct addrinfo *ai) trace_puts (", "); } if (num == 0) - trace_puts ("None!?~0\n"); - else trace_puts ("~0\n"); + trace_puts ("None!?"); + trace_puts ("~0\n"); WSAERROR_POP(); } +/* + * Dump the IANA information for the given addresses. + */ +void dump_IANA_addresses (int family, const char **addresses) +{ + int i; + + if (g_cfg.trace_level <= 0) + return; + + trace_indent (g_cfg.trace_indent+2); + trace_printf ("~4IANA: "); + + for (i = 0; addresses && addresses[i]; i++) + { + struct IANA_record rec; + + if (family == AF_INET) + { + iana_find_by_ip4_address ((const struct in_addr*)addresses[i], &rec); + iana_print_rec (&rec); + } + else if (family == AF_INET6) + { + iana_find_by_ip6_address ((const struct in6_addr*)addresses[i], &rec); + iana_print_rec (&rec); + } + else + { + trace_printf ("Unknown family: %d", family); + break; + } + } + if (i == 0) + trace_puts ("None!?"); + trace_puts ("~0\n"); +} + +void dump_IANA_sockaddr (const struct sockaddr *sa) +{ + const char *addr[2]; + const struct sockaddr_in *sa4; + const struct sockaddr_in6 *sa6; + + if (!sa || g_cfg.trace_level <= 0) + return; + + if (sa->sa_family == AF_INET) + { + sa4 = (const struct sockaddr_in*) sa; + addr[0] = (const char*) &sa4->sin_addr; + addr[1] = NULL; + dump_IANA_addresses (AF_INET, addr); + } + else if (sa->sa_family == AF_INET6) + { + sa6 = (const struct sockaddr_in6*) sa; + addr[0] = (const char*) &sa6->sin6_addr; + addr[1] = NULL; + dump_IANA_addresses (AF_INET6, addr); + } +} + +void dump_IANA_addrinfo (const struct addrinfo *ai) +{ + int num; + + if (g_cfg.trace_level <= 0) + return; + + trace_indent (g_cfg.trace_indent+2); + trace_printf ("~4IANA: "); + + for (num = 0; ai; ai = ai->ai_next, num++) + { + struct IANA_record rec; + + if (ai->ai_family == AF_INET) + { + const struct sockaddr_in *sa4 = (const struct sockaddr_in*) ai->ai_addr; + + iana_find_by_ip4_address (&sa4->sin_addr, &rec); + iana_print_rec (&rec); + } + else if (ai->ai_family == AF_INET6) + { + const struct sockaddr_in6 *sa6 = (const struct sockaddr_in6*) ai->ai_addr; + + iana_find_by_ip6_address (&sa6->sin6_addr, &rec); + iana_print_rec (&rec); + } + else + { + trace_printf ("Unknown family: %d", ai->ai_family); + break; + } + } + if (num == 0) + trace_puts ("None!?"); + trace_puts ("~0\n"); +} + void dump_nameinfo (const char *host, const char *serv, DWORD flags) { trace_indent (g_cfg.trace_indent+2); diff --git a/src/dump.h b/src/dump.h index a6d3fbff..61a8b39e 100644 --- a/src/dump.h +++ b/src/dump.h @@ -28,6 +28,10 @@ extern void dump_countries (int type, const char **addresses); extern void dump_countries_sockaddr (const struct sockaddr *sa); extern void dump_countries_addrinfo (const struct addrinfo *ai); +extern void dump_IANA_addresses (int type, const char **addresses); +extern void dump_IANA_sockaddr (const struct sockaddr *sa); +extern void dump_IANA_addrinfo (const struct addrinfo *ai); + extern void dump_DNSBL (int type, const char **addresses); extern void dump_DNSBL_sockaddr (const struct sockaddr *sa); extern void dump_DNSBL_addrinfo (const struct addrinfo *ai); diff --git a/src/init.c b/src/init.c index b87e461d..ad2f5cf1 100644 --- a/src/init.c +++ b/src/init.c @@ -28,6 +28,7 @@ #include "hosts.h" #include "firewall.h" #include "cpu.h" +#include "iana.h" #include "dnsbl.h" #include "in_addr.h" #include "init.h" @@ -118,11 +119,11 @@ static void set_time_format (TS_TYPE *ret, const char *val) { *ret = TS_NONE; - if (!stricmp(val,"absolute")) + if (!stricmp(val, "absolute")) *ret = TS_ABSOLUTE; - else if (!stricmp(val,"relative")) + else if (!stricmp(val, "relative")) *ret = TS_RELATIVE; - else if (!stricmp(val,"delta")) + else if (!stricmp(val, "delta")) *ret = TS_DELTA; TRACE (4, "val: %s -> TS_TYPE: %d\n", val, *ret); } @@ -296,7 +297,7 @@ static int config_get_line (FILE *fil, { char buf[500]; - if (!fgets(buf,sizeof(buf)-1,fil)) /* EOF */ + if (!fgets(buf, sizeof(buf)-1, fil)) /* EOF */ return (0); for (p = buf; *p && isspace((int)*p); ) @@ -314,7 +315,7 @@ static int config_get_line (FILE *fil, /* * Hit a '[section]' line. Let the caller switch to another config-table. */ - if (sscanf(p,"[%[^]\r\n]", section) == 1) + if (sscanf(p, "[%[^]\r\n]", section) == 1) { (*line)++; *section_p = section; @@ -322,7 +323,7 @@ static int config_get_line (FILE *fil, continue; } - if (sscanf(p,"%[^= ] = %[^\r\n]", key, val) != 2) + if (sscanf(p, "%[^= ] = %[^\r\n]", key, val) != 2) { (*line)++; continue; @@ -486,7 +487,7 @@ BOOL exclude_list_add (const char *name, unsigned exclude_which) tok_fmt = ","; } - for (tok = strtok(p,tok_fmt); tok; tok = strtok(NULL,tok_fmt)) + for (tok = strtok(p, tok_fmt); tok; tok = strtok(NULL, tok_fmt)) { if (exclude_which & EXCL_PROGRAM) while (*tok == ' ') @@ -558,166 +559,166 @@ const char *config_file_name (void) */ static void parse_core_settings (const char *key, const char *val, unsigned line) { - if (!stricmp(key,"trace_level")) + if (!stricmp(key, "trace_level")) g_cfg.trace_level = atoi (val); - else if (!stricmp(key,"trace_overlap")) + else if (!stricmp(key, "trace_overlap")) g_cfg.trace_overlap = atoi (val); - else if (!stricmp(key,"trace_file")) + else if (!stricmp(key, "trace_file")) g_cfg.trace_file = strdup (val); - else if (!stricmp(key,"trace_binmode")) + else if (!stricmp(key, "trace_binmode")) g_cfg.trace_binmode = atoi (val); - else if (!stricmp(key,"trace_caller")) + else if (!stricmp(key, "trace_caller")) g_cfg.trace_caller = atoi (val); - else if (!stricmp(key,"trace_indent")) + else if (!stricmp(key, "trace_indent")) { g_cfg.trace_indent = atoi (val); g_cfg.trace_indent = max (0, g_cfg.trace_indent); } - else if (!stricmp(key,"trace_report")) + else if (!stricmp(key, "trace_report")) g_cfg.trace_report = atoi (val); - else if (!stricmp(key,"trace_max_len") || !stricmp(key,"trace_max_length")) + else if (!stricmp(key, "trace_max_len") || !stricmp(key, "trace_max_length")) g_cfg.trace_max_len = atoi (val); - else if (!stricmp(key,"trace_time")) + else if (!stricmp(key, "trace_time")) set_time_format (&g_cfg.trace_time_format, val); - else if (!stricmp(key,"pcap_enable")) + else if (!stricmp(key, "pcap_enable")) g_cfg.pcap.enable = atoi (val); - else if (!stricmp(key,"pcap_dump")) + else if (!stricmp(key, "pcap_dump")) g_cfg.pcap.dump_fname = strdup (val); - else if (!stricmp(key,"show_caller")) + else if (!stricmp(key, "show_caller")) g_cfg.show_caller = atoi (val); - else if (!stricmp(key,"demangle") || !stricmp(key,"cpp_demangle")) + else if (!stricmp(key, "demangle") || !stricmp(key, "cpp_demangle")) g_cfg.cpp_demangle = atoi (val); - else if (!stricmp(key,"callee_level")) + else if (!stricmp(key, "callee_level")) g_cfg.callee_level = atoi (val); /* Control how many stack-frames to show. Not used yet */ - else if (!stricmp(key,"exclude")) + else if (!stricmp(key, "exclude")) exclude_list_add (val, EXCL_FUNCTION); - else if (!stricmp(key,"hook_extensions")) + else if (!stricmp(key, "hook_extensions")) g_cfg.hook_extensions = atoi (val); - else if (!stricmp(key,"short_errors")) + else if (!stricmp(key, "short_errors")) g_cfg.short_errors = atoi (val); - else if (!stricmp(key,"pdb_report")) + else if (!stricmp(key, "pdb_report")) g_cfg.pdb_report = atoi (val); - else if (!stricmp(key,"use_sema")) + else if (!stricmp(key, "use_sema")) g_cfg.use_sema = atoi (val); - else if (!stricmp(key,"recv_delay")) + else if (!stricmp(key, "recv_delay")) g_cfg.recv_delay = (DWORD) _atoi64 (val); - else if (!stricmp(key,"send_delay")) + else if (!stricmp(key, "send_delay")) g_cfg.send_delay = (DWORD) _atoi64 (val); - else if (!stricmp(key,"select_delay")) + else if (!stricmp(key, "select_delay")) g_cfg.select_delay = (DWORD) _atoi64 (val); - else if (!stricmp(key,"poll_delay")) + else if (!stricmp(key, "poll_delay")) g_cfg.poll_delay = (DWORD) _atoi64 (val); - else if (!stricmp(key,"use_toolhlp32")) + else if (!stricmp(key, "use_toolhlp32")) g_cfg.use_toolhlp32 = atoi (val); - else if (!stricmp(key,"use_ole32")) + else if (!stricmp(key, "use_ole32")) g_cfg.use_ole32 = atoi (val); - else if (!stricmp(key,"use_full_path")) + else if (!stricmp(key, "use_full_path")) g_cfg.use_full_path = atoi (val); - else if (!stricmp(key,"color_file")) + else if (!stricmp(key, "color_file")) get_color (val, &g_cfg.color_file); - else if (!stricmp(key,"color_time")) + else if (!stricmp(key, "color_time")) get_color (val, &g_cfg.color_time); - else if (!stricmp(key,"color_func")) + else if (!stricmp(key, "color_func")) get_color (val, &g_cfg.color_func); - else if (!stricmp(key,"color_trace")) + else if (!stricmp(key, "color_trace")) get_color (val, &g_cfg.color_trace); - else if (!stricmp(key,"color_data")) + else if (!stricmp(key, "color_data")) get_color (val, &g_cfg.color_data); - else if (!stricmp(key,"compact")) + else if (!stricmp(key, "compact")) g_cfg.compact = atoi (val); - else if (!stricmp(key,"dump_select")) + else if (!stricmp(key, "dump_select")) g_cfg.dump_select = atoi (val); - else if (!stricmp(key,"dump_nameinfo")) + else if (!stricmp(key, "dump_nameinfo")) g_cfg.dump_nameinfo = atoi (val); - else if (!stricmp(key,"dump_protoent")) + else if (!stricmp(key, "dump_protoent")) g_cfg.dump_protoent = atoi (val); - else if (!stricmp(key,"dump_modules")) + else if (!stricmp(key, "dump_modules")) g_cfg.dump_modules = atoi (val); - else if (!stricmp(key,"dump_hostent")) + else if (!stricmp(key, "dump_hostent")) g_cfg.dump_hostent = atoi (val); - else if (!stricmp(key,"dump_servent")) + else if (!stricmp(key, "dump_servent")) g_cfg.dump_servent = atoi (val); - else if (!stricmp(key,"dump_data")) + else if (!stricmp(key, "dump_data")) g_cfg.dump_data = atoi (val); - else if (!stricmp(key,"dump_wsaprotocol_info")) + else if (!stricmp(key, "dump_wsaprotocol_info")) g_cfg.dump_wsaprotocol_info = atoi (val); - else if (!stricmp(key,"dump_wsanetwork_events")) + else if (!stricmp(key, "dump_wsanetwork_events")) g_cfg.dump_wsanetwork_events = atoi (val); - else if (!stricmp(key,"max_data")) + else if (!stricmp(key, "max_data")) g_cfg.max_data = atoi (val); - else if (!stricmp(key,"max_fd_set") || !stricmp(key,"max_fd_sets")) + else if (!stricmp(key, "max_fd_set") || !stricmp(key, "max_fd_sets")) g_cfg.max_fd_sets = atoi (val); - else if (!stricmp(key,"max_displacement")) + else if (!stricmp(key, "max_displacement")) g_cfg.max_displacement = atoi (val); - else if (!stricmp(key,"start_new_line")) + else if (!stricmp(key, "start_new_line")) g_cfg.start_new_line = atoi (val); - else if (!stricmp(key,"test_trace")) + else if (!stricmp(key, "test_trace")) g_cfg.test_trace = atoi (val); - else if (!stricmp(key,"msvc_only")) + else if (!stricmp(key, "msvc_only")) g_cfg.msvc_only = atoi (val); - else if (!stricmp(key,"mingw_only")) + else if (!stricmp(key, "mingw_only")) g_cfg.mingw_only = atoi (val); - else if (!stricmp(key,"cygwin_only")) + else if (!stricmp(key, "cygwin_only")) g_cfg.cygwin_only = atoi (val); - else if (!stricmp(key,"no_buffering")) + else if (!stricmp(key, "no_buffering")) g_cfg.no_buffering = atoi (val); - else if (!stricmp(key,"hosts_file")) + else if (!stricmp(key, "hosts_file")) g_cfg.hosts_file = strdup (val); - else if (!stricmp(key,"use_winhttp")) + else if (!stricmp(key, "use_winhttp")) g_cfg.use_winhttp = atoi (val); - else TRACE (0, "%s (%u):\n Unknown keyword '%s' = '%s'\n", + else TRACE (1, "%s (%u):\n Unknown keyword '%s' = '%s'\n", fname, line, key, val); } @@ -726,28 +727,28 @@ static void parse_core_settings (const char *key, const char *val, unsigned line */ static void parse_lua_settings (const char *key, const char *val, unsigned line) { - if (!stricmp(key,"enable")) + if (!stricmp(key, "enable")) g_cfg.lua.enable = atoi (val); - else if (!stricmp(key,"trace_level")) + else if (!stricmp(key, "trace_level")) g_cfg.lua.trace_level = atoi (val); - else if (!stricmp(key,"profile")) + else if (!stricmp(key, "profile")) g_cfg.lua.profile = atoi (val); - else if (!stricmp(key,"color_head")) + else if (!stricmp(key, "color_head")) get_color (val, &g_cfg.lua.color_head); - else if (!stricmp(key,"color_body")) + else if (!stricmp(key, "color_body")) get_color (val, &g_cfg.lua.color_body); - else if (!stricmp(key,"lua_init")) + else if (!stricmp(key, "lua_init")) g_cfg.lua.init_script = strdup (val); - else if (!stricmp(key,"lua_exit")) + else if (!stricmp(key, "lua_exit")) g_cfg.lua.exit_script = strdup (val); - else TRACE (0, "%s (%u):\n Unknown keyword '%s' = '%s'\n", + else TRACE (1, "%s (%u):\n Unknown keyword '%s' = '%s'\n", fname, line, key, val); } @@ -756,31 +757,31 @@ static void parse_lua_settings (const char *key, const char *val, unsigned line) */ static void parse_geoip_settings (const char *key, const char *val, unsigned line) { - if (!stricmp(key,"enable")) - g_cfg.geoip_enable = (*val > '0') ? 1 : 0; + if (!stricmp(key, "enable")) + g_cfg.geoip_enable = (*val > '0') ? TRUE : FALSE; - else if (!stricmp(key,"use_generated")) + else if (!stricmp(key, "use_generated")) g_cfg.geoip_use_generated = atoi (val); - else if (!stricmp(key,"geoip4_file")) + else if (!stricmp(key, "geoip4_file")) g_cfg.geoip4_file = strdup (val); - else if (!stricmp(key,"geoip6_file")) + else if (!stricmp(key, "geoip6_file")) g_cfg.geoip6_file = strdup (val); - else if (!stricmp(key,"geoip4_url")) + else if (!stricmp(key, "geoip4_url")) g_cfg.geoip4_url = strdup (val); - else if (!stricmp(key,"geoip6_url")) + else if (!stricmp(key, "geoip6_url")) g_cfg.geoip6_url = strdup (val); - else if (!stricmp(key,"proxy")) + else if (!stricmp(key, "proxy")) g_cfg.geoip_proxy = strdup (val); - else if (!stricmp(key,"max_days")) + else if (!stricmp(key, "max_days")) g_cfg.geoip_max_days = atoi (val); - else if (!stricmp(key,"ip2location_bin_file")) + else if (!stricmp(key, "ip2location_bin_file")) { if (g_cfg.ip2location_bin_file) { @@ -790,7 +791,7 @@ static void parse_geoip_settings (const char *key, const char *val, unsigned lin g_cfg.ip2location_bin_file = strdup (val); } - else TRACE (0, "%s (%u):\n Unknown keyword '%s' = '%s'\n", + else TRACE (1, "%s (%u):\n Unknown keyword '%s' = '%s'\n", fname, line, key, val); } @@ -799,16 +800,16 @@ static void parse_geoip_settings (const char *key, const char *val, unsigned lin */ static void parse_idna_settings (const char *key, const char *val, unsigned line) { - if (!stricmp(key,"enable")) + if (!stricmp(key, "enable")) g_cfg.idna_enable = atoi (val); - else if (!stricmp(key,"winidn")) + else if (!stricmp(key, "winidn")) g_cfg.idna_winidn = atoi (val); - else if (!stricmp(key,"codepage")) + else if (!stricmp(key, "codepage")) g_cfg.idna_cp = atoi (val); - else TRACE (0, "%s (%u):\n Unknown keyword '%s' = '%s'\n", + else TRACE (1, "%s (%u):\n Unknown keyword '%s' = '%s'\n", fname, line, key, val); } @@ -817,34 +818,34 @@ static void parse_idna_settings (const char *key, const char *val, unsigned line */ static void parse_DNSBL_settings (const char *key, const char *val, unsigned line) { - if (!stricmp(key,"enable")) + if (!stricmp(key, "enable")) g_cfg.DNSBL.enable = atoi (val); - else if (!stricmp(key,"test")) + else if (!stricmp(key, "test")) g_cfg.DNSBL.test = atoi (val); - else if (!stricmp(key,"drop_file")) + else if (!stricmp(key, "drop_file")) g_cfg.DNSBL.drop_file = strdup (val); - else if (!stricmp(key,"dropv6_file")) + else if (!stricmp(key, "dropv6_file")) g_cfg.DNSBL.dropv6_file = strdup (val); - else if (!stricmp(key,"edrop_file")) + else if (!stricmp(key, "edrop_file")) g_cfg.DNSBL.edrop_file = strdup (val); - else if (!stricmp(key,"drop_url")) + else if (!stricmp(key, "drop_url")) g_cfg.DNSBL.drop_url = strdup (val); - else if (!stricmp(key,"dropv6_url")) + else if (!stricmp(key, "dropv6_url")) g_cfg.DNSBL.dropv6_url = strdup (val); - else if (!stricmp(key,"edrop_url")) + else if (!stricmp(key, "edrop_url")) g_cfg.DNSBL.edrop_url = strdup (val); - else if (!stricmp(key,"max_days")) + else if (!stricmp(key, "max_days")) g_cfg.DNSBL.max_days = atoi (val); - else TRACE (0, "%s (%u):\n Unknown keyword '%s' = '%s'\n", + else TRACE (1, "%s (%u):\n Unknown keyword '%s' = '%s'\n", fname, line, key, val); } @@ -874,40 +875,58 @@ static void get_freq_msec (const char *val, struct FREQ_MILLISEC *out) */ static void parse_firewall_settings (const char *key, const char *val, unsigned line) { - if (!stricmp(key,"enable")) + if (!stricmp(key, "enable")) g_cfg.firewall.enable = atoi (val); - else if (!stricmp(key,"show_ipv4")) + else if (!stricmp(key, "show_ipv4")) g_cfg.firewall.show_ipv4 = atoi (val); - else if (!stricmp(key,"show_ipv6")) + else if (!stricmp(key, "show_ipv6")) g_cfg.firewall.show_ipv6 = atoi (val); - else if (!stricmp(key,"show_all")) + else if (!stricmp(key, "show_all")) g_cfg.firewall.show_all = atoi (val); - else if (!stricmp(key,"api_level")) + else if (!stricmp(key, "api_level")) g_cfg.firewall.api_level = atoi (val); - else if (!stricmp(key,"console_title")) + else if (!stricmp(key, "console_title")) g_cfg.firewall.console_title = atoi (val); - else if (!stricmp(key,"exclude")) + else if (!stricmp(key, "exclude")) exclude_list_add (val, EXCL_PROGRAM | EXCL_ADDRESS); - else if (!stricmp(key,"sound.enable")) + else if (!stricmp(key, "sound.enable")) g_cfg.firewall.sound.enable = atoi (val); - else if (!stricmp(key,"sound.beep.event_drop")) + else if (!stricmp(key, "sound.beep.event_drop")) get_freq_msec (val, &g_cfg.firewall.sound.beep.event_drop); - else if (!stricmp(key,"sound.beep.event_allow")) + else if (!stricmp(key, "sound.beep.event_allow")) get_freq_msec (val, &g_cfg.firewall.sound.beep.event_allow); - else if (!stricmp(key,"sound.beep.event_DNSBL")) + else if (!stricmp(key, "sound.beep.event_DNSBL")) get_freq_msec (val, &g_cfg.firewall.sound.beep.event_DNSBL); - else TRACE (0, "%s (%u):\n Unknown keyword '%s' = '%s'\n", + else TRACE (1, "%s (%u):\n Unknown keyword '%s' = '%s'\n", + fname, line, key, val); +} + +/* + * Handler for '[IANA]' section. + */ +static void parse_iana_settings (const char *key, const char *val, unsigned line) +{ + if (!stricmp(key, "enable")) + g_cfg.IANA.enable = atoi (val); + + else if (!stricmp(key, "ip4_file")) + g_cfg.IANA.ip4_file = strdup (val); + + else if (!stricmp(key, "ip6_file")) + g_cfg.IANA.ip6_file = strdup (val); + + else TRACE (1, "%s (%u):\n Unknown keyword '%s' = '%s'\n", fname, line, key, val); } @@ -916,6 +935,7 @@ enum cfg_sections { CFG_CORE, CFG_LUA, CFG_GEOIP, + CFG_IANA, CFG_IDNA, CFG_DNSBL, CFG_FIREWALL @@ -926,17 +946,19 @@ enum cfg_sections { */ static enum cfg_sections lookup_section (const char *section) { - if (!section || !stricmp(section,"core")) + if (!section || !stricmp(section, "core")) return (CFG_CORE); - if (section && !stricmp(section,"lua")) + if (section && !stricmp(section, "lua")) return (CFG_LUA); - if (section && !stricmp(section,"geoip")) + if (section && !stricmp(section, "geoip")) return (CFG_GEOIP); - if (section && !stricmp(section,"idna")) + if (section && !stricmp(section, "iana")) + return (CFG_IANA); + if (section && !stricmp(section, "idna")) return (CFG_IDNA); - if (section && !stricmp(section,"dnsbl")) + if (section && !stricmp(section, "dnsbl")) return (CFG_DNSBL); - if (section && !stricmp(section,"firewall")) + if (section && !stricmp(section, "firewall")) return (CFG_FIREWALL); return (CFG_NONE); } @@ -997,6 +1019,10 @@ static int parse_config_file (FILE *file) parse_firewall_settings (key, val, line); strcpy (last_section, "firewall"); break; + case CFG_IANA: + parse_iana_settings (key, val, line); + strcpy (last_section, "iana"); + break; /* \todo: handle more 'key' / 'val' here by extending lookup_section(). */ @@ -1014,7 +1040,7 @@ static int parse_config_file (FILE *file) return (lines); } -#if !defined(TEST_GEOIP) && !defined(TEST_BACKTRACE) && !defined(TEST_NLM) +#if !defined(TEST_IANA) && !defined(TEST_GEOIP) && !defined(TEST_BACKTRACE) && !defined(TEST_NLM) static void trace_report (void) { const struct exclude *ex; @@ -1119,10 +1145,13 @@ static void trace_report (void) DWORD_CAST(ip2loc_index_errors())); } + if (g_cfg.IANA.enable) + iana_report(); + if (g_cfg.firewall.enable) fw_report(); } -#endif /* !TEST_GEOIP && !TEST_BACKTRACE && !TEST_NLM */ +#endif /* !TEST_IANA && !TEST_GEOIP && !TEST_BACKTRACE && !TEST_NLM */ /* * Called from DllMain(): dwReason == DLL_PROCESS_DETACH @@ -1134,7 +1163,7 @@ void wsock_trace_exit (void) if (fatal_error) g_cfg.trace_report = FALSE; -#if !defined(TEST_GEOIP) && !defined(TEST_BACKTRACE) && !defined(TEST_NLM) +#if !defined(TEST_IANA) && !defined(TEST_GEOIP) && !defined(TEST_BACKTRACE) && !defined(TEST_NLM) #if 0 if (!cleaned_up || startup_count > 0) @@ -1165,7 +1194,7 @@ void wsock_trace_exit (void) fw_monitor_stop (TRUE); fw_exit(); } -#endif /* !TEST_GEOIP && !TEST_BACKTRACE && !TEST_NLM */ +#endif /* !TEST_IANA && !TEST_GEOIP && !TEST_BACKTRACE && !TEST_NLM */ common_exit(); @@ -1195,6 +1224,7 @@ void wsock_trace_exit (void) DNSBL_exit(); geoip_exit(); + iana_exit(); IDNA_exit(); if (ws_sema) @@ -1353,7 +1383,8 @@ void wsock_trace_init (void) if (g_cfg.trace_level > 0 && (g_cfg.trace_use_ods || (!g_cfg.trace_file_device && g_cfg.trace_file_okay))) trace_printf ("\n------- Trace started at %s --------" - "------ %s, %s. Build-date: %s.\n", now, get_builder(), get_dll_short_name(), get_dll_build_date()); + "------ %s, %s. Build-date: %s.\n", + now, get_builder(), get_dll_short_name(), get_dll_build_date()); memset (&console_info, 0, sizeof(console_info)); @@ -1452,7 +1483,7 @@ void wsock_trace_init (void) geoip_init (NULL, NULL); -#if defined(TEST_GEOIP) || defined(TEST_NLM) +#if defined(TEST_IANA) || defined(TEST_GEOIP) || defined(TEST_NLM) DNSBL_init (TRUE); #else @@ -1472,6 +1503,7 @@ void wsock_trace_init (void) StackWalkInit(); overlap_init(); + iana_init(); #if defined(USE_LWIP) ws_lwip_init(); @@ -1479,10 +1511,10 @@ void wsock_trace_init (void) if (g_cfg.DNSBL.test) DNSBL_test(); -#endif /* TEST_GEOIP || TEST_NLM */ +#endif /* TEST_IANA || TEST_GEOIP || TEST_NLM */ } -#if !defined(TEST_GEOIP) && !defined(TEST_BACKTRACE) && !defined(TEST_NLM) +#if !defined(TEST_IANA) && !defined(TEST_GEOIP) && !defined(TEST_BACKTRACE) && !defined(TEST_NLM) /* * Used as e.g. 'INIT_PTR (p_WSAStartup)' which expands to @@ -1508,7 +1540,7 @@ void init_ptr (const void **ptr, const char *ptr_name) if (cleaned_up) TRACE (1, "Function '%s()' called after 'WSACleanup()' was done.\n", func_name); } -#endif /* !TEST_GEOIP && !TEST_BACKTRACE && !TEST_NLM */ +#endif /* !TEST_IANA && !TEST_GEOIP && !TEST_BACKTRACE && !TEST_NLM */ static const struct search_list colors[] = { { 0, "black" }, @@ -1734,7 +1766,7 @@ struct tcp_header { }; /* - * Udp protocol header. + * UDP protocol header. * Per RFC 768, September, 1981. */ struct udp_header { @@ -1839,7 +1871,7 @@ static void _gettimeofday (struct pcap_timeval *tv) FILETIME ft; uint64 tim; -#if !defined(TEST_GEOIP) && !defined(TEST_BACKTRACE) && !defined(TEST_NLM) +#if !defined(TEST_IANA) && !defined(TEST_GEOIP) && !defined(TEST_BACKTRACE) && !defined(TEST_NLM) if (p_GetSystemTimePreciseAsFileTime) (*p_GetSystemTimePreciseAsFileTime) (&ft); else diff --git a/src/init.h b/src/init.h index 1aa3a966..3e7deded 100644 --- a/src/init.h +++ b/src/init.h @@ -63,6 +63,12 @@ struct DNSBL_cfg { int max_days; }; +struct IANA_cfg { + BOOL enable; + char *ip4_file; + char *ip6_file; + }; + typedef struct FREQ_MILLISEC { unsigned frequency; unsigned milli_sec; @@ -164,6 +170,7 @@ struct config_table { struct lua_cfg lua; struct pcap_cfg pcap; struct DNSBL_cfg DNSBL; + struct IANA_cfg IANA; struct firewall_cfg firewall; struct statistics counts; DWORD reentries; diff --git a/src/wsock_trace.c b/src/wsock_trace.c index 74fe24fd..6bc8a8cf 100644 --- a/src/wsock_trace.c +++ b/src/wsock_trace.c @@ -1310,6 +1310,10 @@ EXPORT SOCKET WINAPI WSAAccept (SOCKET s, struct sockaddr *addr, int *addr_len, { if (g_cfg.geoip_enable) dump_countries_sockaddr (addr); + + if (g_cfg.IANA.enable) + dump_IANA_sockaddr (addr); + if (g_cfg.DNSBL.enable) dump_DNSBL_sockaddr (addr); } @@ -1359,6 +1363,10 @@ EXPORT SOCKET WINAPI accept (SOCKET s, struct sockaddr *addr, int *addr_len) { if (g_cfg.geoip_enable) dump_countries_sockaddr (addr); + + if (g_cfg.IANA.enable) + dump_IANA_sockaddr (addr); + if (g_cfg.DNSBL.enable) dump_DNSBL_sockaddr (addr); } @@ -1391,6 +1399,10 @@ EXPORT int WINAPI bind (SOCKET s, const struct sockaddr *addr, int addr_len) { if (g_cfg.geoip_enable) dump_countries_sockaddr (addr); + + if (g_cfg.IANA.enable) + dump_IANA_sockaddr (addr); + if (g_cfg.DNSBL.enable) dump_DNSBL_sockaddr (addr); } @@ -1437,6 +1449,10 @@ EXPORT int WINAPI connect (SOCKET s, const struct sockaddr *addr, int addr_len) { if (g_cfg.geoip_enable) dump_countries_sockaddr (addr); + + if (g_cfg.IANA.enable) + dump_IANA_sockaddr (addr); + if (g_cfg.DNSBL.enable) dump_DNSBL_sockaddr (addr); } @@ -1696,6 +1712,10 @@ EXPORT int WINAPI recvfrom (SOCKET s, char *buf, int buf_len, int flags, struct if (g_cfg.geoip_enable) dump_countries_sockaddr (from); + + if (g_cfg.IANA.enable) + dump_IANA_sockaddr (from); + if (g_cfg.DNSBL.enable) dump_DNSBL_sockaddr (from); } @@ -2092,6 +2112,9 @@ EXPORT int WINAPI WSASendTo (SOCKET s, WSABUF *bufs, DWORD num_bufs, DWORD *num_ if (g_cfg.geoip_enable) dump_countries_sockaddr (to); + if (g_cfg.IANA.enable) + dump_IANA_sockaddr (to); + if (g_cfg.DNSBL.enable) dump_DNSBL_sockaddr (to); @@ -2552,6 +2575,10 @@ EXPORT struct hostent *WINAPI gethostbyname (const char *name) { if (g_cfg.geoip_enable) dump_countries (rc->h_addrtype, (const char**)rc->h_addr_list); + + if (g_cfg.IANA.enable) + dump_IANA_addresses (rc->h_addrtype, (const char**)rc->h_addr_list); + if (g_cfg.DNSBL.enable) dump_DNSBL (rc->h_addrtype, (const char**)rc->h_addr_list); } @@ -2597,6 +2624,19 @@ EXPORT struct hostent *WINAPI gethostbyaddr (const char *addr, int len, int type dump_countries (type, a); } } + if (g_cfg.IANA.enable) + { + if (rc) + dump_IANA_addresses (rc->h_addrtype, (const char**)rc->h_addr_list); + else + { + const char *a[2]; + + a[0] = addr; + a[1] = NULL; + dump_IANA_addresses (type, a); + } + } if (g_cfg.DNSBL.enable) { if (rc) @@ -2715,6 +2755,10 @@ EXPORT int WINAPI getpeername (SOCKET s, struct sockaddr *name, int *name_len) { if (g_cfg.geoip_enable) dump_countries_sockaddr (name); + + if (g_cfg.IANA.enable) + dump_IANA_sockaddr (name); + if (g_cfg.DNSBL.enable) dump_DNSBL_sockaddr (name); } @@ -2739,6 +2783,10 @@ EXPORT int WINAPI getsockname (SOCKET s, struct sockaddr *name, int *name_len) { if (g_cfg.geoip_enable) dump_countries_sockaddr (name); + + if (g_cfg.IANA.enable) + dump_IANA_sockaddr (name); + if (g_cfg.DNSBL.enable) dump_DNSBL_sockaddr (name); } @@ -2805,6 +2853,9 @@ EXPORT int WINAPI getnameinfo (const struct sockaddr *sa, socklen_t sa_len, if (g_cfg.geoip_enable) dump_countries_sockaddr (sa); + if (g_cfg.IANA.enable) + dump_IANA_sockaddr (sa); + if (g_cfg.DNSBL.enable) dump_DNSBL_sockaddr (sa); } @@ -2854,6 +2905,9 @@ EXPORT int WINAPI getaddrinfo (const char *host_name, const char *serv_name, if (g_cfg.geoip_enable) dump_countries_addrinfo (*res); + if (g_cfg.IANA.enable) + dump_IANA_addrinfo (*res); + if (g_cfg.DNSBL.enable) dump_DNSBL_addrinfo (*res); } diff --git a/wsock_trace b/wsock_trace index d843a464..d2d805c0 100644 --- a/wsock_trace +++ b/wsock_trace @@ -183,6 +183,19 @@ # ip2location_bin_file = %APPDATA%\IP2LOCATION-LITE-DB11.IPV6.BIN +# +# IANA settings. +# +[iana] + enable = 1 # Show IANA info for addresses in traced functions + ip4_file = %APPDATA%\ipv4-address-space.csv # The IANA 'IPv4 Address Space Registry' .csv file + ip6_file = %APPDATA%\ipv6-unicast-address-assignments.csv # The IANA 'IPv6 Global Unicast Address Assignments' .csv file (TODO) + + # + # Note: there are no 'ip4_url' and 'ip6_url' for the above files + # (similar to 'DNSBL::drop_url') since the above files gets updated very seldom. + # + # # IDNA settings. Internationalizing Domain Names in Applications. #