1BEGIN { 2 lines = 5 3 fail = 0 4 5 r_i = "[1-9][0-9]*" 6 r_port = "[1-9][0-9][0-9][0-9]+" 7 r_localhost = "127\\.0\\.0\\.1" 8 r_connect = "^connect\\(0<TCP:\\[" r_i "\\]>, \\{sa_family=AF_INET, sin_port=htons\\((" r_port ")\\), sin_addr=inet_addr\\(\"" r_localhost "\"\\)\\}, " r_i ") += 0$" 9} 10 11NR == 1 && /^socket\(PF_INET, SOCK_STREAM, IPPROTO_IP\) += 0$/ {next} 12 13NR == 2 { 14 if (match($0, r_connect, a)) { 15 port_r = a[1] 16 r_send = "^send\\(0<TCP:\\[" r_localhost ":(" r_port ")->" r_localhost ":" port_r "\\]>, \"data\", 4, MSG_DONTROUTE\\) += 4$" 17 r_sendto = "^sendto\\(0<TCP:\\[" r_localhost ":(" r_port ")->" r_localhost ":" port_r "\\]>, \"data\", 4, MSG_DONTROUTE, NULL, 0\\) += 4$" 18 next 19 } 20} 21 22NR == 3 { 23 if (r_send != "" && (match($0, r_send, a) || match($0, r_sendto, a))) { 24 port_l = a[1] 25 r_close = "^close\\(0<TCP:\\[" r_localhost ":" port_l "->" r_localhost ":" port_r "\\]>\\) += 0$" 26 next 27 } 28} 29 30NR == 4 {if (r_close != "" && match($0, r_close)) next} 31 32NR == lines && $0 == "+++ exited with 0 +++" {next} 33 34{ 35 print "Line " NR " does not match: " $0 36 fail=1 37} 38 39END { 40 if (NR != lines) { 41 print "Expected " lines " lines, found " NR " line(s)." 42 print "" 43 exit 1 44 } 45 if (fail) { 46 print "" 47 exit 1 48 } 49} 50