1 # Remote nusers client interface
4 from rpc
import Packer
, Unpacker
, UDPClient
, BroadcastUDPClient
7 class RnusersPacker(Packer
):
8 def pack_utmp(self
, ui
):
9 ut_line
, ut_name
, ut_host
, ut_time
= utmp
10 self
.pack_string(ut_line
)
11 self
.pack_string(ut_name
)
12 self
.pack_string(ut_host
)
13 self
.pack_int(ut_time
)
14 def pack_utmpidle(self
, ui
):
16 self
.pack_utmp(ui_utmp
)
17 self
.pack_uint(ui_idle
)
18 def pack_utmpidlearr(self
, list):
19 self
.pack_array(list, self
.pack_itmpidle
)
22 class RnusersUnpacker(Unpacker
):
23 def unpack_utmp(self
):
24 ut_line
= self
.unpack_string()
25 ut_name
= self
.unpack_string()
26 ut_host
= self
.unpack_string()
27 ut_time
= self
.unpack_int()
28 return ut_line
, ut_name
, ut_host
, ut_time
29 def unpack_utmpidle(self
):
30 ui_utmp
= self
.unpack_utmp()
31 ui_idle
= self
.unpack_uint()
32 return ui_utmp
, ui_idle
33 def unpack_utmpidlearr(self
):
34 return self
.unpack_array(self
.unpack_utmpidle
)
37 class PartialRnusersClient
:
40 self
.packer
= RnusersPacker()
41 self
.unpacker
= RnusersUnpacker('')
44 return self
.make_call(1, None, None, self
.unpacker
.unpack_int
)
47 return self
.make_call(2, None, \
48 None, self
.unpacker
.unpack_utmpidlearr
)
51 return self
.make_call(3, None, \
52 None, self
.unpacker
.unpack_utmpidlearr
)
55 class RnusersClient(PartialRnusersClient
, UDPClient
):
57 def __init__(self
, host
):
58 UDPClient
.__init
__(self
, host
, 100002, 2)
61 class BroadcastRnusersClient(PartialRnusersClient
, BroadcastUDPClient
):
63 def __init__(self
, bcastaddr
):
64 BroadcastUDPClient
.__init
__(self
, bcastaddr
, 100002, 2)
74 c
= RnusersClient(host
)
76 for (line
, name
, host
, time
), idle
in list:
80 print "%r %r %r %s %s" % (name
, host
, line
, time
, idle
)
83 c
= BroadcastRnusersClient('<broadcast>')
84 def listit(list, fromaddr
):
87 for (line
, name
, host
, time
), idle
in list:
90 c
.set_reply_handler(listit
)
92 print 'Total Count:', len(all
)
95 while s
and s
[-1] == '\0': s
= s
[:-1]