2020-03-28 22:23:51 +01:00
|
|
|
#!/usr/bin/env lua
|
2011-08-09 01:49:20 +02:00
|
|
|
|
|
|
|
--[[
|
|
|
|
Show that luasocket returns an error message on zero-length UDP sends,
|
|
|
|
even though the send is valid, and in fact the UDP packet is sent
|
|
|
|
to the peer:
|
|
|
|
|
|
|
|
% sudo tcpdump -i lo -n
|
|
|
|
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
|
|
|
|
listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes
|
|
|
|
13:40:16.652808 IP 127.0.0.1.56573 > 127.0.0.1.5432: UDP, length 0
|
|
|
|
|
|
|
|
]]
|
|
|
|
|
2020-03-28 22:23:51 +01:00
|
|
|
socket = require"socket"
|
2011-08-09 01:49:20 +02:00
|
|
|
|
|
|
|
s = assert(socket.udp())
|
|
|
|
r = assert(socket.udp())
|
|
|
|
assert(r:setsockname("*", 5432))
|
|
|
|
assert(s:setpeername("127.0.0.1", 5432))
|
|
|
|
|
|
|
|
ok, emsg = s:send("")
|
|
|
|
if ok ~= 0 then
|
|
|
|
print("send of zero failed with:", ok, emsg)
|
|
|
|
end
|
|
|
|
|
2012-03-01 01:55:55 +01:00
|
|
|
assert(r:settimeout(2))
|
|
|
|
|
2011-08-09 01:49:20 +02:00
|
|
|
ok, emsg = r:receive()
|
|
|
|
|
|
|
|
if not ok or string.len(ok) ~= 0 then
|
2012-03-01 01:55:55 +01:00
|
|
|
print("fail - receive of zero failed with:", ok, emsg)
|
|
|
|
os.exit(1)
|
2011-08-09 01:49:20 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
print"ok"
|
|
|
|
|