<p>I would guess addrlocal shows you your endpoint of the connection, that is your IP address and port number. For all incoming connections that would be the same as the IP address and port you are listening on, so that's why it's not displayed. In your case most likely: 137.122.81.217:8333</p>

<p>I'm not sure what would happen if the server is multihomed.</p>

CC BY-SA 3.0
2016-01-06T10:58:09.383Z
Why my port number is 58318 (randomnly chosen) and NOT 18333? I am still connected via the testnet right?
Guhan S
CC BY-SA 3.0
2016-01-06T14:14:28.280Z
Because it's an outgoing connection and that's how TCP works: outgoing connections have a random local port (by default). When you connect to a host, you only specify that host and a port, you never specify which IP or port on your own PC you want to use, therefore it will be random.
Jannes
CC BY-SA 3.0
2016-01-07T02:55:50.540Z
Yes exactly. But I have two nodes (laptop A and a seed node) connected here from laptop B. Both are outbound since they are initiated by B (one at the peer discovery and other due to my manual command). Why is no random port chosen for the connection between seed node and laptop B? Why is it using only 18333 on both sides (destination and source) for that? Should not the source also be random port (at B side) for that? I also notice that for all seed nodes the source port in B is 18333 as in this case.
Guhan S
CC BY-SA 3.0
2016-01-06T10:04:12.720Z
2016-01-06T10:04:12.720Z
Jannes
<p>I connected two laptops A and B to bitcoin testnet. I then manually connected B to A using <code>addnode</code> of bitcoin-client. </p>

<p>Snippet of <code>getpeerinfo</code> from B:</p>

<pre><code>  {
    "id": 1,
    "addr": "172.22.94.40:18333",
    "addrlocal": "137.122.81.217:53818",

  }
 { 
   "id": 10,
   "addr": "54.152.9.182:18333",
   "services": "000000000000000
 }
</code></pre>

<p>Some connection have an <code>addrlocal</code> set and its port 53818 is randomnly chosen. I searched through the codebase for this. It looks like some <code>fInbound</code> flag will be getting set in A. Can anyone in simple terms explain what is happening here? </p>

<p>I know that a socket cannot be used for listening and sending data at the same time. Is it got to do with that? </p>

<p>If 53818 is chosen as port to send data to A, then why is there no such random choice happening in seed node connection? (like 54.152.9.182 here in example)</p>

<bitcoind><bitcoin-core><client><port>
Why does ONLY some connections have 'addrlocal' in getpeerinfo output
Guhan S
# Why does ONLY some connections have 'addrlocal' in getpeerinfo output

(Asked by: username_0 on 2016-01-06)

I connected two laptops A and B to bitcoin testnet. I then manually connected B to A using `addnode` of bitcoin-client.

Snippet of `getpeerinfo` from B:

```
  {
    "id": 1,
    "addr": "172.22.94.40:18333",
    "addrlocal": "137.122.81.217:53818",

  }
 { 
   "id": 10,
   "addr": "54.152.9.182:18333",
   "services": "000000000000000
 }

```

Some connection have an `addrlocal` set and its port 53818 is randomnly chosen. I searched through the codebase for this. It looks like some `fInbound` flag will be getting set in A. Can anyone in simple terms explain what is happening here?

I know that a socket cannot be used for listening and sending data at the same time. Is it got to do with that?

If 53818 is chosen as port to send data to A, then why is there no such random choice happening in seed node connection? (like 54.152.9.182 here in example)

**Tags:** bitcoind, bitcoin-core, client, port


---

## 1 answers

### Answer by username_1 on 2016-01-06. Score: 1

I would guess addrlocal shows you your endpoint of the connection, that is your IP address and port number. For all incoming connections that would be the same as the IP address and port you are listening on, so that's why it's not displayed. In your case most likely: 137.122.81.217:8333

I'm not sure what would happen if the server is multihomed.

> **Comments:**
> **username_0**: Why my port number is 58318 (randomnly chosen) and NOT 18333? I am still connected via the testnet right?  
> **username_1**: Because it's an outgoing connection and that's how TCP works: outgoing connections have a random local port (by default). When you connect to a host, you only specify that host and a port, you never specify which IP or port on your own PC you want to use, therefore it will be random.  
> **username_0**: Yes exactly. But I have two nodes (laptop A and a seed node) connected here from laptop B. Both are outbound since they are initiated by B (one at the peer discovery and other due to my manual command). Why is no random port chosen for the connection between seed node and laptop B? Why is it using only 18333 on both sides (destination and source) for that? Should not the source also be random port (at B side) for that? I also notice that for all seed nodes the source port in B is 18333 as in this case.  

---

