1 |
/* |
/* |
2 |
* Cisco C7200 (Predator) simulation platform. |
* Cisco router simulation platform. |
3 |
* Copyright (c) 2005,2006 Christophe Fillot. All rights reserved. |
* Copyright (c) 2005,2006 Christophe Fillot. All rights reserved. |
4 |
* |
* |
5 |
* Utility functions. |
* Utility functions. |
208 |
} |
} |
209 |
|
|
210 |
fprintf(f_output,"\n"); |
fprintf(f_output,"\n"); |
211 |
|
fflush(f_output); |
212 |
} |
} |
213 |
|
|
214 |
/* Logging function */ |
/* Logging function */ |
257 |
} |
} |
258 |
|
|
259 |
/* Read a file and returns it in a buffer */ |
/* Read a file and returns it in a buffer */ |
260 |
ssize_t m_read_file(char *filename,char **buffer) |
ssize_t m_read_file(char *filename,u_char **buffer) |
261 |
{ |
{ |
262 |
char tmp[256],*ptr,*nptr; |
u_char tmp[256],*ptr,*nptr; |
263 |
size_t len,tot_len; |
size_t len,tot_len; |
264 |
FILE *fd; |
FILE *fd; |
265 |
|
|
297 |
{ |
{ |
298 |
void *p; |
void *p; |
299 |
|
|
300 |
#ifdef __linux__ |
#if defined(__linux__) || HAS_POSIX_MEMALIGN |
301 |
if (posix_memalign((void *)&p,boundary,size)) |
if (posix_memalign((void *)&p,boundary,size)) |
302 |
#else |
#else |
303 |
#if defined(__CYGWIN__) || defined(SUNOS) |
#if defined(__CYGWIN__) || defined(SUNOS) |
442 |
|
|
443 |
return(~sum); |
return(~sum); |
444 |
} |
} |
445 |
|
|
446 |
|
/* Byte-swap a memory block */ |
447 |
|
void mem_bswap32(void *ptr,size_t len) |
448 |
|
{ |
449 |
|
m_uint32_t *p = ptr; |
450 |
|
size_t count = len >> 2; |
451 |
|
int i; |
452 |
|
|
453 |
|
for(i=0;i<count;i++,p++) |
454 |
|
*p = swap32(*p); |
455 |
|
} |
456 |
|
|
457 |
|
/* Reverse a byte */ |
458 |
|
m_uint8_t m_reverse_u8(m_uint8_t val) |
459 |
|
{ |
460 |
|
m_uint8_t res = 0; |
461 |
|
int i; |
462 |
|
|
463 |
|
for(i=0;i<8;i++) |
464 |
|
if (val & (1 << i)) |
465 |
|
res |= 1 << (7 - i); |
466 |
|
|
467 |
|
return(res); |
468 |
|
} |