BlinkenArea - GitList
Repositories
Blog
Wiki
libflexipix
Code
Commits
Branches
Tags
Search
Tree:
0e2d779
Branches
Tags
master
v1.0.0
v1.0.1
v1.0.2
v1.0.3
v1.0.4
v1.0.5
v1.0.6
v1.0.7
v1.0.8
libflexipix
include
intern
net.h
adaptions for gcc 5
Stefan Schuermans
commited
0e2d779
at 2017-02-11 09:44:10
net.h
Blame
History
Raw
/* * FlexiPix library * * Copyright 2010-2011 Stefan Schuermans <stefan schuermans info> * * 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, version 3 of the License. * * * 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 Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef FLP_NET_H #define FLP_NET_H #ifdef WINDOWS # include <stdint.h> # include <winsock2.h> #else # include <arpa/inet.h> # include <errno.h> # include <netdb.h> # include <netinet/in.h> # include <string.h> # include <sys/socket.h> # include <unistd.h> #endif /** type of socket descriptor */ #ifdef WINDOWS typedef SOCKET flp_sock_t; #else typedef int flp_sock_t; #endif #ifdef WINDOWS /** IP address type missing on Windows */ typedef uint32_t in_addr_t; #endif #ifdef WINDOWS /** port type missing on Windows */ typedef uint16_t in_port_t; #endif #ifndef WINDOWS /** closesocket() only exists for Windows,other OSes just use close() */ static inline int closesocket(int fd) { return close(fd); } #endif /** * \brief check a socket descriptor * \param[in] sock socket descriptor to check * \return 1 if valid, 0 if not valid */ static inline int flp_sock_is_valid(flp_sock_t sock) { #ifdef WINDOWS return sock != INVALID_SOCKET; #else return sock >= 0; #endif } /** * \brief get error of last socket call as text * \param[in] buf pointer to buffer to place text into * \param[in] buflen size of buffer */ static inline void flp_sock_get_last_error(char *buf, size_t buflen) { #ifdef WINDOWS int err = WSAGetLastError(); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, 0, buf, buflen, NULL); #else strerror_r(errno, buf, buflen); #endif } #endif /* #ifndef FLP_NET_H */