FAQ
Hello. I am trying to create ClamAV lib in golang, but dont understand how
to send in valid way data:

Here JAVA code:
https://github.com/jenkinsci/clamav-plugin/blob/master/src/main/java/org/jenkinsci/plugins/clamav/scanner/ClamAvScanner.java#L147-L192

Doc about Command (from here http://www.clamav.net/doc/latest/clamdoc.pdf,
16 page):

INSTREAM
It is mandatory to prefix this command with n or z.
Scan a stream of data. The stream is sent to clamd in chunks, after
INSTREAM,
on the same socket on which the command was sent. This avoids the overhead
of establishing new TCP connections and problems with NAT. The format of the
chunk is: <length><data> where <length> is the size of the following data in
bytes expressed as a 4 byte unsigned integer in network byte order and
<data> is
the actual chunk. Streaming is terminated by sending a zero-length chunk.
Note:
do not exceed StreamMaxLength as defined in clamd.conf, otherwise clamd will
reply with INSTREAM size limit exceeded and close the connection.

But my code doesn't work:

package main

import (


   stdlog "log"


   "os"
   "net"
   "bufio"
   "io"
   "strconv"
   "encoding/binary"


)

func main() {
   ip := net.ParseIP("127.0.0.1")
   addr := &net.TCPAddr{
     IP: ip,
     Port: 3310,
   }
   conn, err := net.DialTCP("tcp", nil, addr)
   if err != nil {
     log.Errorf("%v", err)
     return
   }
   _, err = conn.Write([]byte("zINSTREAM"))
   if err != nil {
     log.Errorf("%v", err)
     return
   }

   str := "$CEliacmaTrESTuScikgsn$FREE-TEST-SIGNATURE$EEEEE$"
   strBytes := []byte(strconv.Itoa(len(str)) + str)

   _, err = conn.Write(strBytes)
   if err != nil {
     log.Errorf("Write first: %v", err)
     return
   }

   _, err = conn.Write([]byte(strconv.Itoa(0))
   if err != nil {
     log.Errorf("%v", err)
     return
   }

   reader := bufio.NewReader(conn)
   // reading
   for {
     line, err := reader.ReadString('\n')
     if err == io.EOF {
       conn.Close()
       break
     }
     if err != nil {
       conn.Close()
       return
     }
   }

}

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Bogdan Radacina at Jun 14, 2013 at 2:55 am
    The documentation you posted says: "where <length> is the size of the
    following data in
    bytes expressed as a 4 byte unsigned integer in network byte order"

    And you're outputting:
    strconv.Itoa(len(str)) which transforms 23 into "23"

    I think "encoding/binary" package might help you ( I never used it, so I
    don't have experience with it )

    Also len(str) might not be the correct length because if your string
    contains characters that are 2 (or more) bytes long you're under counting
    the length of the resulting byte slice

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • John Beisley at Jun 15, 2013 at 4:47 pm
    len(str) is consistent with len([]byte(str)):

    http://play.golang.org/p/G5S4BwWx8l

    On 13 June 2013 19:55, wrote:

    The documentation you posted says: "where <length> is the size of the
    following data in
    bytes expressed as a 4 byte unsigned integer in network byte order"

    And you're outputting:
    strconv.Itoa(len(str)) which transforms 23 into "23"

    I think "encoding/binary" package might help you ( I never used it, so I
    don't have experience with it )

    Also len(str) might not be the correct length because if your string
    contains characters that are 2 (or more) bytes long you're under counting
    the length of the resulting byte slice

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Bogdan Radacina at Jun 16, 2013 at 10:21 pm
    Ah I didn't remembered that that was the case. Thanks John.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJun 14, '13 at 12:15a
activeJun 16, '13 at 10:21p
posts4
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase