Jacquelinett Posted March 10, 2012 Author Share Posted March 10, 2012 Can anyone show me a tutorial on packet handing buffer tutorial?I mean like, how to set it up. Link to comment Share on other sites More sharing options...
kenny92316 Posted March 10, 2012 Share Posted March 10, 2012 I'm a novice when it comes to packets, but if you don't get any answers try looking for packets in the source and see how it's used. Link to comment Share on other sites More sharing options...
Jacquelinett Posted March 10, 2012 Author Share Posted March 10, 2012 @kenny:> I'm a novice when it comes to packets, but if you don't get any answers try looking for packets in the source and see how it's used.U do know that im talking about setting up a packet system right? I know how packet work in eclipse and can code.Im talking create a packet system like Eclipse with C++ using winsock Link to comment Share on other sites More sharing options...
Yxxe Posted March 10, 2012 Share Posted March 10, 2012 @Yumi-chan:> U do know that im talking about setting up a packet system right? I know how packet work in eclipse and can code.> > Im talking create a packet system like Eclipse with C++ using winsockJust write a few functions which handle packing different variable types into dynamic character array and send that. Link to comment Share on other sites More sharing options...
Godlord Posted March 10, 2012 Share Posted March 10, 2012 Writing a packet buffer is merely based on memory management and pointer arithmetic, really.```#include #include typedef struct Buffer Buffer;struct Buffer{ unsigned char *iBytePointer; unsigned char *iByteList; size_t iByteCount;};Buffer *AllocateBuffer(size_t iByteCount){ Buffer *objBuffer = NULL; objBuffer = (Buffer *)calloc(1, sizeof(Buffer)); if (objBuffer == NULL) return NULL; objBuffer->iByteList = (unsigned char *)calloc(iByteCount, sizeof(unsigned char)); if (objBuffer->iByteList == NULL) { free(objBuffer); return NULL; } objBuffer->iBytePointer = objBuffer->iByteList; objBuffer->iByteCount = iByteCount; return objBuffer;}void FreeBuffer(Buffer *objBuffer){ if (objBuffer == NULL) return; free(objBuffer->iByteList); free(objBuffer);}int ResetBuffer(Buffer *objBuffer){ if (objBuffer == NULL) return -1; objBuffer->iBytePointer = objBuffer->iByteList; return 0;}int ReadShort(Buffer *objBuffer, short *iValue){ if (objBuffer == NULL || iValue == NULL) return -1; *iValue = *((short *)objBuffer->iBytePointer); objBuffer->iBytePointer += sizeof(short); return 0;}int WriteShort(Buffer *objBuffer, short iValue){ if (objBuffer == NULL) return -1; *((short *)objBuffer->iBytePointer) = iValue; objBuffer->iBytePointer += sizeof(short); return 0;}/* The other stuff is practice for the reader. */int main(int argc, char *argv[]){ Buffer *objBuffer = AllocateBuffer(256); short iValue = 0; if (objBuffer == NULL) { printf("Couldn\'t allocate the buffer.\n"); return -1; } printf("Writing values to buffer.\n"); WriteShort(objBuffer, 42); WriteShort(objBuffer, 69); WriteShort(objBuffer, 72); printf("Resetting buffer.\n"); ResetBuffer(objBuffer); printf("Reading values from buffer.\n"); ReadShort(objBuffer, &iValue); printf(" Primary: %d.\n", iValue); ReadShort(objBuffer, &iValue); printf(" Secondary: %d.\n", iValue); ReadShort(objBuffer, &iValue); printf(" Tertiary: %d.\n", iValue); FreeBuffer(objBuffer); return 0;}```Yours faithfully, Stephan. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now