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 /* From pi-csd */ -#include #include #include -#include +/*#include */ #include #include +#include #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); }