• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 5230455705

10 Jun 2023 02:30PM UTC coverage: 91.715% (-0.03%) from 91.746%
5230455705

push

github

randombit
Merge GH #3584 Change clang-format AllowShortFunctionsOnASingleLine config from All to Inline

77182 of 84154 relevant lines covered (91.72%)

11975295.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.78
/src/cli/socket_utils.h
1
/*
2
* (C) 2014,2017 Jack Lloyd
3
*     2017 René Korthaus, Rohde & Schwarz Cybersecurity
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#ifndef BOTAN_CLI_SOCKET_UTILS_H_
9
#define BOTAN_CLI_SOCKET_UTILS_H_
10

11
#include "cli_exceptions.h"
12
#include <botan/types.h>
13

14
#if defined(BOTAN_TARGET_OS_HAS_WINSOCK2)
15

16
   #include <WS2tcpip.h>
17
   #include <winsock2.h>
18

19
typedef SOCKET socket_type;
20

21
inline socket_type invalid_socket() {
22
   return INVALID_SOCKET;
23
}
24

25
typedef size_t ssize_t;
26
typedef int sendrecv_len_type;
27

28
inline void close_socket(socket_type s) {
29
   ::closesocket(s);
30
}
31

32
   #define STDIN_FILENO _fileno(stdin)
33

34
inline void init_sockets() {
35
   WSAData wsa_data;
36
   WORD wsa_version = MAKEWORD(2, 2);
37

38
   if(::WSAStartup(wsa_version, &wsa_data) != 0) {
39
      throw Botan_CLI::CLI_Error("WSAStartup() failed: " + std::to_string(WSAGetLastError()));
40
   }
41

42
   if(LOBYTE(wsa_data.wVersion) != 2 || HIBYTE(wsa_data.wVersion) != 2) {
43
      ::WSACleanup();
44
      throw Botan_CLI::CLI_Error("Could not find a usable version of Winsock.dll");
45
   }
46
}
47

48
inline void stop_sockets() {
49
   ::WSACleanup();
50
}
51

52
inline std::string err_to_string(int e) {
53
   // TODO use strerror_s here
54
   return "Error code " + std::to_string(e);
55
}
56

57
inline int close(int fd) {
58
   return ::closesocket(fd);
59
}
60

61
inline int read(int s, void* buf, size_t len) {
62
   return ::recv(s, reinterpret_cast<char*>(buf), static_cast<int>(len), 0);
63
}
64

65
inline int send(int s, const uint8_t* buf, size_t len, int flags) {
66
   return ::send(s, reinterpret_cast<const char*>(buf), static_cast<int>(len), flags);
67
}
68

69
#elif defined(BOTAN_TARGET_OS_HAS_POSIX1)
70

71
   #include <arpa/inet.h>
72
   #include <errno.h>
73
   #include <fcntl.h>
74
   #include <netdb.h>
75
   #include <netinet/in.h>
76
   #include <sys/socket.h>
77
   #include <sys/time.h>
78
   #include <sys/types.h>
79
   #include <unistd.h>
80

81
typedef int socket_type;
82
typedef size_t sendrecv_len_type;
83

84
inline socket_type invalid_socket() {
7✔
85
   return -1;
7✔
86
}
87

88
inline void close_socket(socket_type s) {
5✔
89
   ::close(s);
5✔
90
}
5✔
91

92
inline void init_sockets() {}
7✔
93

94
inline void stop_sockets() {}
7✔
95

96
inline std::string err_to_string(int e) {
×
97
   return std::strerror(e);
×
98
}
99

100
#endif
101

102
#if !defined(MSG_NOSIGNAL)
103
   #define MSG_NOSIGNAL 0
104
#endif
105

106
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc