/[rdesktop]/sourceforge.net/trunk/rdesktop/rdesktop.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/rdesktop/rdesktop.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 12 by matty, Tue Aug 15 12:01:01 2000 UTC revision 29 by matty, Fri Sep 14 03:38:39 2001 UTC
# Line 18  Line 18 
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */  */
20    
21  #include <stdlib.h>     /* malloc realloc free */  #include <stdlib.h>             /* malloc realloc free */
22  #include <unistd.h>     /* read close getuid getgid getpid getppid gethostname */  #include <unistd.h>             /* read close getuid getgid getpid getppid gethostname */
23  #include <fcntl.h>      /* open */  #include <fcntl.h>              /* open */
24  #include <pwd.h>        /* getpwuid */  #include <pwd.h>                /* getpwuid */
25  #include <sys/stat.h>   /* stat */  #include <sys/stat.h>           /* stat */
26  #include <sys/time.h>   /* gettimeofday */  #include <sys/time.h>           /* gettimeofday */
27  #include <sys/times.h>  /* times */  #include <sys/times.h>          /* times */
28  #include "rdesktop.h"  #include "rdesktop.h"
29    
30  char username[16];  char username[16];
# Line 32  char hostname[16]; Line 32  char hostname[16];
32  int width = 800;  int width = 800;
33  int height = 600;  int height = 600;
34  int keylayout = 0x409;  int keylayout = 0x409;
35  BOOL motion = False;  BOOL bitmap_compression = True;
36    BOOL sendmotion = True;
37  BOOL orders = True;  BOOL orders = True;
38  BOOL licence = True;  BOOL licence = True;
39    BOOL use_encryption = True;
40    BOOL desktop_save = True;
41    BOOL fullscreen = False;
42    
43  /* Display usage information */  /* Display usage information */
44  static void usage(char *program)  static void
45    usage(char *program)
46  {  {
47          STATUS("Usage: %s [options] server\n", program);          STATUS("Usage: %s [options] server\n", program);
48          STATUS("   -u: user name\n");          STATUS("   -u: user name\n");
49            STATUS("   -d: domain\n");
50            STATUS("   -s: shell\n");
51            STATUS("   -c: working directory\n");
52            STATUS("   -p: password (autologon)\n");
53          STATUS("   -n: client hostname\n");          STATUS("   -n: client hostname\n");
54          STATUS("   -w: desktop width\n");          STATUS("   -w: desktop width\n");
55          STATUS("   -h: desktop height\n");          STATUS("   -h: desktop height\n");
56          STATUS("   -k: keyboard layout (hex)\n");          STATUS("   -k: keyboard layout (hex)\n");
         STATUS("   -m: send motion events\n");  
57          STATUS("   -b: force bitmap updates\n");          STATUS("   -b: force bitmap updates\n");
58            STATUS("   -m: do not send motion events\n");
59          STATUS("   -l: do not request licence\n\n");          STATUS("   -l: do not request licence\n\n");
60  }  }
61    
62  /* Client program */  /* Client program */
63  int main(int argc, char *argv[])  int
64    main(int argc, char *argv[])
65  {  {
66          struct passwd *pw;          struct passwd *pw;
67          char *server;          char *server;
68            uint32 flags;
69            char domain[16];
70            char password[16];
71            char shell[32];
72            char directory[32];
73          char title[32];          char title[32];
74          int c;          int c;
75    
76          STATUS("rdesktop: A Remote Desktop Protocol client.\n");          STATUS("rdesktop: A Remote Desktop Protocol client.\n");
77          STATUS("Version "VERSION". Copyright (C) 1999-2000 Matt Chapman.\n\n");          STATUS("Version " VERSION
78                   ". Copyright (C) 1999-2000 Matt Chapman.\n");
79            STATUS("See http://www.rdesktop.org/ for more information.\n\n");
80    
81          while ((c = getopt(argc, argv, "u:n:w:h:k:mbl?")) != -1)          flags = RDP_LOGON_NORMAL;
82            domain[0] = password[0] = shell[0] = directory[0] = 0;
83    
84            while ((c = getopt(argc, argv, "u:d:s:c:p:n:g:k:mbleKFVh?")) != -1)
85          {          {
86                  switch (c)                  switch (c)
87                  {                  {
# Line 69  int main(int argc, char *argv[]) Line 89  int main(int argc, char *argv[])
89                                  strncpy(username, optarg, sizeof(username));                                  strncpy(username, optarg, sizeof(username));
90                                  break;                                  break;
91    
92                          case 'n':                          case 'd':
93                                  strncpy(hostname, optarg, sizeof(hostname));                                  strncpy(domain, optarg, sizeof(domain));
94                                  break;                                  break;
95    
96                          case 'w':                          case 'p':
97                                  width = strtol(optarg, NULL, 10);                                  flags |= RDP_LOGON_AUTO;
98                                    strncpy(password, optarg, sizeof(password));
99                                  break;                                  break;
100    
101                          case 'h':                          case 's':
102                                  height = strtol(optarg, NULL, 10);                                  strncpy(shell, optarg, sizeof(shell));
103                                    break;
104    
105                            case 'c':
106                                    strncpy(directory, optarg, sizeof(directory));
107                                    break;
108    
109                            case 'n':
110                                    strncpy(hostname, optarg, sizeof(hostname));
111                                    break;
112                            case 'g':
113                                    {
114                                            char *tgem = 0;
115                                            width = strtol(optarg, NULL, 10);
116                                            tgem = strchr(optarg, 'x');
117                                            if ((tgem == 0) || (strlen(tgem) < 2))
118                                            {
119                                                    ERROR
120                                                            ("-g: invalid parameter. Syntax example: -g 1024x768\n");
121                                                    exit(1);
122                                            }
123                                            height = strtol(tgem + 1, NULL, 10);
124                                    }
125                                  break;                                  break;
126    
127                          case 'k':                          case 'k':
128                                  keylayout = strtol(optarg, NULL, 16);                                  keylayout = strtol(optarg, NULL, 16);
129                                    /* keylayout = find_keyb_code(optarg); */
130                                    if (keylayout == 0)
131                                            return 0;
132                                  break;                                  break;
133    
134                          case 'm':                          case 'm':
135                                  motion = True;                                  sendmotion = False;
136                                  break;                                  break;
137    
138                          case 'b':                          case 'b':
# Line 97  int main(int argc, char *argv[]) Line 143  int main(int argc, char *argv[])
143                                  licence = False;                                  licence = False;
144                                  break;                                  break;
145    
146                            case 'e':
147                                    use_encryption = False;
148                                    break;
149    
150                            case 'F':
151                                    fullscreen = True;
152                                    break;
153    
154                            case 'h':
155                          case '?':                          case '?':
156                          default:                          default:
157                                  usage(argv[0]);                                  usage(argv[0]);
# Line 133  int main(int argc, char *argv[]) Line 188  int main(int argc, char *argv[])
188                  }                  }
189          }          }
190    
         if (!rdp_connect(server))  
                 return 1;  
   
         STATUS("Connection successful.\n");  
   
191          strcpy(title, "rdesktop - ");          strcpy(title, "rdesktop - ");
192          strncat(title, server, sizeof(title));          strncat(title, server, sizeof(title));
193    
194          if (ui_create_window(title))          if (ui_create_window(title))
195          {          {
196                    if (!rdp_connect(server, flags, domain, password, shell,
197                                     directory))
198                            return 1;
199    
200                    STATUS("Connection successful.\n");
201                  rdp_main_loop();                  rdp_main_loop();
202                  ui_destroy_window();                  ui_destroy_window();
203          }          }
# Line 152  int main(int argc, char *argv[]) Line 207  int main(int argc, char *argv[])
207  }  }
208    
209  /* Generate a 32-byte random for the secure transport code. */  /* Generate a 32-byte random for the secure transport code. */
210  void generate_random(uint8 *random)  void
211    generate_random(uint8 *random)
212  {  {
213          struct stat st;          struct stat st;
214          uint32 *r = (uint32 *)random;          struct tms tmsbuf;
215            uint32 *r = (uint32 *) random;
216          int fd;          int fd;
217    
218          /* If we have a kernel random device, use it. */          /* If we have a kernel random device, use it. */
# Line 169  void generate_random(uint8 *random) Line 226  void generate_random(uint8 *random)
226          /* Otherwise use whatever entropy we can gather - ideas welcome. */          /* Otherwise use whatever entropy we can gather - ideas welcome. */
227          r[0] = (getpid()) | (getppid() << 16);          r[0] = (getpid()) | (getppid() << 16);
228          r[1] = (getuid()) | (getgid() << 16);          r[1] = (getuid()) | (getgid() << 16);
229          r[2] = times(NULL); /* system uptime (clocks) */          r[2] = times(&tmsbuf);  /* system uptime (clocks) */
230          gettimeofday((struct timeval *)&r[3], NULL); /* sec and usec */          gettimeofday((struct timeval *) &r[3], NULL);   /* sec and usec */
231          stat("/tmp", &st);          stat("/tmp", &st);
232          r[5] = st.st_atime;          r[5] = st.st_atime;
233          r[6] = st.st_mtime;          r[6] = st.st_mtime;
# Line 178  void generate_random(uint8 *random) Line 235  void generate_random(uint8 *random)
235  }  }
236    
237  /* malloc; exit if out of memory */  /* malloc; exit if out of memory */
238  void *xmalloc(int size)  void *
239    xmalloc(int size)
240  {  {
241          void *mem = malloc(size);          void *mem = malloc(size);
242          if (mem == NULL)          if (mem == NULL)
# Line 190  void *xmalloc(int size) Line 248  void *xmalloc(int size)
248  }  }
249    
250  /* realloc; exit if out of memory */  /* realloc; exit if out of memory */
251  void *xrealloc(void *oldmem, int size)  void *
252    xrealloc(void *oldmem, int size)
253  {  {
254          void *mem = realloc(oldmem, size);          void *mem = realloc(oldmem, size);
255          if (mem == NULL)          if (mem == NULL)
# Line 202  void *xrealloc(void *oldmem, int size) Line 261  void *xrealloc(void *oldmem, int size)
261  }  }
262    
263  /* free */  /* free */
264  void xfree(void *mem)  void
265    xfree(void *mem)
266  {  {
267          free(mem);          free(mem);
268  }  }
269    
270  /* Produce a hex dump */  /* Produce a hex dump */
271  void hexdump(unsigned char *p, unsigned int len)  void
272    hexdump(unsigned char *p, unsigned int len)
273  {  {
274          unsigned char *line = p;          unsigned char *line = p;
275          unsigned int thisline, offset = 0;          unsigned int thisline, offset = 0;
# Line 222  void hexdump(unsigned char *p, unsigned Line 283  void hexdump(unsigned char *p, unsigned
283                          thisline = 16;                          thisline = 16;
284    
285                  for (i = 0; i < thisline; i++)                  for (i = 0; i < thisline; i++)
286                          STATUS("%02x ", line[i])                          STATUS("%02x ", line[i]) for (; i < 16; i++)
287                                    STATUS("   ");
                 for (; i < 16; i++)  
                         STATUS("   ");  
288    
289                  for (i = 0; i < thisline; i++)                  for (i = 0; i < thisline; i++)
290                          STATUS("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.');                          STATUS("%c",
291                                   (line[i] >= 0x20
292                                    && line[i] < 0x7f) ? line[i] : '.');
293    
294                  STATUS("\n");                  STATUS("\n");
295                  offset += thisline;                  offset += thisline;

Legend:
Removed from v.12  
changed lines
  Added in v.29

  ViewVC Help
Powered by ViewVC 1.1.26