mirror of
https://github.com/AR2000AR/openComputers_codes.git
synced 2025-09-08 06:31:14 +02:00
[osinetwrok] fix bug in udp
fixed : one char was lost in the udp payload
This commit is contained in:
@@ -99,7 +99,7 @@ end
|
||||
---@return UDPDatagram
|
||||
function UDPDatagram.unpack(value)
|
||||
local src, dst, len, chk, offset = string.unpack(UDPDatagram.payloadFormat, value)
|
||||
local payload = string.unpack('>c' .. len - offset, value, offset)
|
||||
local payload = string.unpack('>c' .. (len - offset) + 1, value, offset)
|
||||
return UDPDatagram(src, dst, payload)
|
||||
end
|
||||
|
||||
|
@@ -36,64 +36,7 @@ function UDPLayer:payloadHandler(from, to, payload)
|
||||
socket:payloadHandler(from, to, udpPacket)
|
||||
end
|
||||
|
||||
--#region
|
||||
-- ---Open a new UDP socket.
|
||||
-- ---@param address number
|
||||
-- ---@param port number
|
||||
-- ---@param remoteAddress number
|
||||
-- ---@param remotePort number
|
||||
-- ---@overload fun(self:UDPLayer):UDPSocket
|
||||
-- ---@overload fun(self:UDPLayer,address:number):UDPSocket
|
||||
-- ---@overload fun(self:UDPLayer,address:nil,port:number):UDPSocket?, string?
|
||||
-- ---@overload fun(self:UDPLayer,address:number,port:number):UDPSocket?, string?
|
||||
-- ---@overload fun(self:UDPLayer,address:nil,port:nil,remoteAddress:number,remotePort:number):UDPSocket
|
||||
-- ---@overload fun(self:UDPLayer,address:number,port:nil,remoteAddress:number,remotePort:number):UDPSocket
|
||||
-- ---@return UDPSocket? socket, string? reason
|
||||
-- function UDPLayer:open(address, port, remoteAddress, remotePort)
|
||||
-- --#region checkArg
|
||||
-- if (remoteAddress) then
|
||||
-- checkArg(3, remoteAddress, 'number')
|
||||
-- checkArg(4, remotePort, 'number')
|
||||
-- else
|
||||
-- checkArg(3, remoteAddress, 'nil')
|
||||
-- checkArg(4, remotePort, 'nil')
|
||||
-- end
|
||||
-- --[[Truth table
|
||||
-- address 0 1 1 0 1 0 1 0
|
||||
-- port 0 1 0 1 1 0 0 1
|
||||
-- remoteAddres 0 1 0 0 0 1 1 1
|
||||
-- remotePort 0 1 0 0 0 1 1 1
|
||||
-- 0 15 1 2 3 12 13 14
|
||||
-- ]]
|
||||
-- local validTypes = {[0] = true,[15] = true,[1] = true,[2] = true,[3] = true,[12] = true,[13] = true,[14] = true}
|
||||
-- local currentTypes = 0
|
||||
-- if (address) then currentTypes = currentTypes + 1 end
|
||||
-- if (port) then currentTypes = currentTypes + 2 end
|
||||
-- if (remoteAddress) then currentTypes = currentTypes + 4 end
|
||||
-- if (remotePort) then currentTypes = currentTypes + 8 end
|
||||
-- if (not validTypes[currentTypes]) then
|
||||
-- error("Invalid arguments types. Found : " .. currentTypes .. ". Please check that all required arguments are present", 2)
|
||||
-- end
|
||||
-- --#endregion
|
||||
|
||||
-- --TODO : default to default route interface address
|
||||
-- if (not address) then address = 0 end
|
||||
|
||||
-- if (port == nil or port == 0) then
|
||||
-- repeat
|
||||
-- port = math.random(1025, (2 ^ 16) - 1)
|
||||
-- until not self:getSocket(address, port, remoteAddress, remotePort)
|
||||
-- end
|
||||
-- local socket = UDPSocket(self, address, port, remoteAddress, remotePort)
|
||||
-- if (self:addSocket(socket)) then
|
||||
-- return socket
|
||||
-- else
|
||||
-- return nil, "Could not create socket"
|
||||
-- end
|
||||
-- end
|
||||
--#endregion
|
||||
|
||||
---comment
|
||||
---bind the socket to a local address and port
|
||||
---@param socket UDPSocket
|
||||
---@param address number
|
||||
---@param port number
|
||||
|
@@ -60,6 +60,7 @@ end
|
||||
|
||||
---@return string? datagram, string? fromAddress, number? fromPort
|
||||
function UDPSocket:receivefrom(size)
|
||||
--TODO : use the size
|
||||
if (select(2, self:getsockname()) == 0) then
|
||||
error("Reciving object before binding to a address/port", 2)
|
||||
end
|
||||
@@ -156,6 +157,8 @@ function UDPSocket:setoption(option, value)
|
||||
error("NOT IMPLEMENTED", 2)
|
||||
end
|
||||
|
||||
---Set the socket's timeout in second
|
||||
---@param value number seconds
|
||||
function UDPSocket:settimeout(value)
|
||||
checkArg(1, value, 'number')
|
||||
self._timeout = value * 100
|
||||
|
@@ -255,7 +255,7 @@
|
||||
["osinetwork"] = {
|
||||
["manifestVersion"] = "1.0",
|
||||
["package"] = "osinetwork",
|
||||
["version"] = "2.4.0",
|
||||
["version"] = "2.4.1",
|
||||
["name"] = "OSI Network stack",
|
||||
["repo"] = "tree/master/network",
|
||||
["description"] = "A close to official rfc emulation of the OSI layers for OpenOS. Include Ethernet, ARP, ICMP, UDP. Also provide a luasocket libe librairy",
|
||||
|
Binary file not shown.
@@ -277,7 +277,7 @@
|
||||
note = "Are provided : ping, ifup, ifdown, arp, nc, netstat. Any one of theses tools may be moved to a separate package at any time",
|
||||
authors = "AR2000AR",
|
||||
repo = "tree/master/network",
|
||||
version = "2.4.0"
|
||||
version = "2.4.1"
|
||||
},
|
||||
["dns_common"] = {
|
||||
files = {
|
||||
|
Reference in New Issue
Block a user