Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

misc.cc

Go to the documentation of this file.
00001 //**************************************************************************
00002 #include <stdio.h>
00003 #include <unistd.h>
00004 #include <netdb.h>
00005 #include <sys/time.h>
00006 #include <sys/stat.h>
00007 //**************************************************************************
00008 int myTimer()   // returns time in milliseconds (ms)
00009 {
00010 struct timeval tv;
00011 struct timezone tz;
00012 
00013 gettimeofday(&tv,&tz);
00014 
00015 return (int) ((tv.tv_sec * 1000) + (tv.tv_usec / 1000));
00016 }
00017 //**************************************************************************
00018 double myTimer2()       // returns time in milliseconds (ms)
00019 {
00020 struct timeval tv;
00021 struct timezone tz;
00022 
00023 gettimeofday(&tv,&tz);
00024 
00025 return ((tv.tv_sec * 1000.0) + (tv.tv_usec / 1000.0));
00026 }
00027 //**************************************************************************
00028 int mySleep(int n)      // sleep for "n" microseconds
00029 {
00030 sleep(n/1000000);
00031 usleep(n%1000000);
00032 
00033 return 0;
00034 }
00035 //**************************************************************************
00036 char *getlocalIP(void)
00037 { 
00038 char hostname[200];
00039 struct hostent *host; 
00040 int i, a[4]; 
00041  
00042 gethostname(hostname, 100); 
00043 host = gethostbyname(hostname); 
00044  
00045 for (i = 0; i < 4; i++) 
00046         {
00047          a[i] = (unsigned int) host->h_addr_list[0][i];
00048          if (a[i] < 0) a[i] += 256;
00049         }
00050 
00051 char *ipaddr = new char[16];
00052 sprintf(ipaddr, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
00053 
00054 return ipaddr;
00055 //unsigned long rmid = inet_addr(ipaddr);
00056 //printf("%s[%s]: %ld\n", hostname, ipaddr, rmid); 
00057 }
00058 //**************************************************************************
00059 int getFileSize(char *filename)
00060 {
00061 struct stat statbuf;
00062 
00063 stat(filename, &statbuf);
00064 
00065 return statbuf.st_size;
00066 }
00067 //**************************************************************************

Generated on Sun Jun 16 17:36:49 2002 for POSSE: Portable Object-oriented Scientific Steering Environment by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001