Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 84890
Collapse All | Expand All

(-)gnome-pilot-2.0.12.old/capplet/pilot.c (-6 lines)
Lines 155-164 Link Here
155
		  if (device->type == PILOT_DEVICE_NETWORK) {
155
		  if (device->type == PILOT_DEVICE_NETWORK) {
156
			  device->ip = gnome_config_get_string ("ip");
156
			  device->ip = gnome_config_get_string ("ip");
157
			  g_message ("cradle network ip -> %s", device->ip);
157
			  g_message ("cradle network ip -> %s", device->ip);
158
			  device->ip = gnome_config_get_string ("host");
159
			  g_message ("cradle network host name -> %s", device->host);
160
			  device->ip = gnome_config_get_string ("netmask");
161
			  g_message ("cradle network mask -> %s", device->netmask);
162
		  } else {
158
		  } else {
163
			  device->port = gnome_config_get_string ("device");
159
			  device->port = gnome_config_get_string ("device");
164
			  g_message ("cradle device name -> %s", device->port);
160
			  g_message ("cradle device name -> %s", device->port);
Lines 286-293 Link Here
286
	  gnome_config_set_string ("name", device->name);
282
	  gnome_config_set_string ("name", device->name);
287
	  if (device->type == PILOT_DEVICE_NETWORK) {
283
	  if (device->type == PILOT_DEVICE_NETWORK) {
288
		  gnome_config_set_string ("ip", device->ip);
284
		  gnome_config_set_string ("ip", device->ip);
289
		  gnome_config_set_string ("host", device->host);
290
		  gnome_config_set_string ("netmask", device->netmask);
291
	  } else {
285
	  } else {
292
		  gnome_config_set_string ("device", device->port);
286
		  gnome_config_set_string ("device", device->port);
293
		  gnome_config_set_int ("speed", device->speed);
287
		  gnome_config_set_int ("speed", device->speed);
(-)gnome-pilot-2.0.12.old/gpilotd/gnome-pilot-structures.c (-218 / +44 lines)
Lines 38-49 Link Here
38
#include <signal.h>
38
#include <signal.h>
39
39
40
/* From pi-csd */
40
/* From pi-csd */
41
#include <signal.h>
42
#include <sys/socket.h>
41
#include <sys/socket.h>
43
#include <netinet/in.h>
42
#include <netinet/in.h>
44
#include <net/if.h>
43
/*#include <net/if.h>*/
45
#include <arpa/inet.h>
44
#include <arpa/inet.h>
46
#include <netdb.h>
45
#include <netdb.h>
46
#include <pi-source.h>
47
47
48
#define LOCK_DIR "/var/lock"
48
#define LOCK_DIR "/var/lock"
49
#define LOCK_BINARY 0
49
#define LOCK_BINARY 0
Lines 380-533 Link Here
380
380
381
#ifdef WITH_NETWORK
381
#ifdef WITH_NETWORK
382
382
383
/* 
384
 * pi-csd.c: Connection Service Daemon, required for accepting 
385
 *           logons via NetSync (tm)
386
 * Copyright (c) 1997, Kenneth Albanowski
387
 *
388
 * While this function is useful in pi-csd, it is intended also to
389
 * be a demonstration of the proper (or improper, if I'm unlucky) techniques
390
 * to retrieve networking information.
391
 */
392
static void
393
fetch_host (char *hostname, int hostlen, struct in_addr *address,
394
	   struct in_addr *mask)
395
{
396
#if defined (SIOCGIFCONF) && defined (SIOCGIFFLAGS)
397
	int s, n, i;
398
	struct ifconf ifc;
399
	struct ifreq *ifr, ifreqaddr, ifreqmask;
400
#endif
401
	struct hostent *hent;
402
403
#ifdef HAVE_GETHOSTNAME
404
	/* Get host name the easy way */
405
406
	gethostname (hostname, hostlen);
407
#else
408
# ifdef HAVE_UNAME
409
	struct utsname uts;
410
411
	if (uname (&uts) == 0) {
412
		strncpy (hostname, uts.nodename, hostlen - 1);
413
		hostname[hostlen - 1] = '\0';
414
	}
415
# endif	/*def HAVE_UNAME */
416
#endif /*def HAVE_GETHOSTNAME */
417
418
	/* Get host address through DNS */
419
	hent = gethostbyname (hostname);
420
421
	if (hent) {
422
		while (*hent->h_addr_list) {
423
			struct in_addr haddr;
424
425
			memcpy (&haddr, *(hent->h_addr_list++), sizeof (haddr));
426
			if (haddr.s_addr != inet_addr ("127.0.0.1"))
427
				memcpy (address, &haddr, sizeof (haddr));
428
		}
429
	}
430
#if defined (SIOCGIFCONF) && defined (SIOCGIFFLAGS)
431
	s = socket (AF_INET, SOCK_DGRAM, 0);
432
433
	if (s < 0)
434
		return;
435
436
	ifc.ifc_buf = calloc (1024, 1);
437
	ifc.ifc_len = 1024;
438
439
	if (ioctl (s, SIOCGIFCONF, (char *) &ifc) < 0)
440
		goto done;
441
442
	n = ifc.ifc_len;
443
	for (i = 0; i < n; i += ifreq_size (*ifr)) {
444
		struct sockaddr_in *a;
445
		struct sockaddr_in *b;
446
447
		ifr = (struct ifreq *) ((caddr_t) ifc.ifc_buf + i);
448
		a = (struct sockaddr_in *) &ifr->ifr_addr;
449
		strncpy (ifreqaddr.ifr_name, ifr->ifr_name, sizeof (ifreqaddr.ifr_name));
450
		strncpy (ifreqmask.ifr_name, ifr->ifr_name, sizeof (ifreqmask.ifr_name));
451
452
		if (ioctl (s, SIOCGIFFLAGS, (char *) &ifreqaddr) < 0)
453
			continue;
454
455
		/* Reject loopback device */
456
#ifdef IFF_LOOPBACK
457
		if (ifreqaddr.ifr_flags & IFF_LOOPBACK)
458
			continue;
459
#endif /*def IFF_LOOPBACK */
460
461
#ifdef IFF_UP
462
		/* Reject down devices */
463
		if (!(ifreqaddr.ifr_flags & IFF_UP))
464
			continue;
465
#endif /*def IFF_UP */
466
467
		if (ifr->ifr_addr.sa_family != AF_INET)
468
			continue;
469
470
		/* If it is a point-to-point device, use the dest address */
471
#if defined (IFF_POINTOPOINT) && defined (SIOCGIFDSTADDR)
472
		if (ifreqaddr.ifr_flags & IFF_POINTOPOINT) {
473
			if (ioctl (s, SIOCGIFDSTADDR, (char *) &ifreqaddr) < 0)
474
				break;
475
476
			a = (struct sockaddr_in *) &ifreqaddr.ifr_dstaddr;
477
478
			if (address->s_addr == 0) {
479
				memcpy (address, &a->sin_addr, sizeof (struct in_addr));
480
			}
481
		}
482
		else
483
#endif /*defined (IFF_POINTOPOINT) && defined (SIOCGIFDSTADDR) */
484
			/* If it isn't a point-to-point device, use the address */
485
#ifdef SIOCGIFADDR
486
		{
487
			if (ioctl (s, SIOCGIFADDR, (char *) &ifreqaddr) < 0)
488
				break;
489
490
			a = (struct sockaddr_in *) &ifreqaddr.ifr_addr;
491
492
			if (address->s_addr == 0) {
493
				memcpy (address, &a->sin_addr, sizeof (struct in_addr));
494
			}
495
		}
496
#endif /*def SIOCGIFADDR */
497
		/* OK, we've got an address */
498
499
		/* Compare netmask against the current address and see if it seems to match. */
500
#ifdef SIOCGIFNETMASK
501
		if (ioctl (s, SIOCGIFNETMASK, (char *) &ifreqmask) < 0)
502
			break;
503
504
/* Is there any system where we need to use ifr_netmask?  */
505
#if 1
506
		b = (struct sockaddr_in *) &ifreqmask.ifr_addr;
507
#else
508
		b = (struct sockaddr_in *) &ifreqmask.ifr_netmask;
509
#endif
510
511
		if ((mask->s_addr == 0) && (address->s_addr != 0)) {
512
			if ((b->sin_addr.s_addr & a->sin_addr.s_addr) ==
513
			    (b->sin_addr.s_addr & address->s_addr)) {
514
				memcpy (mask, &b->sin_addr, sizeof (struct in_addr));
515
516
				/* OK, we've got a netmask */
517
518
				break;
519
			}
520
		}
521
#endif /*def SIOCGIFNETMASK */
522
523
	}
524
525
 done:
526
	free (ifc.ifc_buf);
527
	close (s);
528
#endif /*defined (SIOCGIFCONF) && defined (SIOCGIFFLAGS) */
529
}
530
531
/* gpilot_network_device_init (GPilotDevice *device)
383
/* gpilot_network_device_init (GPilotDevice *device)
532
 * pi-csd.c: Connection Service Daemon, required for accepting 
384
 * pi-csd.c: Connection Service Daemon, required for accepting 
533
 *           logons via NetSync (tm)
385
 *           logons via NetSync (tm)
Lines 537-620 Link Here
537
static gint 
389
static gint 
538
gpilot_network_device_init (GPilotDevice *device)
390
gpilot_network_device_init (GPilotDevice *device)
539
{
391
{
540
/*
392
	struct pi_sockaddr addr;
541
 * Open a file descriptor. device->fd
542
 * Check fd. return -1 if fail.
543
 * device->io = g_io_channel_unix_new (device->fd);
544
 * g_io_channel_ref (device->io);
545
 * return 0;
546
 *
547
 */
548
393
549
/* char hostname[130];	this is device->host */
394
	char pi_net[100];
550
	struct in_addr address, netmask;
551
395
552
396
	memset(pi_net, 0, sizeof(pi_net));
553
/*   int sockfd;	this is device->fd */
397
	strncpy(pi_net, "net:", 4);
554
	struct sockaddr_in serv_addr;
398
	if (device->ip != NULL && (strnlen(device->ip, 1) > 0)) {
555
399
		struct 	sockaddr_in serv_addr;
556
	struct hostent *hent;
400
		/* Verify the IP address is valid */
557
/*   int quiet = 0;		It's Always quiet here */
401
		memset(&serv_addr, 0, sizeof(serv_addr));
558
402
		serv_addr.sin_family = AF_INET;
559
	memset (&address, 0, sizeof (address));
403
		serv_addr.sin_addr.s_addr = inet_addr(device->ip);
560
	memset (&netmask, 0, sizeof (netmask));
404
		if (serv_addr.sin_addr.s_addr == (in_addr_t)-1) {
561
405
			struct hostent *hostent = gethostbyname(device->ip);
562
/*   hostname[0] = 0; */
406
		
563
/* device->host = g_new (gchar, 130);
407
			if (!hostent) {
564
   g_free (device->host);
408
				g_warning ("Device [%s]: Bad IP address/hostname: %s", 
565
*/
409
				    device->name, device->ip);
566
410
				return -1;
567
/* This is used if the hostname is not correct in the conf file
411
			}
568
   I'll move it to the conf file saving later */
569
	fetch_host (device->host, 128, &address, &netmask); 
570
	
571
/* device->host I already have from the config file */
572
573
	if (inet_aton (device->ip, &address) == 0) /* Invalid */
574
	{
575
		if ((hent = gethostbyname (device->ip))) {
576
			memcpy (&address.s_addr, hent->h_addr, sizeof (address));
577
		} else {
578
			g_message ("Invalid ip address '%s'", device->ip);
579
			return -1;
580
		}
412
		}
581
	}
582
413
583
	if (inet_aton (device->netmask, &netmask) == 0) {
414
		strncat(pi_net, device->ip, sizeof(pi_net) - 2 - strlen(pi_net));
584
		g_message ("Invalid netmask '%s'", device->netmask);
415
	} else {
585
		return -1;
416
		strncat(pi_net, "any", 3);
586
	}
417
	}
587
418
	device->fd = pi_socket (PI_AF_PILOT, PI_SOCK_STREAM, PI_PF_NET);
588
	/* cannot execute without address and hostname */
419
	if (device->fd < 0) {
589
	if ((address.s_addr == 0) || (strlen (device->host) == 0))
420
		g_warning ("Device [%s, %s]: Unable to get socket: %s", 
590
	{
421
		    device->name, pi_net, strerror(errno));
591
		g_message ("Cannot execute without ip address and hostname.");
592
		return -1;
422
		return -1;
593
	}
423
	}
594
424
595
	device->fd = socket (AF_INET, SOCK_DGRAM, 0);
425
	strncpy (addr.pi_device,pi_net, strlen(pi_net));
596
	if (device->fd < 0) {
426
597
		g_message ("Unable to get socket");
427
	if (pi_bind (device->fd, (struct sockaddr*)&addr, sizeof (addr)) < 0) {
428
		g_warning ("Device [%s, %s]: Unable to bind socket",
429
		    device->name, pi_net);
598
		return -1;
430
		return -1;
599
	}
431
	}
600
432
601
	memset (&serv_addr, 0, sizeof (serv_addr));
433
	/* Now listen for incoming connections */
602
	serv_addr.sin_family = AF_INET;
434
	if (pi_listen (device->fd, 1) != 0) {
603
	serv_addr.sin_addr.s_addr = htonl (INADDR_ANY);
435
		g_warning ("Device [%s, %s]: Error from listen: %s",
604
	serv_addr.sin_port = htons (14237);
436
		    device->name, pi_net, strerror (errno));
605
437
		close(device->fd);
606
	if (bind (device->fd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) < 0) {
607
		g_message ("Unable to bind socket");
608
		return -1;
438
		return -1;
609
	}
439
	}
610
	/*
611
	g_message ("Connection Service Daemon for Palm Computing (tm) device active.");
612
	g_message ("Accepting connection requests for '%s' at %s with mask %s", 
613
		   device->host, inet_ntoa (address), inet_ntoa (netmask));
614
	*/
615
440
616
	/* We don't want to infinite loops here */
441
	/* Register an interest in the socket, to get events when devices connect */
617
	/* Lets try something else instead */
618
	device->io = g_io_channel_unix_new (device->fd);
442
	device->io = g_io_channel_unix_new (device->fd);
619
	g_io_channel_ref (device->io);
443
	g_io_channel_ref (device->io);
620
444
Lines 630-642 Link Here
630
	}
454
	}
631
455
632
	g_free(device->ip);
456
	g_free(device->ip);
633
	g_free(device->host);
634
	g_free(device->netmask);
635
}
457
}
636
458
637
static void
459
static void
638
gpilot_network_device_deinit (GPilotDevice *device)
460
gpilot_network_device_deinit (GPilotDevice *device)
639
{
461
{
462
	if (device->io) {
463
		g_source_remove (device->in_handle);
464
		g_source_remove (device->err_handle);
465
		g_io_channel_close (device->io);
466
		g_io_channel_unref (device->io);
467
	}
640
}
468
}
641
#endif /* WITH_NETWORK */
469
#endif /* WITH_NETWORK */
642
470
Lines 680-687 Link Here
680
gpilot_network_device_load (GPilotDevice *device)
508
gpilot_network_device_load (GPilotDevice *device)
681
{
509
{
682
	device->ip = gnome_config_get_string ("ip");
510
	device->ip = gnome_config_get_string ("ip");
683
	device->host = gnome_config_get_string ("host");
684
	device->netmask = gnome_config_get_string ("netmask");
685
}
511
}
686
512
687
gint
513
gint
(-)gnome-pilot-2.0.12.old/gpilotd/gnome-pilot-structures.h (-2 lines)
Lines 90-97 Link Here
90
90
91
	/* These are used for network (man c++ is soo much cooler) */
