/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 17 - (hide annotations)
Thu Sep 28 15:54:11 2000 UTC (23 years, 7 months ago) by matty
File MIME type: text/plain
File size: 5017 byte(s)
Fixes (?) for font problems with Microsoft Office
Added URL to website http://www.rdesktop.org/
Releasing 0.9.0-alpha2

1 matty 10 /*
2     rdesktop: A Remote Desktop Protocol client.
3     Entrypoint and utility functions
4     Copyright (C) Matthew Chapman 1999-2000
5    
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10    
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     GNU General Public License for more details.
15    
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19     */
20    
21     #include <stdlib.h> /* malloc realloc free */
22     #include <unistd.h> /* read close getuid getgid getpid getppid gethostname */
23     #include <fcntl.h> /* open */
24     #include <pwd.h> /* getpwuid */
25     #include <sys/stat.h> /* stat */
26     #include <sys/time.h> /* gettimeofday */
27     #include <sys/times.h> /* times */
28     #include "rdesktop.h"
29    
30     char username[16];
31     char hostname[16];
32     int width = 800;
33     int height = 600;
34     int keylayout = 0x409;
35     BOOL motion = False;
36     BOOL orders = True;
37     BOOL licence = True;
38    
39     /* Display usage information */
40     static void usage(char *program)
41     {
42     STATUS("Usage: %s [options] server\n", program);
43     STATUS(" -u: user name\n");
44     STATUS(" -n: client hostname\n");
45     STATUS(" -w: desktop width\n");
46     STATUS(" -h: desktop height\n");
47     STATUS(" -k: keyboard layout (hex)\n");
48     STATUS(" -m: send motion events\n");
49     STATUS(" -b: force bitmap updates\n");
50     STATUS(" -l: do not request licence\n\n");
51     }
52    
53     /* Client program */
54     int main(int argc, char *argv[])
55     {
56     struct passwd *pw;
57     char *server;
58     char title[32];
59     int c;
60    
61     STATUS("rdesktop: A Remote Desktop Protocol client.\n");
62 matty 17 STATUS("Version "VERSION". Copyright (C) 1999-2000 Matt Chapman.\n");
63     STATUS("See http://www.rdesktop.org/ for more information.\n\n");
64 matty 10
65     while ((c = getopt(argc, argv, "u:n:w:h:k:mbl?")) != -1)
66     {
67     switch (c)
68     {
69     case 'u':
70     strncpy(username, optarg, sizeof(username));
71     break;
72    
73     case 'n':
74     strncpy(hostname, optarg, sizeof(hostname));
75     break;
76    
77     case 'w':
78     width = strtol(optarg, NULL, 10);
79     break;
80    
81     case 'h':
82     height = strtol(optarg, NULL, 10);
83     break;
84    
85     case 'k':
86     keylayout = strtol(optarg, NULL, 16);
87     break;
88    
89     case 'm':
90     motion = True;
91     break;
92    
93     case 'b':
94     orders = False;
95     break;
96    
97     case 'l':
98     licence = False;
99     break;
100    
101     case '?':
102     default:
103     usage(argv[0]);
104     return 1;
105     }
106     }
107    
108     if (argc - optind < 1)
109     {
110     usage(argv[0]);
111     return 1;
112     }
113    
114     server = argv[optind];
115    
116     if (username[0] == 0)
117     {
118     pw = getpwuid(getuid());
119     if ((pw == NULL) || (pw->pw_name == NULL))
120     {
121     STATUS("Could not determine user name.\n");
122     return 1;
123     }
124    
125     strncpy(username, pw->pw_name, sizeof(username));
126     }
127    
128     if (hostname[0] == 0)
129     {
130     if (gethostname(hostname, sizeof(hostname)) == -1)
131     {
132     STATUS("Could not determine host name.\n");
133     return 1;
134     }
135     }
136    
137     if (!rdp_connect(server))
138     return 1;
139    
140     STATUS("Connection successful.\n");
141    
142 matty 12 strcpy(title, "rdesktop - ");
143     strncat(title, server, sizeof(title));
144    
145 matty 10 if (ui_create_window(title))
146     {
147     rdp_main_loop();
148     ui_destroy_window();
149     }
150    
151     rdp_disconnect();
152     return 0;
153     }
154    
155     /* Generate a 32-byte random for the secure transport code. */
156     void generate_random(uint8 *random)
157     {
158     struct stat st;
159     uint32 *r = (uint32 *)random;
160     int fd;
161    
162     /* If we have a kernel random device, use it. */
163     if ((fd = open("/dev/urandom", O_RDONLY)) != -1)
164     {
165     read(fd, random, 32);
166     close(fd);
167     return;
168     }
169    
170     /* Otherwise use whatever entropy we can gather - ideas welcome. */
171     r[0] = (getpid()) | (getppid() << 16);
172     r[1] = (getuid()) | (getgid() << 16);
173     r[2] = times(NULL); /* system uptime (clocks) */
174     gettimeofday((struct timeval *)&r[3], NULL); /* sec and usec */
175     stat("/tmp", &st);
176     r[5] = st.st_atime;
177     r[6] = st.st_mtime;
178     r[7] = st.st_ctime;
179     }
180    
181     /* malloc; exit if out of memory */
182     void *xmalloc(int size)
183     {
184     void *mem = malloc(size);
185     if (mem == NULL)
186     {
187     ERROR("xmalloc %d\n", size);
188     exit(1);
189     }
190     return mem;
191     }
192    
193     /* realloc; exit if out of memory */
194     void *xrealloc(void *oldmem, int size)
195     {
196     void *mem = realloc(oldmem, size);
197     if (mem == NULL)
198     {
199     ERROR("xrealloc %d\n", size);
200     exit(1);
201     }
202     return mem;
203     }
204    
205     /* free */
206     void xfree(void *mem)
207     {
208     free(mem);
209     }
210    
211     /* Produce a hex dump */
212     void hexdump(unsigned char *p, unsigned int len)
213     {
214     unsigned char *line = p;
215     unsigned int thisline, offset = 0;
216     int i;
217    
218     while (offset < len)
219     {
220     STATUS("%04x ", offset);
221     thisline = len - offset;
222     if (thisline > 16)
223     thisline = 16;
224    
225     for (i = 0; i < thisline; i++)
226     STATUS("%02x ", line[i])
227    
228     for (; i < 16; i++)
229     STATUS(" ");
230    
231     for (i = 0; i < thisline; i++)
232     STATUS("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.');
233    
234     STATUS("\n");
235     offset += thisline;
236     line += thisline;
237     }
238     }

  ViewVC Help
Powered by ViewVC 1.1.26