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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
|
# `sockaddr(1)`
`sockaddr` is a CLI utility that wraps and exposes `go-sockaddr` functionality
from the command line.
```text
$ go get -u github.com/hashicorp/go-sockaddr/cmd/sockaddr
```
```text
% sockaddr -h
usage: sockaddr [--version] [--help] <command> [<args>]
Available commands are:
dump Parses IP addresses
eval Evaluates a sockaddr template
rfc Test to see if an IP is part of a known RFC
version Prints the sockaddr version
```
## `sockaddr dump`
```text
Usage: sockaddr dump [options] input [...]
Parse address(es) or interface and dumps various output.
Options:
-4 Parse the input as IPv4 only
-6 Parse the input as IPv6 only
-H Machine readable output
-I Parse the argument as an interface name
-i Parse the input as IP address (either IPv4 or IPv6)
-n Show only the value
-o Name of an attribute to pass through
-u Parse the input as a UNIX Socket only
```
### `sockaddr dump` example output
By default it prints out all available information unless the `-o` flag is
specified.
```text
% sockaddr dump 127.0.0.2/8
Attribute Value
type IPv4
string 127.0.0.2/8
host 127.0.0.2
address 127.0.0.2
port 0
netmask 255.0.0.0
network 127.0.0.0/8
mask_bits 8
binary 01111111000000000000000000000010
hex 7f000002
first_usable 127.0.0.1
last_usable 127.255.255.254
octets 127 0 0 2
size 16777216
broadcast 127.255.255.255
uint32 2130706434
DialPacket "udp4" ""
DialStream "tcp4" ""
ListenPacket "udp4" ""
ListenStream "tcp4" ""
$ sockaddr dump -H -o host,address,port -o mask_bits 127.0.0.3:8600
host 127.0.0.3:8600
address 127.0.0.3
port 8600
mask_bits 32
$ sockaddr dump -H -n -o host,address,port -o mask_bits 127.0.0.3:8600
127.0.0.3:8600
127.0.0.3
8600
32
$ sockaddr dump -o type,address,hex,network '[2001:db8::3/32]'
Attribute Value
type IPv6
address 2001:db8::3
network 2001:db8::/32
hex 20010db8000000000000000000000003
$ sockaddr dump /tmp/example.sock
Attribute Value
type UNIX
string "/tmp/example.sock"
path /tmp/example.sock
DialPacket "unixgram" "/tmp/example.sock"
DialStream "unix" "/tmp/example.sock"
ListenPacket "unixgram" "/tmp/example.sock"
ListenStream "unix" "/tmp/example.sock"
```
## `sockaddr eval`
```text
Usage: sockaddr eval [options] [template ...]
Parse the sockaddr template and evaluates the output.
The `sockaddr` library has the potential to be very complex,
which is why the `sockaddr` command supports an `eval`
subcommand in order to test configurations from the command
line. The `eval` subcommand automatically wraps its input
with the `{{` and `}}` template delimiters unless the `-r`
command is specified, in which case `eval` parses the raw
input. If the `template` argument passed to `eval` is a
dash (`-`), then `sockaddr eval` will read from stdin and
automatically sets the `-r` flag.
Options:
-d Debug output
-n Suppress newlines between args
-r Suppress wrapping the input with {{ }} delimiters
```
Here are a few impractical examples to get you started:
```text
$ sockaddr eval 'GetAllInterfaces | include "flags" "forwardable" | include "up" | sort "default,type,size" | include "RFC" "6890" | attr "address"'
172.14.6.167
$ sockaddr eval 'GetDefaultInterfaces | sort "type,size" | include "RFC" "6890" | limit 1 | join "address" " "'
172.14.6.167
$ sockaddr eval 'GetPublicIP'
203.0.113.4
$ sockaddr eval 'GetPrivateIP'
172.14.6.167
$ sockaddr eval 'GetInterfaceIP "eth0"'
172.14.6.167
$ sockaddr eval 'GetAllInterfaces | include "network" "172.14.6.0/24" | attr "address"'
172.14.6.167
$ sockaddr eval 'GetPrivateInterfaces | join "type" " "'
IPv4 IPv6
$ sockaddr eval 'GetAllInterfaces | include "flags" "forwardable" | join "address" " "'
203.0.113.4 2001:0DB8::1
$ sockaddr eval 'GetAllInterfaces | include "name" "lo0" | include "type" "IPv6" | sort "address" | join "address" " "'
100:: fe80::1
$ sockaddr eval '. | include "rfc" "1918" | print | len | lt 2'
true
$ sockaddr eval -r '{{with $ifSet := include "name" "lo0" . }}{{ range include "type" "IPv6" $ifSet | sort "address" | reverse}}{{ . }} {{end}}{{end}}'
fe80::1/64 {1 16384 lo0 up|loopback|multicast} 100:: {1 16384 lo0 up|loopback|multicast}
$ sockaddr eval '. | include "name" "lo0" | include "type" "IPv6" | sort "address" | join "address" " "'
100:: fe80::1
$ cat <<'EOF' | sockaddr eval -
{{. | include "name" "lo0" | include "type" "IPv6" | sort "address" | join "address" " "}}
EOF
100:: fe80::1
$ sockaddr eval 'GetPrivateInterfaces | include "flags" "forwardable|up" | include "type" "IPv4" | math "network" "+2" | attr "address"'
172.14.6.2
$ cat <<'EOF' | sudo tee -a /etc/profile
export CONSUL_HTTP_ADDR="http://`sockaddr eval 'GetInterfaceIP \"eth0\"'`:8500"
EOF
```
## `sockaddr rfc`
```text
$ sockaddr rfc
Usage: sockaddr rfc [RFC Number] [IP Address]
Tests a given IP address to see if it is part of a known
RFC. If the IP address belongs to a known RFC, return exit
code 0 and print the status. If the IP does not belong to
an RFC, return 1. If the RFC is not known, return 2.
Options:
-s Silent, only return different exit codes
$ sockaddr rfc 1918 192.168.1.10
192.168.1.10 is part of RFC 1918
$ sockaddr rfc 6890 '[::1]'
100:: is part of RFC 6890
$ sockaddr rfc list
919
1112
1122
1918
2544
2765
2928
3056
3068
3171
3330
3849
3927
4038
4193
4291
4380
4773
4843
5180
5735
5737
6052
6333
6598
6666
6890
7335
```
## `sockaddr tech-support`
If one of the helper methods that derives its output from `GetDefaultInterfaces`
is misbehaving, submit the output from this command as an issue along with
any miscellaneous details that are specific to your environment.
```text
Usage: sockaddr tech-support [options]
Print out network diagnostic information that can be used by
support.
The `sockaddr` library relies on OS-specific commands and
output which can potentially be brittle. The `tech-support`
subcommand emits all of the platform-specific network
details required to debug why a given `sockaddr` API call is
behaving differently than expected. The `-output` flag
controls the output format. The default output mode is
Markdown (`md`) however a raw mode (`raw`) is available to
obtain the original output.
Options:
-output Encode the output using one of Markdown ("md") or Raw ("raw")
```
## `sockaddr version`
The lowly version stub.
```text
$ sockaddr version
sockaddr 0.1.0-dev
```
|