91
	/* These are used for network (man c++ is soo much cooler) */
92
	gchar *ip;
92
	gchar *ip;
93
	gchar *host;
94
	gchar *netmask;
95
93
96
	/* These are used at runtime, to associate 
94
	/* These are used at runtime, to associate 
97
	   an opened file with the device */
95
	   an opened file with the device */
(-)gnome-pilot-2.0.12.old/gpilotd/gpilotd.c (-38 / +37 lines)
Lines 148-189 Link Here
148
		break;
148
		break;
149
	}
149
	}
150
	
150
	
151
	if (!(listen_sd = pi_socket (PI_AF_PILOT, PI_SOCK_STREAM, pf))) {
152
		g_warning ("pi_socket: %s",strerror (errno));
153
		if (error) *error = 1;
154
		return -1;
155
	}
156
	
157
	addr.pi_family = PI_AF_PILOT;
158
159
/*
160
	Most important for networking
161
	. resolves inside libpisock as network
162
	It is done earlier in gpilotd_device_init
163
	so don't really need to do it again here.
164
*/
165
	if (device->type == PILOT_DEVICE_NETWORK) {
151
	if (device->type == PILOT_DEVICE_NETWORK) {
166
		device->port = "net:any";
152
		/* we've already got a listen, so move on to accept */
167
	}
153
		listen_sd = device->fd;
154
	} else {
155
		if (!(listen_sd = pi_socket (PI_AF_PILOT, PI_SOCK_STREAM, pf))) {
156
			g_warning ("pi_socket: %s",strerror (errno));
157
			if (error) *error = 1;
158
			return -1;
159
		}
160
		
161
		addr.pi_family = PI_AF_PILOT;
168
162
169
	strcpy (addr.pi_device,device->port);
163
		strcpy (addr.pi_device,device->port);
170
164
171
	ret = pi_bind (listen_sd, (struct sockaddr*)&addr, sizeof (addr));
165
		ret = pi_bind (listen_sd, (struct sockaddr*)&addr, sizeof (addr));
172
	if (ret == -1) {
166
		if (ret == -1) {
173
		g_warning (_("Unable to bind to pilot"));
167
			g_warning (_("Unable to bind to pilot"));
174
		if (error)
168
			if (error)
175
			*error = 1;
169
				*error = 1;
176
		pi_close(listen_sd);
170
			pi_close(listen_sd);
177
		return 0;
171
			return 0;
178
	}
172
		}
179
173
180
	ret = pi_listen (listen_sd, 1);
174
		ret = pi_listen (listen_sd, 1);
181
	if (ret != 0) {
175
		if (ret != 0) {
182
		g_warning ("pi_listen: %s", strerror (errno));
176
			g_warning ("pi_listen: %s", strerror (errno));
183
		if (error)
177
			if (error)
184
			*error = 2;
178
				*error = 2;
185
		pi_close(listen_sd);
179
			pi_close(listen_sd);
186
		return 0;
180
			return 0;
181
		}
187
	}
182
	}
