Return-Path: william@bourbon.usc.edu Delivery-Date: Thu Sep 4 10:23:25 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on merlot.usc.edu X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.3 Received: from bourbon.usc.edu (bourbon.usc.edu [128.125.9.75]) by merlot.usc.edu (8.14.1/8.14.1) with ESMTP id m84HNPui024829 for ; Thu, 4 Sep 2008 10:23:25 -0700 Received: from bourbon.usc.edu (localhost.localdomain [127.0.0.1]) by bourbon.usc.edu (8.14.2/8.14.1) with ESMTP id m84HLSBb008625 for ; Thu, 4 Sep 2008 10:21:28 -0700 Message-Id: <200809041721.m84HLSBb008625@bourbon.usc.edu> To: cs551@merlot.usc.edu Subject: Re: CSCI 551- Question in warm up project 1 Date: Thu, 04 Sep 2008 10:21:28 -0700 From: Bill Cheng Someone wrote: > I had issue with packet construction. Could you please help me out ? > > I had used a structure to hold the different packet fields i.e. message > type, offset, data length, and the data. > > While sending using sockets, I used to use a pointer to the structure > variable to send the entire packet. Is it fine, if I do it this way ? If you do it very carefully, it should be okay! > Or should i always do it, by packing all the fields into a string and then > send using the pointer to the string ? I would prefer this 2nd approach for the header. This way, you can verify what's in the buffer before you start sending. Please use the debugger to verify the content of your buffer. I've just modified the beginning of my Sockets Programming slides: http://merlot.usc.edu/cs551-f08/lectures/tentative/01a_sockets.pdf On page 4, I've added a new command I've recently learned in gdb: printf "%02x\n",buf[0] If you use the "print" command in gdb, it will print out an integer value. You should use the "printf" command in gdb to display a byte in hex like I've done above. By the way, I'm a bit worried when you used the word "string"! If you really think of this character buffer as a string, you may use functions that operate on string to manipulate data in this buffer. Sometimes this would work, and sometimes not. -- Bill Cheng // bill.cheng@usc.edu