added functions for reading values from byte streams.

This commit is contained in:
gardners 2012-11-30 21:02:43 +10:30
parent e5d5f3f750
commit 692817ffba
2 changed files with 26 additions and 0 deletions

View File

@ -61,3 +61,26 @@ void write_uint16(unsigned char *o,uint16_t v)
{ *(o++)=v&0xff; v=v>>8; }
}
uint64_t read_uint64(unsigned char *o)
{
int i;
uint64_t v=0;
for(i=0;i<8;i++) v=(v<<8)|*(o++);
return v;
}
uint32_t read_uint32(unsigned char *o)
{
int i;
uint32_t v=0;
for(i=0;i<4;i++) v=(v<<8)|*(o++);
return v;
}
uint16_t read_uint16(unsigned char *o)
{
int i;
uint16_t v=0;
for(i=0;i<2;i++) v=(v<<8)|*(o++);
return v;
}

View File

@ -768,5 +768,8 @@ int olsr_send(struct overlay_frame *frame);
void write_uint64(unsigned char *o,uint64_t v);
void write_uint16(unsigned char *o,uint16_t v);
void write_uint32(unsigned char *o,uint32_t v);
uint64_t read_uint64(unsigned char *o);
uint32_t read_uint32(unsigned char *o);
uint16_t read_uint16(unsigned char *o);
#endif // __SERVALD_SERVALD_H