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

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

12139530.51 hits per line

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

80.0
/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() { return INVALID_SOCKET; }
22

23
typedef size_t ssize_t;
24
typedef int sendrecv_len_type;
25

26
inline void close_socket(socket_type s) { ::closesocket(s); }
27

28
   #define STDIN_FILENO _fileno(stdin)
29

30
inline void init_sockets() {
31
   WSAData wsa_data;
32
   WORD wsa_version = MAKEWORD(2, 2);
33

34
   if(::WSAStartup(wsa_version, &wsa_data) != 0) {
35
      throw Botan_CLI::CLI_Error("WSAStartup() failed: " + std::to_string(WSAGetLastError()));
36
   }
37

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

44
inline void stop_sockets() { ::WSACleanup(); }
45

46
inline std::string err_to_string(int e) {
47
   // TODO use strerror_s here
48
   return "Error code " + std::to_string(e);
49
}
50

51
inline int close(int fd) { return ::closesocket(fd); }
52

53
inline int read(int s, void* buf, size_t len) {
54
   return ::recv(s, reinterpret_cast<char*>(buf), static_cast<int>(len), 0);
55
}
56

57
inline int send(int s, const uint8_t* buf, size_t len, int flags) {
58
   return ::send(s, reinterpret_cast<const char*>(buf), static_cast<int>(len), flags);
59
}
60

61
#elif defined(BOTAN_TARGET_OS_HAS_POSIX1)
62

63
   #include <arpa/inet.h>
64
   #include <errno.h>
65
   #include <fcntl.h>
66
   #include <netdb.h>
67
   #include <netinet/in.h>
68
   #include <sys/socket.h>
69
   #include <sys/time.h>
70
   #include <sys/types.h>
71
   #include <unistd.h>
72

73
typedef int socket_type;
74
typedef size_t sendrecv_len_type;
75

76
inline socket_type invalid_socket() { return -1; }
7✔
77

78
inline void close_socket(socket_type s) { ::close(s); }
5✔
79

80
inline void init_sockets() {}
7✔
81

82
inline void stop_sockets() {}
7✔
83

84
inline std::string err_to_string(int e) { return std::strerror(e); }
×
85

86
#endif
87

88
#if !defined(MSG_NOSIGNAL)
89
   #define MSG_NOSIGNAL 0
90
#endif
91

92
#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