Simplify ethsock_send()
This commit is contained in:
parent
2e5dbabf69
commit
6c1e661de2
1 changed files with 14 additions and 9 deletions
23
ethsock.c
23
ethsock.c
|
|
@ -28,6 +28,9 @@
|
||||||
|
|
||||||
#if defined(NMRPFLASH_WINDOWS)
|
#if defined(NMRPFLASH_WINDOWS)
|
||||||
#include <iphlpapi.h>
|
#include <iphlpapi.h>
|
||||||
|
#ifndef ERROR_NDIS_MEDIA_DISCONNECTED
|
||||||
|
#define ERROR_NDIS_MEDIA_DISCONNECTED 0x8034001f
|
||||||
|
#endif
|
||||||
#define WPCAP
|
#define WPCAP
|
||||||
#include <pcap.h>
|
#include <pcap.h>
|
||||||
#else
|
#else
|
||||||
|
|
@ -775,19 +778,21 @@ ssize_t ethsock_recv(struct ethsock *sock, void *buf, size_t len)
|
||||||
|
|
||||||
int ethsock_send(struct ethsock *sock, void *buf, size_t len)
|
int ethsock_send(struct ethsock *sock, void *buf, size_t len)
|
||||||
{
|
{
|
||||||
|
if (pcap_inject(sock->pcap, buf, len) != len) {
|
||||||
#ifdef NMRPFLASH_WINDOWS
|
#ifdef NMRPFLASH_WINDOWS
|
||||||
if (pcap_sendpacket(sock->pcap, buf, len) != 0 && verbosity > 1) {
|
// In recent Npcap versions, pcap_inject fails if the
|
||||||
pcap_perror(sock->pcap, "pcap_sendpacket");
|
// interface is unplugged. This doesn't happen on either
|
||||||
}
|
// Linux or macOS.
|
||||||
return 0;
|
|
||||||
#else
|
if (ethsock_is_unplugged(sock)) {
|
||||||
if (pcap_inject(sock->pcap, buf, len) == len) {
|
return 0;
|
||||||
return 0;
|
}
|
||||||
} else {
|
#endif
|
||||||
pcap_perror(sock->pcap, "pcap_inject");
|
pcap_perror(sock->pcap, "pcap_inject");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ethsock_close(struct ethsock *sock)
|
int ethsock_close(struct ethsock *sock)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue