コード例 #1
0
ファイル: pcap2json.go プロジェクト: jonsen/pcap2json
// Attempt to extract an HTTP request from the packet and serialise with the
// provided encoder.
func SerialisePacket(pkt *pcap.Packet, enc *json.Encoder) {
	// TODO: serialise packet details for non-HTTP packets

	// TODO: naively assumes requests are contained in a single packet and
	// HTTP verbs are not otherwise contained in a request

	// rfc 2616
	httpMethods := [...]string{"OPTIONS", "GET", "HEAD", "POST", "PUT", "DELETE", "TRACE", "CONNECT"}

	// TODO: IPv6
	if hdr, ok := pkt.Headers[0].(*pcap.Iphdr); ok {
		if tcpHdr, ok := pkt.Headers[1].(*pcap.Tcphdr); ok {
			// TODO: Consider peeking at other ports
			if tcpHdr.DestPort == 80 {
				pktString := PacketAsString(pkt)
				for _, verb := range httpMethods {
					if strings.Contains(pktString, verb) {
						unparsedReqs := strings.Split(pktString, verb)
						for _, unparsed := range unparsedReqs {
							req, err := http.ReadRequest(bufio.NewReader(strings.NewReader(verb + unparsed)))
							// TODO: serialise details of packets we fail to parse
							if err == nil {
								rp := RequestPacket{hdr.SrcAddr(), hdr.DestAddr(), tcpHdr.SrcPort, tcpHdr.DestPort, pkt.TimeString(), tcpHdr.FlagsString(), req}
								enc.Encode(rp)
							}
						}
					}
				}
			}
			out.Flush()
		}
	}

}
コード例 #2
0
ファイル: audience.go プロジェクト: juilyoon/Orchestra
func sendQueueFailureResponse(reason string, enc *json.Encoder) {
	resp := make([]interface{}, 2)
	resperr := new(string)
	*resperr = "Error"
	resp[0] = resperr
	if reason != "" {
		resp[1] = &reason
	}
	err := enc.Encode(resp)
	if nil != err {
		o.Warn("Couldn't encode response to audience: %s", err)
	}
}
コード例 #3
0
ファイル: audience.go プロジェクト: juilyoon/Orchestra
func sendQueueSuccessResponse(job *o.JobRequest, enc *json.Encoder) {
	resp := make([]interface{}, 2)
	resperr := new(string)
	*resperr = "OK"
	resp[0] = resperr

	// this probably looks odd, but all numbers cross through float64 when being json encoded.  d'oh!
	jobid := new(uint64)
	*jobid = uint64(job.Id)
	resp[1] = jobid

	err := enc.Encode(resp)
	if nil != err {
		o.Warn("Couldn't encode response to audience: %s", err)
	}
}