188
183
189
	sd = pi_accept_to (listen_sd, NULL,0, device->timeout); 
184
	sd = pi_accept_to (listen_sd, NULL,0, device->timeout); 
Lines 198-204 Link Here
198
193
199
	if (error)
194
	if (error)
200
		*error = 0;
195
		*error = 0;
201
	pi_close(listen_sd);
196
	if (device->type != PILOT_DEVICE_NETWORK) {
197
		pi_close(listen_sd);
198
	}
202
	
199
	
203
	return sd;
200
	return sd;
204
}
201
}
Lines 737-745 Link Here
737
	if (context->paused) {
734
	if (context->paused) {
738
		return FALSE; 
735
		return FALSE; 
739
	}	
736
	}	
740
	g_message (_("Woke on %s"),device->name);
737
	g_message (_("Woke on network: %s"),device->name);
741
	result = sync_device (device,context);
738
	result = sync_device (device,context);
742
739
740
743
	return result;
741
	return result;
744
}
742
}
745
743
Lines 777-785 Link Here
777
	
775
	
778
	device = element->data;
776
	device = element->data;
779
777
780
	gpilot_gui_warning_dialog ("Device error on %s (%s)\n"
778
	gpilot_gui_warning_dialog (_("Device error on %s, Caught %s."),
781
				  "Caught %s",device->name,device->port,tmp); 
779
	    device->name, tmp);
782
	g_warning ("Device error on %s (%s), caught %s",device->name,device->port,tmp);
780
	g_warning ("Device error on %s, caught %s",device->name,
781
	    tmp);
783
782
784
	remove_device (context,device);
783
	remove_device (context,device);
785
	g_free (tmp);
784
	g_free (tmp);
Lines 974-980 Link Here
974
	}
973
	}
975
974
976
	if (dev->type == PILOT_DEVICE_NETWORK) {
975
	if (dev->type == PILOT_DEVICE_NETWORK) {
977
		g_message (_("Watching %s (%s, %s)"), dev->name, dev->ip, dev->host);
976
		g_message (_("Watching %s (%s)"), dev->name, dev->ip);
978
	} else {
977
	} else {
979
		g_message (_("Watching %s (%s)"),dev->name,dev->port);
978
		g_message (_("Watching %s (%s)"),dev->name,dev->port);
980
	}
979
	}

Return to bug 84890