-#include <ctype.h>
-
-enum {
- DEBUG_CONNECTIONS = 0,
- DEBUG_PROTOCOL,
- DEBUG_STATUS,
- DEBUG_error,
- DEBUG_META
-};
-
-#define min(a,b) (((a)<(b))?(a):(b))
-
-#define cp { cp_line = __LINE__; cp_file = __FILE__; }
-
-extern volatile int cp_line;
-extern volatile char *cp_file;
-
-extern void hex2bin(char *src, char *dst, size_t length);
-extern void bin2hex(char *src, char *dst, size_t length);
-
-#endif /* __TINC_UTILS_H__ */
+extern void hex2bin(char *src, char *dst, int length);
+extern void bin2hex(char *src, char *dst, int length);
+
+#ifdef HAVE_MINGW
+extern const char *winerror(int);
+#define strerror(x) ((x)>0?strerror(x):winerror(GetLastError()))
+#define sockerrno WSAGetLastError()
+#define sockstrerror(x) winerror(x)
+#define sockwouldblock(x) ((x) == WSAEWOULDBLOCK || (x) == WSAEINTR)
+#define sockmsgsize(x) ((x) == WSAEMSGSIZE)
+#define sockinprogress(x) ((x) == WSAEINPROGRESS || (x) == WSAEWOULDBLOCK)
+#else
+#define sockerrno errno
+#define sockstrerror(x) strerror(x)
+#define sockwouldblock(x) ((x) == EWOULDBLOCK || (x) == EINTR)
+#define sockmsgsize(x) ((x) == EMSGSIZE)
+#define sockinprogress(x) ((x) == EINPROGRESS)
+#endif
+
+extern unsigned int bitfield_to_int(void *bitfield, size_t size);
+
+#endif /* __TINC_UTILS_H__ */