You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							69 lines
						
					
					
						
							1.9 KiB
						
					
					
				
			
		
		
	
	
							69 lines
						
					
					
						
							1.9 KiB
						
					
					
				package describer
 | 
						|
 | 
						|
import (
 | 
						|
    "encoding/hex"
 | 
						|
    "eruhs/core/parser"
 | 
						|
    "fmt"
 | 
						|
)
 | 
						|
 | 
						|
type TCPDescriber struct {
 | 
						|
    TCP *parser.TCP
 | 
						|
}
 | 
						|
 | 
						|
func (t *TCPDescriber) GetHeader() []byte {
 | 
						|
    return t.TCP.Header
 | 
						|
}
 | 
						|
 | 
						|
func (t *TCPDescriber) GetDetailDescribe() Describe {
 | 
						|
    tcpFlags := make([]string, 0)
 | 
						|
    if t.TCP.NS {
 | 
						|
        tcpFlags = append(tcpFlags, "NS")
 | 
						|
    }
 | 
						|
    if t.TCP.CWR {
 | 
						|
        tcpFlags = append(tcpFlags, "CWR")
 | 
						|
    }
 | 
						|
    if t.TCP.ECE {
 | 
						|
        tcpFlags = append(tcpFlags, "ECE")
 | 
						|
    }
 | 
						|
    if t.TCP.URG {
 | 
						|
        tcpFlags = append(tcpFlags, "URG")
 | 
						|
    }
 | 
						|
    if t.TCP.ACK {
 | 
						|
        tcpFlags = append(tcpFlags, "ACK")
 | 
						|
    }
 | 
						|
    if t.TCP.PSH {
 | 
						|
        tcpFlags = append(tcpFlags, "PSH")
 | 
						|
    }
 | 
						|
    if t.TCP.RST {
 | 
						|
        tcpFlags = append(tcpFlags, "RST")
 | 
						|
    }
 | 
						|
    if t.TCP.SYN {
 | 
						|
        tcpFlags = append(tcpFlags, "SYN")
 | 
						|
    }
 | 
						|
    if t.TCP.FIN {
 | 
						|
        tcpFlags = append(tcpFlags, "FIN")
 | 
						|
    }
 | 
						|
 | 
						|
    optionDescribe := make([]map[string]string, 0)
 | 
						|
    for _, option := range t.TCP.Options {
 | 
						|
        optionDescribe = append(optionDescribe, map[string]string{
 | 
						|
            "类型": fmt.Sprintf("%d", option.OptionType),
 | 
						|
            "长度": fmt.Sprintf("%d", option.OptionLength),
 | 
						|
            "数据": hex.EncodeToString(option.OptionData),
 | 
						|
        })
 | 
						|
    }
 | 
						|
 | 
						|
    return Describe{
 | 
						|
        1:  {"源端口号", fmt.Sprintf("%d", t.TCP.SrcPort)},
 | 
						|
        2:  {"目的端口号", fmt.Sprintf("%d", t.TCP.DstPort)},
 | 
						|
        3:  {"序列号", fmt.Sprintf("%d", t.TCP.Seq)},
 | 
						|
        4:  {"确认号", fmt.Sprintf("%d", t.TCP.Ack)},
 | 
						|
        5:  {"数据偏移", fmt.Sprintf("%d", t.TCP.DataOffset)},
 | 
						|
        6:  {"标志符", fmt.Sprintf("%v", tcpFlags)},
 | 
						|
        7:  {"窗口", fmt.Sprintf("%d", t.TCP.Window)},
 | 
						|
        8:  {"校验和", fmt.Sprintf("%d", t.TCP.Checksum)},
 | 
						|
        9:  {"紧急指针", fmt.Sprintf("%d", t.TCP.Urgent)},
 | 
						|
        10: {"可选字段", fmt.Sprintf("%+v", optionDescribe)},
 | 
						|
        11: {"填充", fmt.Sprintf("%d", len(t.TCP.Padding))},
 | 
						|
    }
 | 
						|
}
 | 
						|
 |