utils.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef TINC_UTILS_H
  2. #define TINC_UTILS_H
  3. /*
  4. utils.h -- header file for utils.c
  5. Copyright (C) 1999-2005 Ivo Timmermans
  6. 2000-2014 Guus Sliepen <guus@tinc-vpn.org>
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License along
  16. with this program; if not, write to the Free Software Foundation, Inc.,
  17. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. */
  19. extern bool hex2bin(char *src, char *dst, int length);
  20. extern void bin2hex(char *src, char *dst, int length);
  21. #if defined(HAVE_MINGW) || defined(HAVE_CYGWIN)
  22. extern const char *winerror(int);
  23. #endif
  24. #ifdef HAVE_MINGW
  25. #define strerror(x) ((x)>0?strerror(x):winerror(GetLastError()))
  26. #define sockerrno WSAGetLastError()
  27. #define sockstrerror(x) winerror(x)
  28. #define sockwouldblock(x) ((x) == WSAEWOULDBLOCK || (x) == WSAEINTR)
  29. #define sockmsgsize(x) ((x) == WSAEMSGSIZE)
  30. #define sockinprogress(x) ((x) == WSAEINPROGRESS || (x) == WSAEWOULDBLOCK)
  31. #else
  32. #define sockerrno errno
  33. #define sockstrerror(x) strerror(x)
  34. #define sockwouldblock(x) ((x) == EWOULDBLOCK || (x) == EINTR)
  35. #define sockmsgsize(x) ((x) == EMSGSIZE)
  36. #define sockinprogress(x) ((x) == EINPROGRESS)
  37. #endif
  38. extern unsigned int bitfield_to_int(const void *bitfield, size_t size);
  39. int memcmp_constant_time(const void *a, const void *b, size_t size);
  40. #endif