File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / hping2 / byteorder.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 22:11:37 2012 UTC (12 years, 3 months ago) by misho
Branches: hping2, MAIN
CVS tags: v2_0_0rc3p7, v2_0_0rc3p5, v2_0_0rc3p4, v2_0_0rc3p0, v2_0_0rc3, HEAD
hping2

    1: #if 0
    2: #
    3: # Compile with:
    4: #	$sh byteorder.c
    5: #
    6: cc byteorder.c -o byteorder || exit 1
    7: echo successfully compiled
    8: exit
    9: #endif /* 0 */
   10: 
   11: /* 
   12:  * $smu-mark$ 
   13:  * $name: byteorder.c$ 
   14:  * $author: Salvatore Sanfilippo <antirez@invece.org>$ 
   15:  * $copyright: Copyright (C) 1999 by Salvatore Sanfilippo$ 
   16:  * $license: This software is under GPL version 2 of license$ 
   17:  * $date: Fri Nov  5 11:55:47 MET 1999$ 
   18:  * $rev: 9$ 
   19:  */ 
   20: 
   21: /*
   22:  * 0.1 first version
   23:  * 0.2 add Strchr, so it's possibile remove string.h
   24:  * 0.3 more portable thx to Pancrazio De Mauro 'TrantIT'!!!
   25:  * 0.4 better debug output
   26:  */
   27: 
   28: #include <stdio.h>
   29: 
   30: char *Strchr(char *s, char c)
   31: {
   32: 	while(*s)
   33: 		if (*s++ == c)
   34: 			return s;
   35: 
   36: 	return (char*) 0;
   37: }
   38: 
   39: int main(int argc, char **argv)
   40: {
   41: 	unsigned int test = 1;
   42: 	unsigned char *x;
   43: 	int macro = 0, debug = 0, help = 0, j;
   44: 
   45: 	for (j = 1; j < argc; j++) {
   46: 		if (Strchr(argv[j], 'm')) macro = 1;
   47: 		if (Strchr(argv[j], 'd')) debug = 1;
   48: 		if (Strchr(argv[j], 'h')) help = 1;
   49: 	}
   50: 
   51: 	if (help) {
   52: 		printf(	"-m	macro output\n"
   53: 			"-d	debug\n"
   54: 			"-h	help\n");
   55: 		return 0;
   56: 	}
   57: 		
   58: 	x = (unsigned char*) &test;
   59: 
   60: 	if (*x == 0x00) {
   61: 		if (macro)
   62: 			printf("__BIG_ENDIAN_BITFIELD\n");
   63: 		else
   64: 			printf("big endian\n");
   65: 	}
   66: 	else if (*x == 0x01) {
   67: 		if (macro)
   68: 			printf("__LITTLE_ENDIAN_BITFIELD\n");
   69: 		else
   70: 			printf("little endian\n");
   71: 	} else {
   72: 		printf("\nWARNING!!! byteorder exception\n\n");
   73: 		debug = 1;
   74: 	}
   75: 
   76: 	if (debug) {
   77: 		printf("sizeof(unsigned int) = %d\n", sizeof(unsigned int));
   78: 		printf("unsigned int test = 1;\n");
   79: 		printf("in memory as: ");
   80: 		for (j = 0; j < sizeof(unsigned int); j++)
   81: 			printf("%02x ", x[j]);
   82: 		printf("\n");
   83: 	}
   84: 	return 0;
   85: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>