home *** CD-ROM | disk | FTP | other *** search
/ sustworks.com / 2014.06.sustworks.com.tar / sustworks.com / SetupAP.cp.sit.hqx / SetupAP.cp next >
Text File  |  1996-08-29  |  3KB  |  98 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. #include <OpenTransport.h>
  6. #include <OpenTptInternet.h>
  7. #include <OpenTptDevLinks.h>
  8. #include <stropts.h>
  9.  
  10. // open stream flags (read/write)
  11. #define O_RDWR                0x02
  12. #define debugMe false
  13.  
  14. // forward function declaration
  15. void SetupAutopush(Boolean pushOn);
  16.  
  17.  
  18. // ---------------------------------------------------------------------------
  19. //        Ñ Main
  20. // ---------------------------------------------------------------------------
  21. //    Just setup autopush and exit
  22. void main(void)
  23. {
  24.     if (debugMe) printf ("\nHello World, this is SetupAP");
  25.  
  26.     // Setup to autopush our Proxy module on top of the PPP link
  27.     SetupAutopush(false);    // remove any previous autopush
  28.     SetupAutopush(true);
  29.     
  30.     if (debugMe) printf ("\nGoodbye");
  31. }
  32.  
  33.  
  34.  
  35. // ---------------------------------------------------------------------------
  36. //        Ñ SetupAutopush
  37. // ---------------------------------------------------------------------------
  38. //    Setup to Autopush or not Autopush our Proxy module on top of the PPP link
  39. void
  40. SetupAutopush(Boolean pushOn)
  41. {
  42.     OSStatus        err = kOTNoError;
  43.     OTPortRecord    portInfo;
  44.     UInt32            index;
  45.     UInt16            deviceType;
  46.  
  47.  
  48.     // open a stream to the sad device
  49.     StreamRef myStreamRef = OTStreamOpen(kSADModuleName, O_RDWR, &err);
  50.     if (err != noErr) {
  51.         printf ("\nSetupAP: unable to open stream to sad device.");
  52.         return;
  53.     }
  54.     
  55.     // Scan available ports
  56.     index = 0;
  57.     deviceType = 0;
  58.     while (OTGetIndexedPort(&portInfo, index)) {
  59.         deviceType = OTGetDeviceTypeFromPortRef(portInfo.fRef);
  60.         index += 1;
  61.     
  62.         // setup target devices for autopush
  63.         if ((deviceType == kOTPPPDevice) ||
  64.             (deviceType == kOTSLIPDevice) ||
  65.             (deviceType == kOTMDEVDevice)) {
  66.             // setup autopush info structure
  67.             OTAutopushInfo myAutopushInfo;
  68.             if (pushOn) myAutopushInfo.sap_cmd = kSAP_ALL;    // Autopush or not?
  69.             else myAutopushInfo.sap_cmd = kSAP_CLEAR;
  70.             strcpy((char*)myAutopushInfo.sap_device_name,
  71.                 portInfo.fModuleName);    // name of data link module
  72.             myAutopushInfo.sap_minor = 0;
  73.             myAutopushInfo.sap_lastminor = 0;
  74.             myAutopushInfo.sap_npush = 1;    // number of modules to push
  75.             strcpy((char*)myAutopushInfo.sap_list[0], "Proxym");    // name of module to push
  76.  
  77.             // send ioctl to set autopush info
  78.             struct strioctl stri;
  79.             stri.ic_cmd = I_SAD_SAP;
  80.             stri.ic_dp    = (char*)&myAutopushInfo;
  81.             stri.ic_len = sizeof(OTAutopushInfo);
  82.             stri.ic_timout = -1;
  83.             err = OTStreamIoctl(myStreamRef, I_STR, (void*)&stri);
  84.             if (err != kOTNoError ) {
  85.                 if (!pushOn && (err == kENODEVErr)) {
  86.                     // The module specified is not configured for autopush,
  87.                     // so there is nothing to clear.  Ignore.
  88.                 } else {
  89.                     printf ("\nSetupAP: Set autopush ioctl failed with error code %d.", err);
  90.                 }
  91.             }
  92.         }
  93.     }
  94.  
  95.     // close SAD stream to free up resources
  96.     err = OTStreamClose(myStreamRef);
  97. }
  98.