Posted 08 March 2012 - 07:34 PM
Hi guys,
I'm working on a packet switched network. Some computers run a program, called mnet_gateway, that handles incoming packets, and is able to forward them along other gateways until they finally reach their destinations. Normal terminals can discover these gateways and register in order to be able to use them, etcetera.
Anyway, a problem is BREAKING my brains for a couple of hours now.. In my mnet api, I have the following code section:
The function receive() waits for a packet to arrive. It is then parsed by the function parse(), which returns the different pieces of info it contains. This all is used in my mnet_gateway program. The output:
WHAT?? As you can see in the source of the parser, I'm looking for a " " (space) char in the string "0>0 5>0 7>0". It is found at position 25 (!) which is, ironically, the exact position in the original network packet, 6|0|gateway_announce|0>0 5>0 7>0
I quadruple-checked everything, I just don't get it… Any idea anyone??
ps1: the exit() is just in order for the program to stop execution, even though it crashes.
ps2: for those who want to understand what I actually do: 6|0|gateway_announce|0>0 5>0 7>0 means packet from 6 to 0, then the command, then the routing table (3>6 means "for 3, send your packet to 6")
I'm working on a packet switched network. Some computers run a program, called mnet_gateway, that handles incoming packets, and is able to forward them along other gateways until they finally reach their destinations. Normal terminals can discover these gateways and register in order to be able to use them, etcetera.
Anyway, a problem is BREAKING my brains for a couple of hours now.. In my mnet api, I have the following code section:
function parse(packet)
local sep1, sep2, sep3, to, source, misc, data
sep1 = string.find(packet, "|")
if (sep1 == nil) then return nil, nil, packet, nil end
sep2 = string.find(packet, "|", sep1 + 1)
if (sep1 == nil) then return nil, nil, packet, nil end
sep3 = string.find(packet, "|", sep2 + 1)
if (sep1 == nil) then return nil, nil, packet, nil end
to = tonumber(string.sub(packet, 0, sep1 - 1))
source = tonumber(string.sub(packet, sep1 + 1, sep2 - 1))
data = string.sub(packet, sep2 + 1, sep3 - 1)
misc = string.sub(packet, sep3 + 1)
[b]print(misc)
a, b = string.find(misc, " ", 0, true)
print(a .. " till " .. :mellow:/>/>[/b]
return to, source, data, misc
end
function receive(timeout)
local from, packet, to, source, data, misc
from, packet = rednet.receive(timeout)
print("[ ] " .. from .. ": " .. packet)
to, source, data, misc = parse(packet)
exit()
return from, to, source, data, misc
end
The function receive() waits for a packet to arrive. It is then parsed by the function parse(), which returns the different pieces of info it contains. This all is used in my mnet_gateway program. The output:
> mnet_gateway
[i] Opening network device on [top]...
[i] Broadcasting gateway...
Listening for connections.
[ ] 0: 6|0|gateway_announce|0>0 5>0 7>0
[b]0>0 5>0 7>0 [/b]
[b]25 till 25[/b]
mnet: 56: attempt to call nil
WHAT?? As you can see in the source of the parser, I'm looking for a " " (space) char in the string "0>0 5>0 7>0". It is found at position 25 (!) which is, ironically, the exact position in the original network packet, 6|0|gateway_announce|0>0 5>0 7>0
I quadruple-checked everything, I just don't get it… Any idea anyone??
ps1: the exit() is just in order for the program to stop execution, even though it crashes.
ps2: for those who want to understand what I actually do: 6|0|gateway_announce|0>0 5>0 7>0 means packet from 6 to 0, then the command, then the routing table (3>6 means "for 3, send your packet to 6")