X-Git-Url: http://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Futils.h;fp=src%2Futils.h;h=fddb8a67a3a279c3a35d3247811c5b9abc063be5;hb=35b1c25093a478d20e01f0ff391c9cdc9c41c2b8;hp=0000000000000000000000000000000000000000;hpb=41497246eeccbcc417f93c2ae087e927751c6914;p=tinc diff --git a/src/utils.h b/src/utils.h new file mode 100644 index 00000000..fddb8a67 --- /dev/null +++ b/src/utils.h @@ -0,0 +1,47 @@ +/* + utils.h -- header file for utils.c + Copyright (C) 1999-2005 Ivo Timmermans + 2000-2009 Guus Sliepen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifndef __TINC_UTILS_H__ +#define __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) +#define sockinuse(x) ((x) == WSAEADDRINUSE) +#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) +#define sockinuse(x) ((x) == EADDRINUSE) +#endif + +extern unsigned int bitfield_to_int(void *bitfield, size_t size); + +#endif /* __TINC_UTILS_H__ */