Hello all, this is probably a very newbie question, as I'm very rusty and just getting back into some coding. I'm including some background so that my question has context.
Background:I'm working my way through
Network Programming with Go by Jan Newmarch and, among various issues with the code examples, ran into some confusion in 3.11 code example
Ping where the variable
addr is passed to
net.DialIP twice, as both
laddr and
raddr.
addr, err := net.ResolveIPAddr("ip4", os.Args[1])
...
conn, err := net.DialIP("ip4:icmp", addr, addr)
I imagine it will come as no surprise to at least some of you that when using this code to dial localhost it works just fine, but trying to dial
any other host results in errors (
Cannot assign requested address). Since I didn't (and still don't) understand what
laddr is doing I tried setting it to a resolved localhost, which gave me an "
invalid parameter" error. Based on the documentation for
DialTCP I tried
nil, which works just fine and makes it possible to ping anywhere I like (within reason). So...
The question:
What, in the functions
net.DialIP, net.DialTCP, and
net.DialUDP, does the
laddr parameter do? I know it's short for "local address", but what is the meaning of "local"? Is it an alias for the
raddr, or is it supposed to be the IP address of the NIC? Is it something else entirely?
Thank you