tinc/lib/utils.h

46 lines
1.7 KiB
C
Raw Normal View History

2019-08-26 11:44:36 +00:00
/*
utils.h -- header file for utils.c
2019-08-26 11:44:38 +00:00
Copyright (C) 1999-2005 Ivo Timmermans
2000-2009 Guus Sliepen <guus@tinc-vpn.org>
2019-08-26 11:44:36 +00:00
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.
2019-08-26 11:44:38 +00:00
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.
2019-08-26 11:44:36 +00:00
*/
#ifndef __TINC_UTILS_H__
#define __TINC_UTILS_H__
2019-08-26 11:44:43 +00:00
extern bool hex2bin(char *src, char *dst, int length);
2019-08-26 11:44:36 +00:00
extern void bin2hex(char *src, char *dst, int length);
2019-08-26 11:44:36 +00:00
#ifdef HAVE_MINGW
2019-08-26 11:44:38 +00:00
extern const char *winerror(int);
2019-08-26 11:44:36 +00:00
#define strerror(x) ((x)>0?strerror(x):winerror(GetLastError()))
2019-08-26 11:44:38 +00:00
#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)
2019-08-26 11:44:36 +00:00
#endif
2019-08-26 11:44:41 +00:00
extern unsigned int bitfield_to_int(const void *bitfield, size_t size);
2019-08-26 11:44:38 +00:00
2019-08-26 11:44:36 +00:00
#endif /* __TINC_UTILS_H__ */