/* ** @(#) sample.c - RDP development module ** @(#) $Id: sample.c,v 1.1.1.1 2003/11/10 10:34:02 lucio Exp $ */ /* ** ================================================================== ** ** $Logfile:$ ** $RCSfile: sample.c,v $ ** $Revision: 1.1.1.1 $ ** $Date: 2003/11/10 10:34:02 $ ** $Author: lucio $ ** ** ================================================================== ** ** $Log: sample.c,v $ ** Revision 1.1.1.1 2003/11/10 10:34:02 lucio ** ASN.1 developments. ** ** ================================================================== */ #include #include #include #include #include #include <9p.h> #define NAMELEN (40) #define MSGLEN (80) static char *ident = "@(#) $Id: sample.c,v 1.1.1.1 2003/11/10 10:34:02 lucio Exp $"; static void copyright (void) { print ("sample: RDP test bench\n"); print ("Copyright (C) 2003 Lucio De Re.\n"); } static char *use[] = { "usage: %s [-h|H] [-p srv] host\n", "\n", "opts: -h|H: this message\n", " -N: show copyright notice\n", "\n", " -p srv: service name\n", nil }; static void usage (char *argv0, char *use) { fprint (2, use, argv0); exits ("usage"); } static void help (char *argv0, char **use) { print (*use++, argv0); while (*use) { print (*use++); } } /* Opening the lower layer */ int sub (char *layer, char *service, int *fd) { int ctl, data; int chan; char buf[NAMELEN]; int len; snprint (buf, NAMELEN, "/net/%s/clone", layer); ctl = open (buf, ORDWR); if (ctl < 0) { perror ("No layer"); exits (layer); } if (read (ctl, buf, NAMELEN) <= 0) { perror ("Bad layer"); exits (layer); } chan = strtoul (buf, nil, 0); len = snprint (buf, NAMELEN, "use %s", service) + 1; if (write (ctl, buf, len) != len) { perror ("CTL write"); exits ("ctl write"); } snprint (buf, NAMELEN, "/net/%s/%d/data", layer, chan); data = open (buf, ORDWR); if (data < 0) { perror ("DATA open"); exits ("data open"); } if (fd) *fd = ctl; return data; } static void cls (int ctl) { if (write (ctl, "close", 5) != 5) { perror ("CTL write"); exits ("ctl write"); } close (ctl); } int main (int argc, char *argv[]) { int net; // data fd int srv; // exported connection char *srvpt = "port"; int iso, isoctl; /* char *isopt = "isop"; char *mcspt = "mcsp"; int mcs, mcsctl; char *rdppt = "rdpp" int rdp, rdpctl; */ char remote[NAMELEN], *rem, service[NAMELEN]; char msg[MSGLEN]; char buf[NAMELEN]; int x, len; ARGBEGIN { case 'p': srvpt = EARGF (usage (argv0, use[0])); break; case 'h': case 'H': case '?': help (argv0, use); exits (0); default: usage (argv0, use[0]); } ARGEND; if (argc != 1) usage (argv0, use[0]); strncpy (remote, argv[0], NAMELEN); rem = netmkaddr (remote, "tcp", "3389"); net = dial (rem, nil, nil, nil); if (net < 0) { fprint (2, "No connection: %r"); exits ("connect"); } strcpy (service, "#s/"); strncat (service, srvpt, NAMELEN); print ("Mounting on: %s\n", service); srv = create (service, OWRITE|ORCLOSE, 0600); if (srv < 0) { snprint (msg, MSGLEN, "Can't post to %s", service); perror (msg); exits ("service"); } fprint (srv, "%d", net); iso = sub ("iso", service, &isoctl); /* if (write (iso, "this is data\n", 14) < 0) { perror ("iso write"); exits ("iso write"); } while ((len = read (iso, buf, NAMELEN)) > 0) { print ("buf:"); for (x = 0; x < len; x++) print (" %#X", buf[x]); print ("\n"); } */ /* strcpy (service, "#s/"); strncat (service, isopt, NAMELEN); print ("Mounting on: %s\n", service); srv = create (service, OWRITE|ORCLOSE, 0600); if (srv < 0) { snprint (msg, MSGLEN, "Can't post to %s", service); perror (msg); exits ("service"); } fprint (srv, "%d", iso); mcs = sub ("mcs", service, &mcsctl); strcpy (service, "#s/"); strncat (service, mcspt, NAMELEN); print ("Mounting on: %s\n", service); srv = create (service, OWRITE|ORCLOSE, 0600); if (srv < 0) { snprint (msg, MSGLEN, "Can't post to %s", service); perror (msg); exits ("service"); } fprint (srv, "%d", mcs); rdp = sub ("rdp", service, &rdpctl); strcpy (service, "#s/"); strncat (service, rdppt, NAMELEN); */ /* ... */ /* close (rdp); cls (rdpctl); close (mcs); cls (mcsctl); */ close (iso); cls (isoctl); close (srv); close (net); return (0); }