BlinkenArea - GitList
Repositories
Blog
Wiki
libetherpix
Code
Commits
Branches
Tags
Search
Tree:
693f1e8
Branches
Tags
master
libetherpix
src
net.h
move internal includes
Stefan Schuermans
commited
693f1e8
at 2017-09-24 08:51:47
net.h
Blame
History
Raw
/* * EtherPix library * * Copyright 2010-2017 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 ETP_NET_H #define ETP_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 etp_sock_t; #else typedef int etp_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 etp_sock_is_valid(etp_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 etp_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 ETP_NET_H */