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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
|
diff -r -u gnome-pilot-2.0.12.old/capplet/pilot.c gnome-pilot-2.0.12/capplet/pilot.c
--- gnome-pilot-2.0.12.old/capplet/pilot.c 2005-03-11 15:19:25.241666392 +0100
+++ gnome-pilot-2.0.12/capplet/pilot.c 2005-03-11 15:24:06.103968832 +0100
@@ -155,10 +155,6 @@
if (device->type == PILOT_DEVICE_NETWORK) {
device->ip = gnome_config_get_string ("ip");
g_message ("cradle network ip -> %s", device->ip);
- device->ip = gnome_config_get_string ("host");
- g_message ("cradle network host name -> %s", device->host);
- device->ip = gnome_config_get_string ("netmask");
- g_message ("cradle network mask -> %s", device->netmask);
} else {
device->port = gnome_config_get_string ("device");
g_message ("cradle device name -> %s", device->port);
@@ -286,8 +282,6 @@
gnome_config_set_string ("name", device->name);
if (device->type == PILOT_DEVICE_NETWORK) {
gnome_config_set_string ("ip", device->ip);
- gnome_config_set_string ("host", device->host);
- gnome_config_set_string ("netmask", device->netmask);
} else {
gnome_config_set_string ("device", device->port);
gnome_config_set_int ("speed", device->speed);
diff -r -u gnome-pilot-2.0.12.old/gpilotd/gnome-pilot-structures.c gnome-pilot-2.0.12/gpilotd/gnome-pilot-structures.c
--- gnome-pilot-2.0.12.old/gpilotd/gnome-pilot-structures.c 2005-03-11 15:19:25.220669584 +0100
+++ gnome-pilot-2.0.12/gpilotd/gnome-pilot-structures.c 2005-03-11 15:23:01.207834544 +0100
@@ -38,12 +38,12 @@
#include <signal.h>
/* From pi-csd */
-#include <signal.h>
#include <sys/socket.h>
#include <netinet/in.h>
-#include <net/if.h>
+/*#include <net/if.h>*/
#include <arpa/inet.h>
#include <netdb.h>
+#include <pi-source.h>
#define LOCK_DIR "/var/lock"
#define LOCK_BINARY 0
@@ -380,154 +380,6 @@
#ifdef WITH_NETWORK
-/*
- * pi-csd.c: Connection Service Daemon, required for accepting
- * logons via NetSync (tm)
- * Copyright (c) 1997, Kenneth Albanowski
- *
- * While this function is useful in pi-csd, it is intended also to
- * be a demonstration of the proper (or improper, if I'm unlucky) techniques
- * to retrieve networking information.
- */
-static void
-fetch_host (char *hostname, int hostlen, struct in_addr *address,
- struct in_addr *mask)
-{
-#if defined (SIOCGIFCONF) && defined (SIOCGIFFLAGS)
- int s, n, i;
- struct ifconf ifc;
- struct ifreq *ifr, ifreqaddr, ifreqmask;
-#endif
- struct hostent *hent;
-
-#ifdef HAVE_GETHOSTNAME
- /* Get host name the easy way */
-
- gethostname (hostname, hostlen);
-#else
-# ifdef HAVE_UNAME
- struct utsname uts;
-
- if (uname (&uts) == 0) {
- strncpy (hostname, uts.nodename, hostlen - 1);
- hostname[hostlen - 1] = '\0';
- }
-# endif /*def HAVE_UNAME */
-#endif /*def HAVE_GETHOSTNAME */
-
- /* Get host address through DNS */
- hent = gethostbyname (hostname);
-
- if (hent) {
- while (*hent->h_addr_list) {
- struct in_addr haddr;
-
- memcpy (&haddr, *(hent->h_addr_list++), sizeof (haddr));
- if (haddr.s_addr != inet_addr ("127.0.0.1"))
- memcpy (address, &haddr, sizeof (haddr));
- }
- }
-#if defined (SIOCGIFCONF) && defined (SIOCGIFFLAGS)
- s = socket (AF_INET, SOCK_DGRAM, 0);
-
- if (s < 0)
- return;
-
- ifc.ifc_buf = calloc (1024, 1);
- ifc.ifc_len = 1024;
-
- if (ioctl (s, SIOCGIFCONF, (char *) &ifc) < 0)
- goto done;
-
- n = ifc.ifc_len;
- for (i = 0; i < n; i += ifreq_size (*ifr)) {
- struct sockaddr_in *a;
- struct sockaddr_in *b;
-
- ifr = (struct ifreq *) ((caddr_t) ifc.ifc_buf + i);
- a = (struct sockaddr_in *) &ifr->ifr_addr;
- strncpy (ifreqaddr.ifr_name, ifr->ifr_name, sizeof (ifreqaddr.ifr_name));
- strncpy (ifreqmask.ifr_name, ifr->ifr_name, sizeof (ifreqmask.ifr_name));
-
- if (ioctl (s, SIOCGIFFLAGS, (char *) &ifreqaddr) < 0)
- continue;
-
- /* Reject loopback device */
-#ifdef IFF_LOOPBACK
- if (ifreqaddr.ifr_flags & IFF_LOOPBACK)
- continue;
-#endif /*def IFF_LOOPBACK */
-
-#ifdef IFF_UP
- /* Reject down devices */
- if (!(ifreqaddr.ifr_flags & IFF_UP))
- continue;
-#endif /*def IFF_UP */
-
- if (ifr->ifr_addr.sa_family != AF_INET)
- continue;
-
- /* If it is a point-to-point device, use the dest address */
-#if defined (IFF_POINTOPOINT) && defined (SIOCGIFDSTADDR)
- if (ifreqaddr.ifr_flags & IFF_POINTOPOINT) {
- if (ioctl (s, SIOCGIFDSTADDR, (char *) &ifreqaddr) < 0)
- break;
-
- a = (struct sockaddr_in *) &ifreqaddr.ifr_dstaddr;
-
- if (address->s_addr == 0) {
- memcpy (address, &a->sin_addr, sizeof (struct in_addr));
- }
- }
- else
-#endif /*defined (IFF_POINTOPOINT) && defined (SIOCGIFDSTADDR) */
- /* If it isn't a point-to-point device, use the address */
-#ifdef SIOCGIFADDR
- {
- if (ioctl (s, SIOCGIFADDR, (char *) &ifreqaddr) < 0)
- break;
-
- a = (struct sockaddr_in *) &ifreqaddr.ifr_addr;
-
- if (address->s_addr == 0) {
- memcpy (address, &a->sin_addr, sizeof (struct in_addr));
- }
- }
-#endif /*def SIOCGIFADDR */
- /* OK, we've got an address */
-
- /* Compare netmask against the current address and see if it seems to match. */
-#ifdef SIOCGIFNETMASK
- if (ioctl (s, SIOCGIFNETMASK, (char *) &ifreqmask) < 0)
- break;
-
-/* Is there any system where we need to use ifr_netmask? */
-#if 1
- b = (struct sockaddr_in *) &ifreqmask.ifr_addr;
-#else
- b = (struct sockaddr_in *) &ifreqmask.ifr_netmask;
-#endif
-
- if ((mask->s_addr == 0) && (address->s_addr != 0)) {
- if ((b->sin_addr.s_addr & a->sin_addr.s_addr) ==
- (b->sin_addr.s_addr & address->s_addr)) {
- memcpy (mask, &b->sin_addr, sizeof (struct in_addr));
-
- /* OK, we've got a netmask */
-
- break;
- }
- }
-#endif /*def SIOCGIFNETMASK */
-
- }
-
- done:
- free (ifc.ifc_buf);
- close (s);
-#endif /*defined (SIOCGIFCONF) && defined (SIOCGIFFLAGS) */
-}
-
/* gpilot_network_device_init (GPilotDevice *device)
* pi-csd.c: Connection Service Daemon, required for accepting
* logons via NetSync (tm)
@@ -537,84 +389,56 @@
static gint
gpilot_network_device_init (GPilotDevice *device)
{
-/*
- * Open a file descriptor. device->fd
- * Check fd. return -1 if fail.
- * device->io = g_io_channel_unix_new (device->fd);
- * g_io_channel_ref (device->io);
- * return 0;
- *
- */
+ struct pi_sockaddr addr;
-/* char hostname[130]; this is device->host */
- struct in_addr address, netmask;
+ char pi_net[100];
-
-/* int sockfd; this is device->fd */
- struct sockaddr_in serv_addr;
-
- struct hostent *hent;
-/* int quiet = 0; It's Always quiet here */
-
- memset (&address, 0, sizeof (address));
- memset (&netmask, 0, sizeof (netmask));
-
-/* hostname[0] = 0; */
-/* device->host = g_new (gchar, 130);
- g_free (device->host);
-*/
-
-/* This is used if the hostname is not correct in the conf file
- I'll move it to the conf file saving later */
- fetch_host (device->host, 128, &address, &netmask);
-
-/* device->host I already have from the config file */
-
- if (inet_aton (device->ip, &address) == 0) /* Invalid */
- {
- if ((hent = gethostbyname (device->ip))) {
- memcpy (&address.s_addr, hent->h_addr, sizeof (address));
- } else {
- g_message ("Invalid ip address '%s'", device->ip);
- return -1;
+ memset(pi_net, 0, sizeof(pi_net));
+ strncpy(pi_net, "net:", 4);
+ if (device->ip != NULL && (strnlen(device->ip, 1) > 0)) {
+ struct sockaddr_in serv_addr;
+ /* Verify the IP address is valid */
+ memset(&serv_addr, 0, sizeof(serv_addr));
+ serv_addr.sin_family = AF_INET;
+ serv_addr.sin_addr.s_addr = inet_addr(device->ip);
+ if (serv_addr.sin_addr.s_addr == (in_addr_t)-1) {
+ struct hostent *hostent = gethostbyname(device->ip);
+
+ if (!hostent) {
+ g_warning ("Device [%s]: Bad IP address/hostname: %s",
+ device->name, device->ip);
+ return -1;
+ }
}
- }
- if (inet_aton (device->netmask, &netmask) == 0) {
- g_message ("Invalid netmask '%s'", device->netmask);
- return -1;
+ strncat(pi_net, device->ip, sizeof(pi_net) - 2 - strlen(pi_net));
+ } else {
+ strncat(pi_net, "any", 3);
}
-
- /* cannot execute without address and hostname */
- if ((address.s_addr == 0) || (strlen (device->host) == 0))
- {
- g_message ("Cannot execute without ip address and hostname.");
+ device->fd = pi_socket (PI_AF_PILOT, PI_SOCK_STREAM, PI_PF_NET);
+ if (device->fd < 0) {
+ g_warning ("Device [%s, %s]: Unable to get socket: %s",
+ device->name, pi_net, strerror(errno));
return -1;
}
- device->fd = socket (AF_INET, SOCK_DGRAM, 0);
- if (device->fd < 0) {
- g_message ("Unable to get socket");
+ strncpy (addr.pi_device,pi_net, strlen(pi_net));
+
+ if (pi_bind (device->fd, (struct sockaddr*)&addr, sizeof (addr)) < 0) {
+ g_warning ("Device [%s, %s]: Unable to bind socket",
+ device->name, pi_net);
return -1;
}
- memset (&serv_addr, 0, sizeof (serv_addr));
- serv_addr.sin_family = AF_INET;
- serv_addr.sin_addr.s_addr = htonl (INADDR_ANY);
- serv_addr.sin_port = htons (14237);
-
- if (bind (device->fd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) < 0) {
- g_message ("Unable to bind socket");
+ /* Now listen for incoming connections */
+ if (pi_listen (device->fd, 1) != 0) {
+ g_warning ("Device [%s, %s]: Error from listen: %s",
+ device->name, pi_net, strerror (errno));
+ close(device->fd);
return -1;
}
- /*
- g_message ("Connection Service Daemon for Palm Computing (tm) device active.");
- g_message ("Accepting connection requests for '%s' at %s with mask %s",
- device->host, inet_ntoa (address), inet_ntoa (netmask));
- */
- /* We don't want to infinite loops here */
- /* Lets try something else instead */
+ /* Register an interest in the socket, to get events when devices connect */
device->io = g_io_channel_unix_new (device->fd);
g_io_channel_ref (device->io);
@@ -630,13 +454,17 @@
}
g_free(device->ip);
- g_free(device->host);
- g_free(device->netmask);
}
static void
gpilot_network_device_deinit (GPilotDevice *device)
{
+ if (device->io) {
+ g_source_remove (device->in_handle);
+ g_source_remove (device->err_handle);
+ g_io_channel_close (device->io);
+ g_io_channel_unref (device->io);
+ }
}
#endif /* WITH_NETWORK */
@@ -680,8 +508,6 @@
gpilot_network_device_load (GPilotDevice *device)
{
device->ip = gnome_config_get_string ("ip");
- device->host = gnome_config_get_string ("host");
- device->netmask = gnome_config_get_string ("netmask");
}
gint
diff -r -u gnome-pilot-2.0.12.old/gpilotd/gnome-pilot-structures.h gnome-pilot-2.0.12/gpilotd/gnome-pilot-structures.h
--- gnome-pilot-2.0.12.old/gpilotd/gnome-pilot-structures.h 2005-03-11 15:19:25.220669584 +0100
+++ gnome-pilot-2.0.12/gpilotd/gnome-pilot-structures.h 2005-03-11 15:23:20.805855192 +0100
@@ -90,8 +90,6 @@
/* These are used for network (man c++ is soo much cooler) */
gchar *ip;
- gchar *host;
- gchar *netmask;
/* These are used at runtime, to associate
an opened file with the device */
diff -r -u gnome-pilot-2.0.12.old/gpilotd/gpilotd.c gnome-pilot-2.0.12/gpilotd/gpilotd.c
--- gnome-pilot-2.0.12.old/gpilotd/gpilotd.c 2005-03-11 15:19:25.226668672 +0100
+++ gnome-pilot-2.0.12/gpilotd/gpilotd.c 2005-03-11 15:22:37.000514616 +0100
@@ -148,42 +148,37 @@
break;
}
- if (!(listen_sd = pi_socket (PI_AF_PILOT, PI_SOCK_STREAM, pf))) {
- g_warning ("pi_socket: %s",strerror (errno));
- if (error) *error = 1;
- return -1;
- }
-
- addr.pi_family = PI_AF_PILOT;
-
-/*
- Most important for networking
- . resolves inside libpisock as network
- It is done earlier in gpilotd_device_init
- so don't really need to do it again here.
-*/
if (device->type == PILOT_DEVICE_NETWORK) {
- device->port = "net:any";
- }
+ /* we've already got a listen, so move on to accept */
+ listen_sd = device->fd;
+ } else {
+ if (!(listen_sd = pi_socket (PI_AF_PILOT, PI_SOCK_STREAM, pf))) {
+ g_warning ("pi_socket: %s",strerror (errno));
+ if (error) *error = 1;
+ return -1;
+ }
+
+ addr.pi_family = PI_AF_PILOT;
- strcpy (addr.pi_device,device->port);
+ strcpy (addr.pi_device,device->port);
- ret = pi_bind (listen_sd, (struct sockaddr*)&addr, sizeof (addr));
- if (ret == -1) {
- g_warning (_("Unable to bind to pilot"));
- if (error)
- *error = 1;
- pi_close(listen_sd);
- return 0;
- }
+ ret = pi_bind (listen_sd, (struct sockaddr*)&addr, sizeof (addr));
+ if (ret == -1) {
+ g_warning (_("Unable to bind to pilot"));
+ if (error)
+ *error = 1;
+ pi_close(listen_sd);
+ return 0;
+ }
- ret = pi_listen (listen_sd, 1);
- if (ret != 0) {
- g_warning ("pi_listen: %s", strerror (errno));
- if (error)
- *error = 2;
- pi_close(listen_sd);
- return 0;
+ ret = pi_listen (listen_sd, 1);
+ if (ret != 0) {
+ g_warning ("pi_listen: %s", strerror (errno));
+ if (error)
+ *error = 2;
+ pi_close(listen_sd);
+ return 0;
+ }
}
sd = pi_accept_to (listen_sd, NULL,0, device->timeout);
@@ -198,7 +193,9 @@
if (error)
*error = 0;
- pi_close(listen_sd);
+ if (device->type != PILOT_DEVICE_NETWORK) {
+ pi_close(listen_sd);
+ }
return sd;
}
@@ -737,9 +734,10 @@
if (context->paused) {
return FALSE;
}
- g_message (_("Woke on %s"),device->name);
+ g_message (_("Woke on network: %s"),device->name);
result = sync_device (device,context);
+
return result;
}
@@ -777,9 +775,10 @@
device = element->data;
- gpilot_gui_warning_dialog ("Device error on %s (%s)\n"
- "Caught %s",device->name,device->port,tmp);
- g_warning ("Device error on %s (%s), caught %s",device->name,device->port,tmp);
+ gpilot_gui_warning_dialog (_("Device error on %s, Caught %s."),
+ device->name, tmp);
+ g_warning ("Device error on %s, caught %s",device->name,
+ tmp);
remove_device (context,device);
g_free (tmp);
@@ -974,7 +973,7 @@
}
if (dev->type == PILOT_DEVICE_NETWORK) {
- g_message (_("Watching %s (%s, %s)"), dev->name, dev->ip, dev->host);
+ g_message (_("Watching %s (%s)"), dev->name, dev->ip);
} else {
g_message (_("Watching %s (%s)"),dev->name,dev->port);
}
|