NETWORK ATTACKS FRAMEWORK  1.0.0
A NETwork Attacks framework. Making network attacks impact evaluation easier!
endian.c
Go to the documentation of this file.
00001 /*****************************************************************************
00002  *
00003  * Copyright (C) 2002 Uppsala University.
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  *
00019  * Authors: Björn Wiberg <bjorn.wiberg@home.se>
00020  *
00021  *****************************************************************************/
00022 
00023 /*
00024   This code was partially borrowed from Per Kristian Hove
00025   <Per.Hove@math.ntnu.no>, who originally posted it to the rdesktop
00026   mailing list at rdesktop.org.
00027 
00028   It solves the problem of non-existent <endian.h> on some systems by
00029   generating it.
00030 
00031   (Compile, run, and redirect the output to endian.h.)
00032 */
00033 
00034 #include <stdio.h>
00035 
00036 int litend(void)
00037 {
00038     int i = 0;
00039     ((char *) (&i))[0] = 1;
00040     return (i == 1);
00041 }
00042 
00043 int bigend(void)
00044 {
00045     return !litend();
00046 }
00047 
00048 int main(int argc, char **argv)
00049 {
00050     printf("#ifndef ENDIAN_H\n");
00051     printf("#define ENDIAN_H\n");
00052     printf("#define __LITTLE_ENDIAN 1234\n");
00053     printf("#define __BIG_ENDIAN    4321\n");
00054     printf("#define __BYTE_ORDER __%s_ENDIAN\n", litend()? "LITTLE" : "BIG");
00055     printf("#endif\n");
00056     return 0;
00057 }
 All Classes Files Functions Variables Typedefs Enumerator Defines