int SendDataUDP(int dsize,unsigned char *dptr) { int retval,i; int packetsize; // return (SendData(dsize,dptr)); if (UDPEnable){ /*int SendPtr; char SendBuffer[256*32]; char SendBufferSize[256];*/ blahblahblah++; packetsize = 0; for (i=0;i<dsize;i++) SendBuffer[SendPtr*32+i]=dptr[i]; SendBufferSize[SendPtr]=dsize; if ((dsize == 2) && (dptr[0]<=1)){ if (SendRepeated < 32) SendRepeated++; cpacketdata[0]=4; cpacketdata[1]=dptr[1]; cpacketdata[2]=(char)SendPtr; cpacketdata[3]=(char)SendPtr2; cpacketdata[4]=(char)SendRepeated; packetsize=5; packetsize=AttachEnd(packetsize); PrevSPacket[UDPBackTrace-2]=0; SendPtr=(SendPtr+1) & 0xFF; if (!SendPtr) SendPtr2=(SendPtr2+1) & 0xFF; retval = sendto(ugamesocket,cpacketdata,packetsize,0,(struct sockaddr *)&ugameaddress,sizeof(ugameaddress)); if (retval == SOCKET_ERROR) { closesocket(gamesocket); return(-1); } } else { if (SendRepeated){ PrevSPacket[UDPBackTrace-2]=1; PrevSSize[UDPBackTrace-2]=3; PrevSData[(UDPBackTrace-2)*32]=0; PrevSData[(UDPBackTrace-2)*32+1]=dptr[1]; PrevSData[(UDPBackTrace-2)*32+2]=SendRepeated; PrevSPtr[UDPBackTrace-2]=(SendPtr-1) & 0xFF; } SendRepeated=0; cpacketdata[0]=5; cpacketdata[1]=dptr[1]; cpacketdata[2]=SendPtr; cpacketdata[3]=SendPtr2; cpacketdata[4]=dsize; packetsize=5; for (i=0;i<dsize;i++) cpacketdata[i+5]=dptr[i]; packetsize+=dsize; packetsize=AttachEnd(packetsize); PrevSPacket[UDPBackTrace-2]=1; PrevSSize[UDPBackTrace-2]=dsize; for (i=0;i<dsize;i++) PrevSData[(UDPBackTrace-2)*32+i]=dptr[i]; PrevSPtr[UDPBackTrace-2]=SendPtr; SendPtr=(SendPtr+1) & 0xFF; if (!SendPtr) SendPtr2=(SendPtr2+1) & 0xFF; retval = sendto(ugamesocket,cpacketdata,packetsize,0,(struct sockaddr *)&ugameaddress,sizeof(ugameaddress)); if (retval == SOCKET_ERROR) { closesocket(gamesocket); return(-1); } } return(0); } /* send data with the socket */ retval = sendto(gamesocket,dptr,dsize,0,(struct sockaddr *) &ugameaddress,sizeof(struct sockaddr)); if (retval == SOCKET_ERROR) { closesocket(gamesocket); return(-1); } return(0); }
int main(int argc, char** argv) { TREE pTree = AllocTree(NULL); void *pContents; ITERATOR pIter; int nChoice = 0, nKey; while (nChoice != -1) { printf("1: Insert\n"); printf("2: Remove\n"); printf("3: Print\n"); printf("4: Print all keys\n"); printf("5: Print all keys reverse\n"); printf("6: Mass insert\n"); printf("7: Mass remove\n"); printf("Else: Quit\n\n"); BTSCAN("%d", &nChoice); switch(nChoice) { case 1: printf("Key: "); BTSCAN("%d", &nKey); Insert(nKey, "temp", pTree); break; case 2: printf("Key: "); BTSCAN("%d", &nKey); Remove(nKey, pTree); break; case 3: printf("Key: " ); BTSCAN("%d", &nKey); pContents = Search(nKey, pTree); if (pContents != NULL) { printf("Contents: %s\n", pContents); } else { printf("Not found\n"); } break; case 4: pIter = AllocIterator(); Attach(pIter, pTree); while ((pContents = Next(pIter)) != NULL) { printf("Contents: %d\n", pContents); } Detach(pIter); FreeIterator(pIter); break; case 5: pIter = AllocIterator(); AttachEnd(pIter, pTree); while ((pContents = Next(pIter)) != NULL) { printf("Contents: %d\n", pContents); } Detach(pIter); FreeIterator(pIter); break; case 6: for (nKey = 100; nKey > 0; nKey--) { Insert(nKey, "temp", pTree); } break; case 7: for (nKey = 100; nKey > 0; nKey--) { Remove(nKey, pTree); } break; default: nChoice = -1; break; } printf("\n"); } return 0; }