summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatias Fontanini <matias.fontanini@gmail.com>2021-03-06 11:34:51 -0800
committerGitHub <noreply@github.com>2021-03-06 11:34:51 -0800
commitb447c664e10d6cc78e27644aa2a70c71ac4f0de0 (patch)
tree0ab1efedab54c356aca9661f085a683a5e228b7b
parentcd40b232e737117e3057a80fb5321530f8183b73 (diff)
parent468159e6d2687243fcd6c647986d0c747192e19d (diff)
Merge pull request #433 from visuve/master
Close socket when setsockopt fails
-rw-r--r--src/packet_sender.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/packet_sender.cpp b/src/packet_sender.cpp
index c7a91e2..96f7649 100644
--- a/src/packet_sender.cpp
+++ b/src/packet_sender.cpp
@@ -267,6 +267,11 @@ void PacketSender::open_l3_socket(SocketType type) {
#endif
const int level = (is_v6) ? IPPROTO_IPV6 : IPPROTO_IP;
if (setsockopt(sockfd, level, IP_HDRINCL, (option_ptr)&on, sizeof(on)) != 0) {
+ #ifndef _WIN32
+ ::close(sockfd);
+ #else
+ ::closesocket(sockfd);
+ #endif
throw socket_open_error(make_error_string());
}