1 /*
2 ettercap -- sleep / timer functions
3
4 Copyright (C) ALoR & NaGA
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 */
21
22 #include <ec.h>
23 #include <ec_sleep.h>
24
25 #include <unistd.h>
26 #include <time.h>
27
28 /* this function is used to unify *sleep calls within ettercap */
ec_usleep(unsigned int usecs)29 void ec_usleep(unsigned int usecs)
30 {
31 #ifndef OS_WINDOWS
32 struct timespec ts;
33 ts.tv_sec = MICRO2SEC(usecs);
34 ts.tv_nsec = MICRO2NANO((usecs % (SEC2MICRO(1))));
35
36 nanosleep(&ts, NULL);
37 #else
38 /*
39 * Use SleepEx() instead:
40 * http://msdn.microsoft.com/library/windows/desktop/ms686307.aspx
41 */
42 DWORD msecs = usecs / 1000;
43 SleepEx (msecs, FALSE);
44 #endif
45 }
46
47 /* EOF */
48
49 // vim:ts=3:expandtab
50