home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / mac / programm / 14896 < prev    next >
Encoding:
Text File  |  1992-09-02  |  5.0 KB  |  200 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!stanford.edu!leland.Stanford.EDU!bolo.stanford.edu!cheshire
  3. From: Stuart Cheshire <cheshire@cs.stanford.edu>
  4. Subject: Re: Looking for some sample appletalk ATP code...
  5. Message-ID: <1992Sep2.181108.3750@leland.Stanford.EDU>
  6. X-Xxmessage-Id: <A6CA51C584030010@bolo.stanford.edu>
  7. X-Xxdate: Wed, 2 Sep 92 19:11:01 GMT
  8. Sender: news@leland.Stanford.EDU (Mr News)
  9. Organization: Stanford University
  10. X-Useragent: Nuntius v1.1.1d7
  11. References: <1992Sep1.033635.28604@sunb10.cs.uiuc.edu>
  12. Date: Wed, 2 Sep 92 18:11:08 GMT
  13. Lines: 185
  14.  
  15. In article <1992Sep1.033635.28604@sunb10.cs.uiuc.edu> Alex Bratton,
  16. bratton@sparc3.cs.uiuc.edu writes:
  17. >If you have some sample code (ATP) that opens, registers, and dumps some
  18. >data, I'd really appreciate seeing it.  This has been bugging me for a
  19. while
  20. >and I think I need to look at some working code to see what I'm missing.
  21.  
  22. Here is some more sample code, which opens and registers an ATP socket.
  23. It is from the Macintosh User Authenticator mentioned in a previous post
  24. be me.
  25.  
  26. The code is written for Think C 5.
  27.  
  28. #include <Traps.h>
  29. #include <GestaltEqu.h>
  30. #include <Folders.h>
  31. #include <AppleTalk.h>
  32.  
  33. #define local static
  34. #define export
  35. #define import extern
  36. typedef unsigned char  BYTE;
  37. typedef unsigned short WORD;
  38. typedef unsigned long  DWORD;
  39. #define until(A) while (!(A))
  40.  
  41. typedef struct
  42.     {
  43.     BYTE sysLAPAddr;
  44.     BYTE destnode;
  45.     BYTE srcnode;
  46.     BYTE ALAPproto;
  47.     WORD length;
  48.     union
  49.         {
  50.         struct
  51.             {
  52.             BYTE destsocket;
  53.             BYTE srcsocket;
  54.             BYTE DPPproto;
  55.             BYTE userdata[15];
  56.             } shortheader;
  57.         struct
  58.             {
  59.             WORD checksum;
  60.             WORD destnet;
  61.             WORD srcnet;
  62.             BYTE destnode;
  63.             BYTE srcnode;
  64.             BYTE destsocket;
  65.             BYTE srcsocket;
  66.             BYTE DPPproto;
  67.             BYTE userdata[7];
  68.             } longheader;
  69.         } u;
  70.     BYTE unused;
  71.     BYTE sysABridge;
  72.     WORD sysNetNum;
  73.     WORD vSCCEnable;
  74.     } MPPglobals;
  75.  
  76. extern MPPglobals *ABusVars : 0x2D8;
  77.  
  78. typedef struct
  79.     {
  80.     ATPParamBlock p;
  81.     long *myglobals;
  82.     } myATPParamBlock;
  83.  
  84. local NamesTableEntry myNTE;    /* DONT TOUCH THIS -- IT'S USED CONTINUOUSLY
  85. BY NBP */
  86.  
  87. // name must be 8 characters long
  88. local void construct_name(AddrBlock addr, unsigned char *name)
  89.     {
  90.     static unsigned char hextable[] = "0123456789ABCDEF";
  91.     name[0] = 7;
  92.     name[1] = hextable[(addr.aNet  >> 12) & 0xF];
  93.     name[2] = hextable[(addr.aNet  >>  8) & 0xF];
  94.     name[3] = hextable[(addr.aNet  >>  4) & 0xF];
  95.     name[4] = hextable[(addr.aNet  >>  0) & 0xF];
  96.     name[5] = '.';
  97.     name[6] = hextable[(addr.aNode >>  4) & 0xF];
  98.     name[7] = hextable[(addr.aNode >>  0) & 0xF];
  99.     }
  100.  
  101. local void awaitrequest(void);
  102. local void acceptrequest(void)
  103.     {
  104.     static char dummy;
  105.     static BDSElement bds;
  106.     
  107.     myATPParamBlock *atp_pb;
  108.     long *saveGptr;
  109.     asm    {    move.l    GLOBREG, saveGptr
  110.             move.l    a0, atp_pb
  111.             move.l    myATPParamBlock.myglobals(a0), GLOBREG
  112.         }
  113.     
  114.     // if (atp_pb->p.ATPioResult) What to do if error?
  115.  
  116. // do whatever you want here to prepare your response...
  117.     
  118.     bds.buffSize  = sizeof(dummy);
  119.     bds.buffPtr   = (Ptr)&dummy;
  120.     bds.dataSize  = 0;
  121.     bds.userBytes = 0;
  122.     
  123.     atp_pb->p.ATPioCompletion = awaitrequest;
  124.     atp_pb->p.ATPatpFlags   = atpEOMvalue;
  125.     atp_pb->p.ATPbdsPointer = (Ptr)&bds;
  126.     atp_pb->p.ATPnumOfBuffs = 1;
  127.     atp_pb->p.ATPbdsSize    = 1;
  128.     
  129.     PSendResponse(&atp_pb->p, TRUE);
  130.  
  131.     asm { move.l saveGptr, GLOBREG }
  132.     }
  133.  
  134. local void awaitrequest(void)
  135.     {
  136.     static MACAUTH_REQUEST req;
  137.     myATPParamBlock *atp_pb;
  138.     long *saveGptr;
  139.     asm    {    move.l    GLOBREG, saveGptr
  140.             move.l    a0, atp_pb
  141.             move.l    myATPParamBlock.myglobals(a0), GLOBREG
  142.         }
  143.     atp_pb->p.ATPioCompletion = acceptrequest;
  144.     atp_pb->p.ATPatpSocket    = myNTE.nt.nteAddress.aSocket;
  145.     atp_pb->p.ATPreqLength    = sizeof(req);
  146.     atp_pb->p.ATPreqPointer   = (Ptr)&req;
  147.     PGetRequest(&atp_pb->p, TRUE);
  148.     asm { move.l saveGptr, GLOBREG }
  149.     }
  150.  
  151. local OSErr AppleTalkInit(void)    // returns non-zero if init failed
  152.     {
  153.     OSErr retcode;
  154.     short MPPRefNum;
  155.     MPPParamBlock p;
  156.     ATPParamBlock atp;
  157.     static myATPParamBlock req_pb;
  158.     static AddrBlock zeroaddress;
  159.     static unsigned char regname[8];
  160.     
  161.     if (retcode = OpenDriver("\p.MPP", &MPPRefNum))
  162.         { DebugStr("\pCouldn't open AppleTalk driver"); return(retcode); }
  163.  
  164.     p.SETSELF.newSelfFlag = TRUE;
  165.     PSetSelfSend(&p, FALSE);     // no need to abort if this fails
  166.     
  167.     atp.ATPatpSocket = 0;
  168.     atp.ATPaddrBlock = zeroaddress;
  169.     if (retcode = POpenATPSkt(&atp, FALSE))
  170.         { DebugStr("\pCouldn't open ATP socket"); return(retcode); }
  171.  
  172.     myNTE.nt.nteAddress.aNet    = ABusVars->sysNetNum;
  173.     myNTE.nt.nteAddress.aNode   = ABusVars->sysLAPAddr;
  174.     myNTE.nt.nteAddress.aSocket = atp.ATPatpSocket;
  175.     
  176.     construct_name(myNTE.nt.nteAddress, regname);
  177.  
  178.     NBPSetNTE((Ptr)&myNTE,
  179.         (Ptr)regname, (Ptr)"\pMacintosh Authenticator", (Ptr)"\p*",
  180.         myNTE.nt.nteAddress.aSocket);
  181.     
  182.     p.NBPinterval    = 2;
  183.     p.NBPcount       = 2;
  184.     p.NBPntQElPtr    = (Ptr)&myNTE;
  185.     p.NBPverifyFlag  = TRUE;
  186.     if (retcode = PRegisterName(&p, FALSE))
  187.         { DebugStr("\pCouldn't Register name"); return(retcode); }
  188.  
  189.     asm    {    move.l    GLOBREG, req_pb.myglobals
  190.             lea        req_pb, a0
  191.             bsr        awaitrequest
  192.         }
  193.     }
  194.  
  195.  
  196. Stuart Cheshire <cheshire@cs.stanford.edu>
  197.  * Liliore Green Rains Houses Resident Computer Coordinator
  198.  * Stanford Distributed Systems Group Research Assistant
  199.  * Macintosh Programmer
  200.