Xref: utzoo comp.sys.mac.programmer:20917 comp.lang.c:35469 Path: utzoo!attcan!uunet!zaphod.mps.ohio-state.edu!ncar!csn!boulder!peter From: peter@boulder.Colorado.EDU (Peter A. Steinauer) Newsgroups: comp.sys.mac.programmer,comp.lang.c Subject: AppleTalk / C Programming Problem Keywords: AppleTalk, C, Macintosh Message-ID: <1991Jan9.164305.18451@csn.org> Date: 9 Jan 91 16:43:05 GMT Sender: news@csn.org Reply-To: peter@siegel.Colorado.EDU (Peter A. Steinauer) Organization: University of Colorado, Boulder Lines: 101 Nntp-Posting-Host: siegel.colorado.edu Ok everyone, I have a problem that I'm hoping someone can help me out with... I'm trying to write a simple program which will compose a packet and send it from one socket to another on the same machine (or to a socket on a different machine)... I'm able to open both the source and desination sockets but when I try to compose and send the packet DDPWrite returns a -91 in errCode which is supposed to say that the source socket isn't open... I don't understand... Could some one take a look at the following code and let me know what I'm missing. I would really appreciate it... Pete Steinauer University of Colorado Boulder ********** /* * Simple appletalk tester... This program should open up two ddp sockets * one which it will use to send a packet from and another one to send * a packet to. */ #include #include #include #include #include #define FALSE 0 #define TRUE 1 ABRecHandle myABRecHandle; ABRecPtr myABRecPtr; ABusRecord myABRecord; unsigned char mySocketsource, mySocketdest; char myBuffer[600]; char someText[255] = "This is a sample datagram"; int errCode, dataLen, index; unsigned int async, retCksumErrs, doChecksum; main() { int myNode, myNet; /* Open up AppleTalk */ errCode = MPPOpen(); /* if there was an opening error then print an error... Otherwise go on to other work */ if (errCode != noErr) printf("Error in opening AppleTalk\n"); else { /* Get the node number and net number */ errCode = GetNodeAddress(&myNode, &myNet); if (errCode != noErr) printf("Error in getting the node address \n"); else printf("Node Number: %d Net Number: %d\n", myNode, myNet); /* Open up necessary sockets */ mySocketsource = 77; mySocketdest = 78; errCode = DDPOpenSocket(&mySocketsource, NULL); printf("Source Socket number is %d\n",mySocketsource); printf("errCode is %d\n",errCode); errCode = DDPOpenSocket(&mySocketdest, NULL); printf("Destination Socket number is %d\n",mySocketdest); printf("errCode is %d\n",errCode); if (errCode != noErr) printf("Error opening socket...\n"); else { /* Prepare packet to be sent */ myABRecPtr = &myABRecord; myABRecHandle = & myABRecPtr; dataLen = strlen(someText); strcpy(myBuffer, someText); async = FALSE; myABRecord.ddpProto.ddpType = 5; myABRecord.ddpProto.ddpSocket = mySocketsource; myABRecord.ddpProto.ddpAddress.aNet=myNet; myABRecord.ddpProto.ddpAddress.aNode=myNode; myABRecord.ddpProto.ddpAddress.aSocket = mySocketdest; myABRecord.ddpProto.ddpReqCount = dataLen; myABRecord.ddpProto.ddpDataPtr = myBuffer; doChecksum = FALSE; /* Try to send packet....*/ errCode = DDPWrite(myABRecHandle, doChecksum, async); /* Print out resultant error code */ printf("errCode = %d\n",errCode); } } }