Alexandre Lision | 7fd5d3d | 2013-12-04 13:06:40 -0500 | [diff] [blame] | 1 | /* |
| 2 | Copyright (C) 2012-2013 Werner Dittmann |
| 3 | |
| 4 | This program is free software: you can redistribute it and/or modify |
| 5 | it under the terms of the GNU Lesser General Public License as published by |
| 6 | the Free Software Foundation, either version 3 of the License, or |
| 7 | (at your option) any later version. |
| 8 | |
| 9 | This program is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | GNU General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License |
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
| 18 | |
| 19 | #include <stdint.h> |
| 20 | #include <common/osSpecifics.h> |
| 21 | |
| 22 | |
| 23 | #if defined(_WIN32) || defined(_WIN64) |
| 24 | |
| 25 | #else |
| 26 | |
| 27 | #endif |
| 28 | |
| 29 | #if defined(_WIN32) || defined(_WIN64) |
| 30 | # include <WinSock2.h> |
| 31 | # include <time.h> |
| 32 | |
| 33 | uint64_t zrtpGetTickCount() |
| 34 | { |
| 35 | // return GetTickCount64(); //works only on 64bit OS |
| 36 | unsigned long long ret; |
| 37 | FILETIME ft; |
| 38 | GetSystemTimeAsFileTime(&ft); |
| 39 | ret = ft.dwHighDateTime; |
| 40 | ret <<= 32; |
| 41 | ret |= ft.dwLowDateTime; |
| 42 | |
| 43 | return ret / 10; //return msec |
| 44 | } |
| 45 | #else |
| 46 | # include <netinet/in.h> |
| 47 | # include <sys/time.h> |
| 48 | |
| 49 | uint64_t zrtpGetTickCount() |
| 50 | { |
| 51 | struct timeval tv; |
| 52 | gettimeofday(&tv, 0); |
| 53 | |
| 54 | return ((uint64_t)tv.tv_sec) * (uint64_t)1000 + ((uint64_t)tv.tv_usec) / (uint64_t)1000; |
| 55 | } |
| 56 | |
| 57 | #endif |
| 58 | |
| 59 | uint32_t zrtpNtohl (uint32_t net) |
| 60 | { |
| 61 | return ntohl(net); |
| 62 | } |
| 63 | |
| 64 | uint16_t zrtpNtohs (uint16_t net) |
| 65 | { |
| 66 | return ntohs(net); |
| 67 | } |
| 68 | |
| 69 | uint32_t zrtpHtonl (uint32_t host) |
| 70 | { |
| 71 | return htonl(host); |
| 72 | } |
| 73 | uint16_t zrtpHtons (uint16_t host) |
| 74 | { |
| 75 | return htons(host); |
| 76 | } |
| 77 | |