a3a92abf1ca043aaaaaa79381afa316abaa00ace
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

1) /*
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

2)  * EtherPix library
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

3)  *
Stefan Schuermans removed version information...

Stefan Schuermans authored 13 years ago

4)  * Copyright 2010-2011 Stefan Schuermans <stefan schuermans info>
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 7 years ago

20) #ifndef ETP_NET_H
21) #define ETP_NET_H
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

22) 
23) #ifdef WINDOWS
Stefan Schuermans v1.0.6

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

26) #else
Stefan Schuermans v1.0.6

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

34) #endif
35) 
Stefan Schuermans v1.0.6

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 7 years ago

38) typedef SOCKET etp_sock_t;
Stefan Schuermans v1.0.6

Stefan Schuermans authored 13 years ago

39) #else
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

40) typedef int etp_sock_t;
Stefan Schuermans v1.0.6

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 7 years ago

55) static inline int closesocket(int fd)
Stefan Schuermans v1.0.6

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 7 years ago

66) static inline int etp_sock_is_valid(etp_sock_t sock)
Stefan Schuermans v1.0.6

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 7 years ago

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

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

Stefan Schuermans authored 7 years ago

91) #endif /* #ifndef ETP_NET_H */