From 2d7378dbc090eaf3b659de785a5b5669cddbe05e Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Mon, 16 Jan 2017 11:56:13 +0300 Subject: [PATCH] nncp-pkt can decompress the data --- doc/cmds.texi | 6 ++++-- doc/news.texi | 1 + src/cypherpunks.ru/nncp/cmd/nncp-pkt/main.go | 21 +++++++++++++++----- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/doc/cmds.texi b/doc/cmds.texi index 1061cc2..54348c8 100644 --- a/doc/cmds.texi +++ b/doc/cmds.texi @@ -185,7 +185,7 @@ operating system. @verbatim % nncp-pkt [options] < pkt -% nncp-pkt [options] -dump < pkt > payload +% nncp-pkt [options] [-decompress] -dump < pkt > payload @end verbatim Low level packet parser. Normally it should not be used, but can help in @@ -215,7 +215,9 @@ Path: stargrave@stargrave.org @end verbatim And with the @option{-dump} option it will give you the actual payload -(the whole file, mail message, and so on). +(the whole file, mail message, and so on). @option{-decompress} option +tries to zlib-decompress the data from plain packet (useful for mail +packets). @node nncp-stat @section nncp-stat diff --git a/doc/news.texi b/doc/news.texi index 405cd15..d72250f 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -18,4 +18,5 @@ could be used to keep connection alive for a long time. @item @option{-maxonlinetime} option gives ability to set maximal allowable online connection alive time. @item @ref{nncp-caller} command appeared: cron-ed TCP daemon caller. +@item @ref{nncp-pkt} command can decompress the data. @end itemize diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-pkt/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-pkt/main.go index 535c7d2..82bcffb 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-pkt/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-pkt/main.go @@ -22,6 +22,7 @@ package main import ( "bufio" "bytes" + "compress/zlib" "flag" "fmt" "io" @@ -44,10 +45,11 @@ func usage() { func main() { var ( - dump = flag.Bool("dump", false, "Write decrypted/parsed payload to stdout") - cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") - version = flag.Bool("version", false, "Print version information") - warranty = flag.Bool("warranty", false, "Print warranty information") + dump = flag.Bool("dump", false, "Write decrypted/parsed payload to stdout") + decompress = flag.Bool("decompress", false, "Try to zlib decompress dumped data") + cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") + version = flag.Bool("version", false, "Print version information") + warranty = flag.Bool("warranty", false, "Print warranty information") ) flag.Usage = usage flag.Parse() @@ -70,7 +72,16 @@ func main() { if err == nil && pkt.Magic == nncp.MagicNNCPPv1 { if *dump { bufW := bufio.NewWriter(os.Stdout) - if _, err = io.Copy(bufW, bufio.NewReader(os.Stdin)); err != nil { + var r io.Reader + r = bufio.NewReader(os.Stdin) + if *decompress { + decompressor, err := zlib.NewReader(r) + if err != nil { + log.Fatalln(err) + } + r = decompressor + } + if _, err = io.Copy(bufW, r); err != nil { log.Fatalln(err) } if err = bufW.Flush(); err != nil { -- 2.44.0