473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

protocol header

hi @all,

I'm designing a new simple protocol and now I need a header for it.
There should only be 3 fields, one 32bit and 2 16bit fields -> 64bit
header (8byte). Due to the used library I need the data as a (unsigned
char*) for delivering. I thought about a struct to store the header but
I don't know how to cast it to the expected format for delivering.
Is there a way to store all this information and deliver it in a char[8]
which would be exactly 8byte long?
Jul 23 '05 #1
4 1487
"Andreas Müller" wrote
hi @all,

I'm designing a new simple protocol and now I need a header for it.
There should only be 3 fields, one 32bit and 2 16bit fields -> 64bit
header (8byte). Due to the used library I need the data as a (unsigned
char*) for delivering. I thought about a struct to store the header but
I don't know how to cast it to the expected format for delivering.
Is there a way to store all this information and deliver it in a char[8]
which would be exactly 8byte long?


homework?
it's so simple. hint: typecast adress of struct to char*, or use
union and struct and...
Jul 23 '05 #2
> I'm designing a new simple protocol and now I need a header for it.
There should only be 3 fields, one 32bit and 2 16bit fields -> 64bit
header (8byte). Due to the used library I need the data as a (unsigned
char*) for delivering. I thought about a struct to store the header but
I don't know how to cast it to the expected format for delivering.
Is there a way to store all this information and deliver it in a char[8]
which would be exactly 8byte long?


Most compilers will place the struct you describe in 8 bytes, but some
compilers might not.
And on some processors the most significant byte will be first (Motorola)
and on others the least significant byte will be first (Intel). So you have
to take the byte order into account, f.ex by swapping the bytes on one of
the processor types.

Niels Dybdahl
Jul 23 '05 #3
Andreas Müller wrote:
hi @all,

I'm designing a new simple protocol and now I need a header for it.
There should only be 3 fields, one 32bit and 2 16bit fields -> 64bit
header (8byte). Due to the used library I need the data as a (unsigned
char*) for delivering. I thought about a struct to store the header but
I don't know how to cast it to the expected format for delivering.
Is there a way to store all this information and deliver it in a char[8]
which would be exactly 8byte long?


Hello,

if you are using C++, then reinterpret_cast might be a solution.

regards marbac

Jul 23 '05 #4
Andreas Müller wrote:
I'm designing a new simple protocol and now I need a header for it.
There should only be 3 fields, one 32bit and 2 16bit fields -> 64bit
header (8byte). Due to the used library I need the data as a (unsigned
char*) for delivering. I thought about a struct to store the header but
I don't know how to cast it to the expected format for delivering.
Is there a way to store all this information and deliver it in a char[8]
which would be exactly 8byte long?


Just use a char [8], or better, unsigned char [8] Put/get your data in it in
the format you want to use, and the code will work in all machines (in all
that use the same byte size, at least).

--
Salu2
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Justin Malloy | last post by:
I am using the System.Net.Webclient to try and download an XML file from a website but am receiving a HTTP protocol error when running the DownloadFile() sub routine. I did a HTTP trace using...
4
by: Michael--J | last post by:
Hi, I have been writing a Communications protocol component in C# that will basically be used in client and server applications. The sole purpose of the component is to allow applications to be...
0
by: SWJust | last post by:
I found out that the socket in C# can be set in an GGP mode, but what does that mean, it is nessary for me to enter at mode where it is possible to communicate with routers, because my application...
1
by: Qingdong Z. | last post by:
I had the trouble a long time, and hope some experts can really help me. I used HttpWebRequest/HttpWebResponse to get the content of an URL. It throws "HTTP Protocol Violation". Even I set...
0
by: admin | last post by:
TCP/IP UDP Protocol Development Library and Resources Free VC++ 6.0 (ws2_32.lib) Winsock 2 TCP/IP Library complete with project source implements TCP/IP Header construction, Checksum...
102
by: hug | last post by:
www.webmaster, was suggested that this ng could be a better place.] I've updated my test server to handle if-modified-since. I've noticed that the (old copies I run of) IE and Netscape seem...
0
by: Kris Mattheus | last post by:
A little background: I've been using web services successfully for a while now. My web server is a Windows CE 4.2 device and my client is a windows C# application created with Visual Studio 2003....
3
by: Scott McDermott | last post by:
I have an application that is making an HTTP request with HttpWebRequest.GetRequest. Unless I set 'httpWebRequest useUnsafeHeaderParsing="true"' in the web.config, I get a 'The server committed a...
2
by: trishikh2002 | last post by:
I want to implement the entire GO BACK N protocol in C with 3 nodes A,B ,C The Node B is a relay node which receives the packets from A and passes on to C. The communication is over UDP sockets...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.