dtuy84033 2014-12-29 09:31
浏览 68
已采纳

找不到函数Marshal()

I am writing small code for generating the ICMP packet. For that I am following the code from golang net package.

I identified the following code to use for ICMP packet generation:

   109          c, err := Dial(tt.net, tt.raddr)
   110          if err != nil {
   111              t.Fatalf("Dial failed: %v", err)
   112          }
   113          c.SetDeadline(time.Now().Add(100 * time.Millisecond))
   114          defer c.Close()
   115  
   116          typ := icmpv4EchoRequest
   117          if net == "ip6" {
   118              typ = icmpv6EchoRequest
   119          }
   120          xid, xseq := os.Getpid()&0xffff, i+1
   121          wb, err := (&icmpMessage{
   122              Type: typ, Code: 0,
   123              Body: &icmpEcho{
   124                  ID: xid, Seq: xseq,
   125                  Data: bytes.Repeat([]byte("Go Go Gadget Ping!!!"), 3),
   126              },
   127          }).Marshal()
   128          if err != nil {
   129              t.Fatalf("icmpMessage.Marshal failed: %v", err)
   130          }
   131          if _, err := c.Write(wb); err != nil {
   132              t.Fatalf("Conn.Write failed: %v", err)
   133          }

I am not able to understand followings in this code :

  1. Marshal() is not included in the net package documentation, please let me know how to find this function and why it is not included in the net package.

  2. please explain me line #121 (icmpMessage struct and function calling as these are not defined in this file).

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