udp-zero-length-send 641 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/lua
  2. --[[
  3. Show that luasocket returns an error message on zero-length UDP sends,
  4. even though the send is valid, and in fact the UDP packet is sent
  5. to the peer:
  6. % sudo tcpdump -i lo -n
  7. tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
  8. listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes
  9. 13:40:16.652808 IP 127.0.0.1.56573 > 127.0.0.1.5432: UDP, length 0
  10. ]]
  11. require"socket"
  12. s = assert(socket.udp())
  13. r = assert(socket.udp())
  14. assert(r:setsockname("*", 5432))
  15. assert(s:setpeername("127.0.0.1", 5432))
  16. ssz, emsg = s:send("")
  17. print(ssz == 0 and "OK" or "FAIL",[[send:("")]], ssz, emsg)