summaryrefslogtreecommitdiff
path: root/ebus-racket/dumper.rkt
blob: 7ffd556d65e8eff871be88025a2a7297d98c1bb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#! /usr/bin/env racket
#lang racket/base
(require racket/cmdline
         racket/tcp
	 racket/pretty
         "layer2.rkt"
	 "layer7.rkt")

;(define verbose? (make-parameter #f))
(define connect-host? (make-parameter null))
(define connect-port? (make-parameter null))
(define layer7? (make-parameter #f))

(define greeting
  (command-line
   #:once-each
   [("-a" "--layer7")
    "Parse Layer7" (layer7? #t)]
   [("-c" "--connect") 
    host port
    "Connect to server <host> <port>"
    (connect-host? host)
    (connect-port? (string->number port))
    ]))

; Connect
(if (or (null? (connect-host?)) (null? (connect-port?)))
    (display "Using stdin\n")
    (let-values ([(cin cout) (tcp-connect (connect-host?) (connect-port?))])
      (display (format "Connected to ~s ~s ~n" (connect-host?) (connect-port?)))
      (current-input-port cin)))

(define (read-ebus-loop2 input-port)
  (let ([paket (layer2-read-ebus (current-input-port))])
    (pretty-print paket)
    (cond ((not (eof-object? paket)) (read-ebus-loop2 input-port)))))

(define (read-ebus-loop7 input-port)
  (let ([fields (layer7-read-ebus (current-input-port))])
    (if (not (void? fields))
	(pretty-print fields)
	(display ""))
    (cond ((not (eof-object? fields)) (read-ebus-loop7 input-port)))))

(if (layer7?)
    (let ()
      (display "Layer 7\n")
      (read-ebus-loop7 (current-input-port)))
    (let ()
      (display "Layer 2\n")
      (read-ebus-loop2 (current-input-port))))