693f1e87154947811c9ac21a092b5aefe1f38836
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

include/intern/net.h  1) /*
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

include/intern/net.h  2)  * EtherPix library
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

include/intern/net.h  3)  *
Stefan Schuermans update copyright year

Stefan Schuermans authored 7 years ago

include/intern/net.h  4)  * Copyright 2010-2017 Stefan Schuermans <stefan schuermans info>
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

include/intern/net.h  5)  *
include/intern/net.h  6)  * This program is free software: you can redistribute it and/or modify
include/intern/net.h  7)  * it under the terms of the GNU General Public License as published by
include/intern/net.h  8)  * the Free Software Foundation, version 3 of the License.
include/intern/net.h  9)  *
include/intern/net.h 10)  *
include/intern/net.h 11)  * This program is distributed in the hope that it will be useful,
include/intern/net.h 12)  * but WITHOUT ANY WARRANTY; without even the implied warranty of
include/intern/net.h 13)  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
include/intern/net.h 14)  * GNU General Public License for more details.
include/intern/net.h 15)  *
include/intern/net.h 16)  * You should have received a copy of the GNU Lesser General Public License
include/intern/net.h 17)  * along with this program. If not, see <http://www.gnu.org/licenses/>.
include/intern/net.h 18)  */
include/intern/net.h 19) 
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

include/intern/net.h 20) #ifndef ETP_NET_H
include/intern/net.h 21) #define ETP_NET_H
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

include/intern/net.h 22) 
include/intern/net.h 23) #ifdef WINDOWS
Stefan Schuermans v1.0.6

Stefan Schuermans authored 13 years ago

include/intern/net.h 24) #  include <stdint.h>
include/intern/net.h 25) #  include <winsock2.h>
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

include/intern/net.h 26) #else
Stefan Schuermans v1.0.6

Stefan Schuermans authored 13 years ago

include/intern/net.h 27) #  include <arpa/inet.h>
include/intern/net.h 28) #  include <errno.h>
include/intern/net.h 29) #  include <netdb.h>
include/intern/net.h 30) #  include <netinet/in.h>
include/intern/net.h 31) #  include <string.h>
include/intern/net.h 32) #  include <sys/socket.h>
include/intern/net.h 33) #  include <unistd.h>
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

include/intern/net.h 34) #endif
include/intern/net.h 35) 
Stefan Schuermans v1.0.6

Stefan Schuermans authored 13 years ago

include/intern/net.h 36) /** type of socket descriptor */
include/intern/net.h 37) #ifdef WINDOWS
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

include/intern/net.h 38) typedef SOCKET etp_sock_t;
Stefan Schuermans v1.0.6

Stefan Schuermans authored 13 years ago

include/intern/net.h 39) #else
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

include/intern/net.h 40) typedef int etp_sock_t;
Stefan Schuermans v1.0.6

Stefan Schuermans authored 13 years ago

include/intern/net.h 41) #endif
include/intern/net.h 42) 
include/intern/net.h 43) #ifdef WINDOWS
include/intern/net.h 44) /** IP address type missing on Windows */
include/intern/net.h 45) typedef uint32_t in_addr_t;
include/intern/net.h 46) #endif
include/intern/net.h 47) 
include/intern/net.h 48) #ifdef WINDOWS
include/intern/net.h 49) /** port type missing on Windows */
include/intern/net.h 50) typedef uint16_t in_port_t;
include/intern/net.h 51) #endif
include/intern/net.h 52) 
include/intern/net.h 53) #ifndef WINDOWS
include/intern/net.h 54) /** closesocket() only exists for Windows,other OSes just use close() */
Stefan Schuermans adaptions for gcc 5

Stefan Schuermans authored 7 years ago

include/intern/net.h 55) static inline int closesocket(int fd)
Stefan Schuermans v1.0.6

Stefan Schuermans authored 13 years ago

include/intern/net.h 56) {
include/intern/net.h 57)   return close(fd);
include/intern/net.h 58) }
include/intern/net.h 59) #endif
include/intern/net.h 60) 
include/intern/net.h 61) /**
include/intern/net.h 62)  * \brief check a socket descriptor
include/intern/net.h 63)  * \param[in] sock socket descriptor to check
include/intern/net.h 64)  * \return 1 if valid, 0 if not valid
include/intern/net.h 65)  */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

include/intern/net.h 66) static inline int etp_sock_is_valid(etp_sock_t sock)
Stefan Schuermans v1.0.6

Stefan Schuermans authored 13 years ago

include/intern/net.h 67) {
include/intern/net.h 68) #ifdef WINDOWS
include/intern/net.h 69)   return sock != INVALID_SOCKET;
include/intern/net.h 70) #else
include/intern/net.h 71)   return sock >= 0;
include/intern/net.h 72) #endif
include/intern/net.h 73) }
include/intern/net.h 74) 
include/intern/net.h 75) /**
include/intern/net.h 76)  * \brief get error of last socket call as text
include/intern/net.h 77)  * \param[in] buf pointer to buffer to place text into
include/intern/net.h 78)  * \param[in] buflen size of buffer
include/intern/net.h 79)  */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

include/intern/net.h 80) static inline void etp_sock_get_last_error(char *buf, size_t buflen)
Stefan Schuermans v1.0.6

Stefan Schuermans authored 13 years ago

include/intern/net.h 81) {
include/intern/net.h 82) #ifdef WINDOWS
include/intern/net.h 83)   int err = WSAGetLastError();
include/intern/net.h 84)   FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
include/intern/net.h 85)                 NULL, err, 0, buf, buflen, NULL);
include/intern/net.h 86) #else
include/intern/net.h 87)   strerror_r(errno, buf, buflen);
include/intern/net.h 88) #endif
include/intern/net.h 89) }
include/intern/net.h 90) 
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

include/intern/net.h 91) #endif /* #ifndef ETP_NET_H */