1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/*
* The Unix Channel
*
* by Michel Beaudouin-Lafon
*
* Copyright 1990-1993
* Laboratoire de Recherche en Informatique (LRI)
*
* Port server: test program
*
* $Id$
* $CurLog$
*/
#include "PortServer.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int
fMatch (const char* match, lword host, sword port, const char*)
{
printf ("0x%lx:%d -> %s\n", host, port, match);
return 1;
}
main (int argc, char **argv)
{
char *host = 0;
char *service = "portserv";
if (argc > 1 && argv [1] [0] == ':') {
host = argv [1] + 1;
argc--, argv++;
}
if (argc > 1 && argv [1] [0] == '=') {
service = argv [1] + 1;
argc--, argv++;
}
UchPortServer ps (service, host);
switch (argc) {
case 1:
ps.Dump ();
break;
case 2:
if (strcmp (argv [1], "quit") == 0)
ps.Quit ();
else
if (argv [1] [0] == '?')
ps.Match (argv [1] + 1, fMatch);
else {
UchInetAddress* addr = ps.Inquire (argv [1]);
if (addr) {
printf ("0x%lx:%d\n", addr->Host (), addr->Port ());
delete addr;
} else
printf ("not found\n");
}
break;
case 3: {
UchInetAddress addr ("", atoi (argv [2]));
if (argv [1] [0] == '-')
ps.Remove (argv [1] + 1, addr, 987);
else
ps.Register (argv [1], addr, 987);
break;
}
}
}
|