chiark / gitweb /
Bugfixes
[vinegar-ip.git] / make-probes.tcl
index f41cae14986de7e989ba3904875a74c8c585f83e..6a033ff5aff84ff77a36367bb8f3593520a62c66 100755 (executable)
@@ -33,6 +33,10 @@ proc packet-csum-ip {packet} {
     return [expr {$cs & 0xffff}]
 }
 
+proc packet-fromstring {s} {
+    binary scan $s H* y
+    return $y
+}
 
 namespace eval Random-Bytes {
     namespace export random-bytes random-bytes-init
@@ -52,7 +56,7 @@ namespace eval Random-Bytes {
            set h $fh; unset fh; close $h
            error "openssl bf-ofb exited unexpectedly"
        }
-       binary scan $x H* y
+       set y [packet-fromstring $x]
        if {[string length $y] != $n*2} { error "binary format failed $n $y" }
        return $y
     }
@@ -191,6 +195,12 @@ proc get/number {s v min max} {
     return $rv
 }
 
+proc get/hex {s v min max} {
+    set rv [choice-int $min $max]
+    getlog [format %s=0x%x $v $rv]
+    return $rv
+}
+
 proc get/flag {s v defprob} {
     set rv [choice-prob $s-$v $defprob]
     if {$rv} { getlog "$v" } else { getlog "!$v" }
@@ -244,7 +254,7 @@ proc get/string {s v minlen maxlen first rest} {
        set now $rest
     }
     getlog "$v=\"$o\""
-    return $o
+    return [packet-fromstring $o]
 }
 
 
@@ -401,8 +411,8 @@ proc gen_1_ip {mtu} {
     upvar #0 ip_dest dest
     get-for ip
     set version 4
-    get tos number 0x00 0xff
-    get id number 0x0000 0xffff
+    get tos hex 0x00 0xff
+    get id hex 0x0000 0xffff
     get df flag 0.5
     if {$df} {
        set mf 0
@@ -508,8 +518,8 @@ define icmp-type 0 pong {mbl} { icmp-echo $mbl }
 proc icmp-echo {mbl} {
     get-for icmp-echo
     get code enum 0 255 0.4
-    get id number 0 0xffff
-    get seq number 0 0xffff
+    get id hex 0 0xffff
+    get seq hex 0 0xffff
     assemble body {
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |       Id                      |        Seq                    |
@@ -526,8 +536,8 @@ define icmp-type 14 timestampreply {mbl} { icmp-timestamp }
 proc icmp-timestamp {} {
     get-for icmp-timestamp
     get code enum 0 255 0.4
-    get id number 0 0xffff
-    get seq number 0 0xffff
+    get id hex 0 0xffff
+    get seq hex 0 0xffff
     get originate ip-timestamp
     get receive ip-timestamp
     get transmit ip-timestamp
@@ -551,8 +561,8 @@ define icmp-type 16 inforeply {mbl} { icmp-inforeq }
 proc icmp-inforeq {} {
     get-for icmp-inforeq
     get code enum 0 255 0.4
-    get id number 0 0xffff
-    get seq number 0 0xffff
+    get id hex 0 0xffff
+    get seq hex 0 0xffff
     assemble body {
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |           Id                  |        Seq                    |
@@ -618,7 +628,7 @@ define ip-proto 17 udp {mtu} {
        set csum [packet-csum-ip $udp]
        if {!$csum} { set csum 0xffff }
        if {"$checksum" == "bad"} {
-           get error number 1 0xffff
+           get error hex 1 0xffff
            set csum [expr {$csum ^ $error}]
        }
     } else {
@@ -656,11 +666,11 @@ define udp-port 50 remailck {mtu style} {
            get user rand 0 [expr {$mtu - 4}]
        }
        req-auth {
-           get auth enum 0 31
-           set user [depending-on auth {$mtu - 4}]
+           get auth enum 0 31 0.5
+           set user [depending-on remailck auth $mtu -4]
        }
        resp-auth {
-           get auth number 0 0xffff
+           get auth hex 0 0xffff
            set modified 0
            set read 0
        }
@@ -718,6 +728,15 @@ define udp-port 50 remailck {mtu style} {
     return $packet
 }
 
+define remailck-auth 31 passwd {mtu} {
+    get-for remailck-passwd
+    get passwd string 6 8 \
+           0123456789abcdefghijklmnopqrstuvxwyz \
+           0123456789abcdefghijklmnopqrstuvxwyz
+    return $passwd
+}
+
+
 proc emit {count} {
     global getlog_log errorInfo
     if {[catch {