I open two terminal windows on my linux box. On one, I have netcat listen to a UDP port and on other I nmap -sU that port. Netcat receives the connection and the data, but nmap reports the udp port closed. I also see an ICMP port unreachable in nmap logs (not sure why OS is sending it). I've tried --max-retries 1 also. Any advice is much appreciated.
$ nc -l -u -p 12345 -v
listening on [any] 12345 ...
connect to [127.0.0.1] from localhost [127.0.0.1] 65188
test
In a different window
$ sudo nmap -Pn -sU -p 12345 localhost --data-string test -vvv --packet-trace
Starting Nmap 6.49BETA4 ( https://nmap.org ) at 2015-10-15 19:29 EDT
Warning: Hostname localhost resolves to 2 IPs. Using 127.0.0.1.
Initiating UDP Scan at 19:29
Scanning localhost (127.0.0.1) [1 port]
SENT (0.0481s) UDP 127.0.0.1:65188 > 127.0.0.1:12345 ttl=42 id=17191 iplen=32
RCVD (0.0479s) UDP 127.0.0.1:65188 > 127.0.0.1:12345 ttl=42 id=17191 iplen=32
SENT (1.0482s) UDP 127.0.0.1:65189 > 127.0.0.1:12345 ttl=59 id=50254 iplen=32
RCVD (1.0482s) UDP 127.0.0.1:65189 > 127.0.0.1:12345 ttl=59 id=50254 iplen=32
RCVD (1.0482s) ICMP [127.0.0.1 > 127.0.0.1 Port 12345 unreachable (type=3/code=3) ] IP [ttl=64 id=4558 iplen=60 ]
Completed UDP Scan at 19:29, 1.20s elapsed (1 total ports)
Nmap scan report for localhost (127.0.0.1)
Host is up, received user-set (0.000067s latency).
Other addresses for localhost (not scanned): ::1
Scanned at 2015-10-15 19:29:52 EDT for 2s
PORT STATE SERVICE REASON
12345/udp closed unknown port-unreach ttl 64
Read data files from: /usr/bin/../share/nmap
Nmap done: 1 IP address (1 host up) scanned in 1.25 seconds
Raw packets sent: 2 (64B) | Rcvd: 3 (124B)