Bits how to program them

This is a discussion on Bits how to program them within the Linux Networking forums, part of the Linux Forums category; Hi, I am writing a P2P client application. As such, I am creating packets that are to be sent between ...


Go Back   Usenet Forums > Linux Forums > Linux Networking

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-11-2004
Marcia Hon
 
Posts: n/a
Default Bits how to program them

Hi,

I am writing a P2P client application. As such, I am creating packets that
are to be sent between the peers. I would like to know how in C these bits
of the packets may be programmed. These bits need to be continguous.

For example: I create a packet of size 5. 2 bytes for the size, 1 for the
message type, 1 for the start flag, 1 for the body, and 1 for the end flag.

How to I program this?

I have tried the following:

unsigned size:16;
unsigned type:8;
unsigned start:8;
unsigned body:8;
unsigned end:8;

How to I keep them contiguous? I would like to eventually send them over the
socket connection. And therefore would like to store them in an unsigned *
buffer.

Please, please help.

Thank you,
Marcia


Reply With Quote
  #2 (permalink)  
Old 02-11-2004
Bill Unruh
 
Posts: n/a
Default Re: Bits how to program them

"Marcia Hon" <honm@rogers.com> writes:

]Hi,

]I am writing a P2P client application. As such, I am creating packets that
]are to be sent between the peers. I would like to know how in C these bits
]of the packets may be programmed. These bits need to be continguous.

]For example: I create a packet of size 5. 2 bytes for the size, 1 for the
]message type, 1 for the start flag, 1 for the body, and 1 for the end flag.

]How to I program this?

]I have tried the following:

]unsigned size:16;
]unsigned type:8;
]unsigned start:8;
]unsigned body:8;
]unsigned end:8;

]How to I keep them contiguous? I would like to eventually send them over the
]socket connection. And therefore would like to store them in an unsigned *
]buffer.

Make a structure.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 12:06 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0