@@ -103,7 +103,7 @@ bool Sniffer::bind_socket()
103103
104104 // Bind the socket to the specified IP address.
105105 const auto iface_addr = get_if_address (if_name_, sock_);
106- if (INVALID_SOCKET == bind (sock_, reinterpret_cast <const struct sockaddr *>(&iface_addr), sizeof (iface_addr)))
106+ if (- 1 == bind (sock_, reinterpret_cast <const struct sockaddr *>(&iface_addr), sizeof (iface_addr)))
107107 {
108108 std::cerr << " bind() failed: " << sock_wrap_.get_last_error_string () << " ." << std::endl;
109109 return false ;
@@ -124,7 +124,7 @@ bool Sniffer::switch_promisc(bool enabled) noexcept
124124 // interface.
125125 int rc = WSAIoctl (sock_, SIO_RCVALL, &value, sizeof (value), nullptr , 0 , &out, nullptr , nullptr );
126126
127- if (INVALID_SOCKET == rc)
127+ if (SOCKET_ERROR == rc)
128128 {
129129 std::cerr << " Ioctl() failed: " << sock_wrap_.get_last_error_code () << " ." << std::endl;
130130 return false ;
@@ -200,13 +200,14 @@ bool Sniffer::capture()
200200 // Read the next packet, blocking forever.
201201 const int rc = recv (sock_, buffer.data () + BUFFER_WRITE_OFFSET, BUFFER_SIZE_IP, 0 );
202202
203- if (INVALID_SOCKET == rc)
203+ if (- 1 == rc)
204204 {
205+ // Data receiving error.
205206 std::cerr << " recv() failed: " << sock_wrap_.get_last_error_string () << std::endl;
206207 return false ;
207208 }
208209
209- // Data receiving error , so stop reading packets.
210+ // Connection closed , so stop reading packets.
210211 if (!rc) return false ;
211212
212213 std::cout << rc << " bytes received..." << std::endl;
0 commit comments