Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/interplane-forge/blob/main/infra/test/netprobe.om # interplane-forge INTERPLANE Forge Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `interplane-forge / infra / test / netprobe.om` 186 lines ยท 3450 bytes Raw Blame History 1 om2 2 note netprobe (test-only, sandbox gate). Runs inside the sandbox in place of forged. 3 note netprobe TARGET ... TARGET is A.B.C.D:PORT (TCP) or @NAME (abstract unix stream socket). 4 note For each target it tries one connect (nonblocking, at most 2 s) and prints 5 note "TARGET connected" or "TARGET refused errno E". It sends nothing. Then it prints the 6 note interface names from /proc/net/dev. Exit 0: no target connected. 1: at least one did. 7 note 2: usage error. 8 note Linux ARM64: SOCK_STREAM|SOCK_NONBLOCK|SOCK_CLOEXEC = 526337; EINPROGRESS 115, EISCONN 106; 9 note POLLOUT 4. A second connect after the socket turns writable gives 0 or EISCONN when the 10 note connection was made, otherwise the error of the attempt. 11 global arg uchar 256 12 global sa uchar 128 13 global num uchar 32 14 global dev uchar 8192 15 text tok " connected\n" 16 text tno " refused errno " 17 text tbad " unparsable\n" 18 text tnl "\n" 19 text tdev "/proc/net/dev" 20 text tif "interface " 21 fn putdec v ulong to void 22 x = v 23 i = ulong 32 24 while gt i 0 bound 32 25 i = sub i 1 26 put num i add uchar rem x 10 48 27 x = div x 10 28 if eq x 0 29 break 30 end 31 end 32 k = write 1 num i sub 32 i 33 end 34 fn tcpaddr n ulong to ulong 35 note arg[0..n) as A.B.C.D:PORT into sa (sockaddr_in, 16 bytes); returns 16, or 0 if malformed. 36 for i ulong 16 37 put sa i 0 38 end 39 put sa 0 2 40 pt = ulong 0 41 v = ulong 0 42 d = ulong 0 43 for i ulong n bound 256 44 c = get arg i 45 if and ge c 48 le c 57 46 v = add mul v 10 ulong sub c 48 47 d = add d 1 48 if or gt v 65535 gt d 5 49 ret 0 50 end 51 else 52 if or eq d 0 gt v 255 53 ret 0 54 end 55 if eq c 46 56 if ge pt 3 57 ret 0 58 end 59 put sa add 4 pt uchar v 60 else 61 if or ne c 58 ne pt 3 62 ret 0 63 end 64 put sa 7 uchar v 65 end 66 pt = add pt 1 67 v = ulong 0 68 d = ulong 0 69 end 70 end 71 if or ne pt 4 eq d 0 72 ret 0 73 end 74 put sa 2 uchar shr v 8 75 put sa 3 uchar and v 255 76 ret 16 77 end 78 fn unixaddr n ulong to ulong 79 note arg[0..n) as @NAME into sa (sockaddr_un, abstract: family 1, a zero byte, NAME). 80 if or lt n 2 gt n 100 81 ret 0 82 end 83 put sa 0 1 84 put sa 1 0 85 put sa 2 0 86 for i ulong sub n 1 bound 100 87 put sa add i 3 get arg add i 1 88 end 89 ret add n 2 90 end 91 fn try fam int al ulong to long 92 fd = socknew fam 526337 0 93 if lt fd 0 94 ret fd 95 end 96 r = connect int fd sa 0 al 97 if eq r -115 98 w = waitio int fd 4 `2000000000` 99 r = connect int fd sa 0 al 100 if eq r -106 101 r = long 0 102 end 103 if eq w 0 104 r = long -110 105 end 106 end 107 c = fclose int fd 108 ret r 109 end 110 fn prname s ulong e ulong to void 111 note Print "interface NAME" for dev[s..e), leading spaces skipped. 112 if ge s e 113 ret 114 end 115 p = s 116 while lt p e bound 8192 117 if ne get dev p 32 118 break 119 end 120 p = add p 1 121 end 122 k = write 1 tif 0 len tif 123 k = write 1 dev p sub e p 124 k = write 1 tnl 0 len tnl 125 end 126 fn devs to void 127 note Print the interface names: the text before ':' on each line after the two header lines. 128 fd = fopen tdev 0 len tdev 524288 0 129 if lt fd 0 130 ret 131 end 132 n = read int fd dev 0 len dev 133 c = fclose int fd 134 if le n 0 135 ret 136 end 137 line = ulong 0 138 s = ulong 0 139 for i ulong ulong n bound 8192 140 b = get dev i 141 if eq b 10 142 line = add line 1 143 s = add i 1 144 end 145 if and eq b 58 ge line 2 146 prname s i 147 s = ulong n 148 end 149 end 150 end 151 fn main to int 152 if lt argcnt 2 153 ret 2 154 end 155 hit = int 0 156 for t ulong ulong sub argcnt 1 bound 64 157 n = argread add t 1 arg 0 len arg 158 if le n 0 159 ret 2 160 end 161 fam = int 2 162 al = ulong 0 163 if eq get arg 0 64 164 fam = int 1 165 al = unixaddr ulong n 166 else 167 al = tcpaddr ulong n 168 end 169 k = write 1 arg 0 ulong n 170 if eq al 0 171 k = write 1 tbad 0 len tbad 172 ret 2 173 end 174 r = try fam al 175 if eq r 0 176 k = write 1 tok 0 len tok 177 hit = int 1 178 else 179 k = write 1 tno 0 len tno 180 putdec ulong neg r 181 k = write 1 tnl 0 len tnl 182 end 183 end 184 devs 185 ret hit 186 end