# Remote nusers client interface
from rpc import Packer, Unpacker, UDPClient, BroadcastUDPClient
class RnusersPacker(Packer):
ut_line, ut_name, ut_host, ut_time = utmp
self.pack_string(ut_line)
self.pack_string(ut_name)
self.pack_string(ut_host)
def pack_utmpidle(self, ui):
def pack_utmpidlearr(self, list):
self.pack_array(list, self.pack_itmpidle)
class RnusersUnpacker(Unpacker):
ut_line = self.unpack_string()
ut_name = self.unpack_string()
ut_host = self.unpack_string()
ut_time = self.unpack_int()
return ut_line, ut_name, ut_host, ut_time
def unpack_utmpidle(self):
ui_utmp = self.unpack_utmp()
ui_idle = self.unpack_uint()
def unpack_utmpidlearr(self):
return self.unpack_array(self.unpack_utmpidle)
class PartialRnusersClient:
self.packer = RnusersPacker()
self.unpacker = RnusersUnpacker('')
return self.make_call(1, None, None, self.unpacker.unpack_int)
return self.make_call(2, None, \
None, self.unpacker.unpack_utmpidlearr)
return self.make_call(3, None, \
None, self.unpacker.unpack_utmpidlearr)
class RnusersClient(PartialRnusersClient, UDPClient):
def __init__(self, host):
UDPClient.__init__(self, host, 100002, 2)
class BroadcastRnusersClient(PartialRnusersClient, BroadcastUDPClient):
def __init__(self, bcastaddr):
BroadcastUDPClient.__init__(self, bcastaddr, 100002, 2)
for (line, name, host, time), idle in list:
print "%r %r %r %s %s" % (name, host, line, time, idle)
c = BroadcastRnusersClient('<broadcast>')
def listit(list, fromaddr):
for (line, name, host, time), idle in list:
c.set_reply_handler(listit)
print 'Total Count:', len(all)
while s and s[-1] == '\0': s = s[:-1]