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.orig < prev    next >
Encoding:
Text File  |  1997-05-23  |  2.4 KB  |  103 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.   ret = pi_listen(sd, 1);
  52.   if(ret == -1) {
  53.     perror("pi_listen");
  54.     exit(1);
  55.   }
  56.  
  57.   sd = pi_accept(sd, 0, 0);
  58.   if(sd < 0) {
  59.     perror("pi_accept");
  60.     exit(1);
  61.   }
  62.   
  63.   /* Tell user (via Pilot) that we are starting things up */
  64.   dlp_OpenConduit(sd);
  65.  
  66.   dlp_ReadUserInfo(sd, &U);
  67.   
  68.   dlp_ReadSysInfo(sd, &S);
  69.   
  70.   C.cardno = -1;
  71.   C.more = 1;
  72.   while(C.more) {
  73.     if(dlp_ReadStorageInfo(sd, C.cardno+1, &C)<0)
  74.       break;
  75.     
  76.     printf(" Card #%d has %lu bytes of ROM, and %lu bytes of RAM (%lu of that is free)\n",
  77.        C.cardno, C.ROMsize, C.RAMsize, C.RAMfree);
  78.     printf(" It is called '%s', and was made by '%s'.\n", C.name, C.manuf);
  79.   }
  80.   
  81.  
  82.   if (argc == 2) {
  83.     printf ("Pilot user %s\n",U.username);
  84.     printf("UserID %ld \n", U.userID );
  85.   }
  86.   else {
  87.     strcpy(U.username, argv[2]);
  88.     if (argc == 4) { U.userID = atoi(argv[3]); }
  89.     U.lastSyncDate = time( (time_t *)0);
  90.     dlp_WriteUserInfo(sd, &U);
  91.   }
  92.   
  93.   printf( "Through ReadSysInfo: ROM Version: 0x%8.8lX, locale: 0x%8.8lX, name: '%s'\n", 
  94.               S.ROMVersion, S.localizationID, S.name);
  95.  
  96.   dlp_ReadFeature(sd, makelong("psys"), 1, &romversion);
  97.   
  98.   printf( "ROM Version through ReadFeature: 0x%8.8lX\n", romversion);
  99.   
  100.   pi_close(sd);
  101.   exit(0);
  102. }
  103.