home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 August / PCO0897.ISO / filesbbs / os2 / plnk065.arj / PLNK065.ZIP / pilot-link.0.6.5 / install-user.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-16  |  2.5 KB  |  105 lines

  1. /* install-user.c:  User name
  2.  *
  3.  * This is free software, licensed under the GNU Public License V2.
  4.  * See the file COPYING for details.
  5.  */
  6.  
  7. /* Note: if you use this program to change the user name on the Pilot, I
  8.  * _highly_ reccomend that you perform a hard reset before HotSyncing with a
  9.  * Windows machine. This is because the user-id information has only been
  10.  * partially altered, and it is not worth trying to predict what the Desktop
  11.  * will do. - KJA
  12.  */
  13.  
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include "pi-source.h"
  18. #include "pi-socket.h"
  19. #include "pi-dlp.h"
  20.  
  21. int main(int argc, char *argv[])
  22. {
  23.   struct pi_sockaddr addr;
  24.   int sd;
  25.   struct PilotUser U;
  26.   struct SysInfo S;
  27.   struct CardInfo C;
  28.   unsigned long romversion;
  29.   int ret;
  30.  
  31.   if (argc < 2) {
  32.     fprintf(stderr,"usage:%s %s [User name [User ID]]\n",argv[0],TTYPrompt);
  33.     exit(2);
  34.   }
  35.  
  36.   if (!(sd = pi_socket(PI_AF_SLP, PI_SOCK_STREAM, PI_PF_PADP))) {
  37.     perror("pi_socket");
  38.     exit(1);
  39.   }
  40.     
  41.   addr.pi_family = PI_AF_SLP;
  42.   addr.pi_port = 3;
  43.   strcpy(addr.pi_device,argv[1]);
  44.   
  45.   ret = pi_bind(sd, &addr, sizeof(addr));
  46.   if(ret == -1) {
  47.     perror("pi_bind");
  48.     exit(1);
  49.   }
  50.   
  51.   fprintf(stderr, "Waiting for connection (press the HotSync button now)...\n");
  52.   
  53.   ret = pi_listen(sd, 1);
  54.   if(ret == -1) {
  55.     perror("pi_listen");
  56.     exit(1);
  57.   }
  58.  
  59.   sd = pi_accept(sd, 0, 0);
  60.   if(sd < 0) {
  61.     perror("pi_accept");
  62.     exit(1);
  63.   }
  64.   
  65.   /* Tell user (via Pilot) that we are starting things up */
  66.   dlp_OpenConduit(sd);
  67.  
  68.   dlp_ReadUserInfo(sd, &U);
  69.   
  70.   dlp_ReadSysInfo(sd, &S);
  71.   
  72.   C.cardno = -1;
  73.   C.more = 1;
  74.   while(C.more) {
  75.     if(dlp_ReadStorageInfo(sd, C.cardno+1, &C)<0)
  76.       break;
  77.     
  78.     printf(" Card #%d has %lu bytes of ROM, and %lu bytes of RAM (%lu of that is free)\n",
  79.        C.cardno, C.ROMsize, C.RAMsize, C.RAMfree);
  80.     printf(" It is called '%s', and was made by '%s'.\n", C.name, C.manuf);
  81.   }
  82.   
  83.  
  84.   if (argc == 2) {
  85.     printf ("Pilot user %s\n",U.username);
  86.     printf("UserID %ld \n", U.userID );
  87.   }
  88.   else {
  89.     strcpy(U.username, argv[2]);
  90.     if (argc == 4) { U.userID = atoi(argv[3]); }
  91.     U.lastSyncDate = time( (time_t *)0);
  92.     dlp_WriteUserInfo(sd, &U);
  93.   }
  94.   
  95.   printf( "Through ReadSysInfo: ROM Version: 0x%8.8lX, locale: 0x%8.8lX, name: '%s'\n", 
  96.               S.ROMVersion, S.localizationID, S.name);
  97.  
  98.   dlp_ReadFeature(sd, makelong("psys"), 1, &romversion);
  99.   
  100.   printf( "ROM Version through ReadFeature: 0x%8.8lX\n", romversion);
  101.   
  102.   pi_close(sd);
  103.   exit(0);
  104. }
  105.