AppleTalk / C Programming Problem
Peter A. Steinauer
peter at boulder.Colorado.EDU
Thu Jan 10 03:43:05 AEST 1991
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 <MemoryMgr.h>
#include <AppleTalk.h>
#include <nAppleTalk.h>
#include <stdio.h>
#include <string.h>
#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);
}
}
}
More information about the Comp.lang.c
mailing list