summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2022-01-03 13:32:05 +0100
committerDaniel Stenberg <daniel@haxx.se>2022-01-03 22:32:05 +0100
commit61cbb4b626af761a58f15d81899bfee7ed5e8944 (patch)
tree6ddbfa6047679d252b5ead649ba851effb3e5cec
parenteffd2bd7ba2a5fd24487bddbaa1f7803c59f935d (diff)
downloadcurl-61cbb4b626af761a58f15d81899bfee7ed5e8944.tar.gz
server/socksd: log atyp + address in a separate log
To allow the test suite to verify that the right data arrived
-rw-r--r--tests/server/socksd.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/server/socksd.c b/tests/server/socksd.c
index 869d86506..6867141e3 100644
--- a/tests/server/socksd.c
+++ b/tests/server/socksd.c
@@ -101,6 +101,10 @@
#define DEFAULT_LOGFILE "log/socksd.log"
#endif
+#ifndef DEFAULT_REQFILE
+#define DEFAULT_REQFILE "log/socksd-request.log"
+#endif
+
#ifndef DEFAULT_CONFIG
#define DEFAULT_CONFIG "socksd.config"
#endif
@@ -136,6 +140,7 @@ struct configurable {
static struct configurable config;
const char *serverlogfile = DEFAULT_LOGFILE;
+const char *reqlogfile = DEFAULT_REQFILE;
static const char *configfile = DEFAULT_CONFIG;
#ifdef ENABLE_IPV6
@@ -515,6 +520,35 @@ static curl_socket_t sockit(curl_socket_t fd)
}
logmsg("Received ATYP %d", type);
+ {
+ FILE *dump;
+ dump = fopen(reqlogfile, "ab");
+ if(dump) {
+ int i;
+ fprintf(dump, "atyp %u =>", type);
+ switch(type) {
+ case 1:
+ /* 4 bytes IPv4 address */
+ fprintf(dump, " %u.%u.%u.%u\n",
+ address[0], address[1], address[2], address[3]);
+ break;
+ case 3:
+ /* The first octet of the address field contains the number of octets
+ of name that follow */
+ fprintf(dump, " %.*s\n", len-1, &address[1]);
+ break;
+ case 4:
+ /* 16 bytes IPv6 address */
+ for(i = 0; i < 16; i++) {
+ fprintf(dump, " %02x", address[i]);
+ }
+ fprintf(dump, "\n");
+ break;
+ }
+ fclose(dump);
+ }
+ }
+
if(!config.port) {
unsigned char *portp = &buffer[SOCKS5_DSTADDR + len];
s5port = (unsigned short)((portp[0]<<8) | (portp[1]));
@@ -931,6 +965,11 @@ int main(int argc, char *argv[])
if(argc>arg)
serverlogfile = argv[arg++];
}
+ else if(!strcmp("--reqfile", argv[arg])) {
+ arg++;
+ if(argc>arg)
+ reqlogfile = argv[arg++];
+ }
else if(!strcmp("--ipv6", argv[arg])) {
#ifdef ENABLE_IPV6
ipv_inuse = "IPv6";
@@ -964,6 +1003,7 @@ int main(int argc, char *argv[])
" --logfile [file]\n"
" --pidfile [file]\n"
" --portfile [file]\n"
+ " --reqfile [file]\n"
" --ipv4\n"
" --ipv6\n"
" --bindonly\n"