1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Simplified error string generation on Sniffer::pcap_open_live_extended.

This commit is contained in:
Matias Fontanini
2014-05-05 08:32:45 -03:00
parent c249ff608c
commit b2788fad63
2 changed files with 4 additions and 14 deletions

View File

@@ -211,17 +211,7 @@ pcap_open_live_extended(const char *source, int snaplen, int promisc, int to_ms,
return (p);
fail:
if (status == PCAP_ERROR)
snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s", source,
pcap_geterr(p));
else if (status == PCAP_ERROR_NO_SUCH_DEVICE ||
status == PCAP_ERROR_PERM_DENIED ||
status == PCAP_ERROR_PROMISC_PERM_DENIED)
snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s (%s)", source,
pcap_statustostr(status), pcap_geterr(p));
else
snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s", source,
pcap_statustostr(status));
snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s", source, pcap_geterr(p));
pcap_close(p);
return (NULL);
}

View File

@@ -40,7 +40,7 @@ TEST_F(ICMPTest, DefaultConstructor) {
EXPECT_EQ(icmp.code(), 0);
EXPECT_EQ(icmp.type(), ICMP::ECHO_REQUEST);
EXPECT_EQ(icmp.id(), 0);
EXPECT_EQ(icmp.check(), 0);
EXPECT_EQ(icmp.checksum(), 0);
}
TEST_F(ICMPTest, CopyConstructor) {
@@ -79,7 +79,7 @@ TEST_F(ICMPTest, ChecksumOnTimestamp) {
EthernetII pkt(raw_pkt, sizeof(raw_pkt));
pkt.serialize();
EXPECT_EQ(0xb919, pkt.rfind_pdu<IP>().checksum());
EXPECT_EQ(0xed8d, pkt.rfind_pdu<ICMP>().check());
EXPECT_EQ(0xed8d, pkt.rfind_pdu<ICMP>().checksum());
}
TEST_F(ICMPTest, AddressMaskRequest) {
@@ -91,7 +91,7 @@ TEST_F(ICMPTest, AddressMaskRequest) {
EthernetII pkt(raw_pkt, sizeof(raw_pkt));
IP::serialization_type buffer = pkt.serialize();
EXPECT_EQ(0xf926, pkt.rfind_pdu<IP>().checksum());
EXPECT_EQ(0xeaf9, pkt.rfind_pdu<ICMP>().check());
EXPECT_EQ(0xeaf9, pkt.rfind_pdu<ICMP>().checksum());
EXPECT_EQ(IPv4Address("1.2.3.4"), pkt.rfind_pdu<ICMP>().address_mask());
}