/[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 12 - (hide annotations)
Tue Aug 15 12:01:01 2000 UTC (23 years, 9 months ago) by matty
File MIME type: text/plain
File size: 4952 byte(s)
Portability fixes for Solaris and OSF1.

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     STATUS("Version "VERSION". Copyright (C) 1999-2000 Matt Chapman.\n\n");
63    
64     while ((c = getopt(argc, argv, "u:n:w:h:k:mbl?")) != -1)
65     {
66     switch (c)
67     {
68     case 'u':
69     strncpy(username, optarg, sizeof(username));
70     break;
71    
72     case 'n':
73     strncpy(hostname, optarg, sizeof(hostname));
74     break;
75    
76     case 'w':
77     width = strtol(optarg, NULL, 10);
78     break;
79    
80     case 'h':
81     height = strtol(optarg, NULL, 10);
82     break;
83    
84     case 'k':
85     keylayout = strtol(optarg, NULL, 16);
86     break;
87    
88     case 'm':
89     motion = True;
90     break;
91    
92     case 'b':
93     orders = False;
94     break;
95    
96     case 'l':
97     licence = False;
98     break;
99    
100     case '?':
101     default:
102     usage(argv[0]);
103     return 1;
104     }
105     }
106    
107     if (argc - optind < 1)
108     {
109     usage(argv[0]);
110     return 1;
111     }
112    
113     server = argv[optind];
114    
115     if (username[0] == 0)
116     {
117     pw = getpwuid(getuid());
118     if ((pw == NULL) || (pw->pw_name == NULL))
119     {
120     STATUS("Could not determine user name.\n");
121     return 1;
122     }
123    
124     strncpy(username, pw->pw_name, sizeof(username));
125     }
126    
127     if (hostname[0] == 0)
128     {
129     if (gethostname(hostname, sizeof(hostname)) == -1)
130     {
131     STATUS("Could not determine host name.\n");
132     return 1;
133     }
134     }
135    
136     if (!rdp_connect(server))
137     return 1;
138    
139     STATUS("Connection successful.\n");
140    
141 matty 12 strcpy(title, "rdesktop - ");
142     strncat(title, server, sizeof(title));
143    
144 matty 10 if (ui_create_window(title))
145     {
146     rdp_main_loop();
147     ui_destroy_window();
148     }
149    
150     rdp_disconnect();
151     return 0;
152     }
153    
154     /* Generate a 32-byte random for the secure transport code. */
155     void generate_random(uint8 *random)
156     {
157     struct stat st;
158     uint32 *r = (uint32 *)random;
159     int fd;
160    
161     /* If we have a kernel random device, use it. */
162     if ((fd = open("/dev/urandom", O_RDONLY)) != -1)
163     {
164     read(fd, random, 32);
165     close(fd);
166     return;
167     }
168    
169     /* Otherwise use whatever entropy we can gather - ideas welcome. */
170     r[0] = (getpid()) | (getppid() << 16);
171     r[1] = (getuid()) | (getgid() << 16);
172     r[2] = times(NULL); /* system uptime (clocks) */
173     gettimeofday((struct timeval *)&r[3], NULL); /* sec and usec */
174     stat("/tmp", &st);
175     r[5] = st.st_atime;
176     r[6] = st.st_mtime;
177     r[7] = st.st_ctime;
178     }
179    
180     /* malloc; exit if out of memory */
181     void *xmalloc(int size)
182     {
183     void *mem = malloc(size);
184     if (mem == NULL)
185     {
186     ERROR("xmalloc %d\n", size);
187     exit(1);
188     }
189     return mem;
190     }
191    
192     /* realloc; exit if out of memory */
193     void *xrealloc(void *oldmem, int size)
194     {
195     void *mem = realloc(oldmem, size);
196     if (mem == NULL)
197     {
198     ERROR("xrealloc %d\n", size);
199     exit(1);
200     }
201     return mem;
202     }
203    
204     /* free */
205     void xfree(void *mem)
206     {
207     free(mem);
208     }
209    
210     /* Produce a hex dump */
211     void hexdump(unsigned char *p, unsigned int len)
212     {
213     unsigned char *line = p;
214     unsigned int thisline, offset = 0;
215     int i;
216    
217     while (offset < len)
218     {
219     STATUS("%04x ", offset);
220     thisline = len - offset;
221     if (thisline > 16)
222     thisline = 16;
223    
224     for (i = 0; i < thisline; i++)
225     STATUS("%02x ", line[i])
226    
227     for (; i < 16; i++)
228     STATUS(" ");
229    
230     for (i = 0; i < thisline; i++)
231     STATUS("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.');
232    
233     STATUS("\n");
234     offset += thisline;
235     line += thisline;
236     }
237     }

  ViewVC Help
Powered by ViewVC 1.1.26