16 #include <sys/socket.h>
17 #include <sys/sockio.h>
20 #include <net/if_dl.h>
21 #include <net/if_types.h>
44 strcpy(request.ifr_name, name);
56 u_char* buffer = (u_char*)handle->
buffer + handle->
offset;
57 struct sockaddr_dl from;
58 ssize_t bytesReceived;
69 (
struct sockaddr*)&from, &fromLength);
70 }
while (bytesReceived < 0 &&
errno == B_INTERRUPTED);
72 if (bytesReceived < 0) {
73 if (
errno == B_WOULD_BLOCK) {
83 int32 captureLength = bytesReceived;
84 if (captureLength > handle->
snapshot)
90 captureLength) == 0) {
98 header.
caplen = captureLength;
99 header.
len = bytesReceived;
100 header.
ts.tv_usec = system_time() % 1000000;
101 header.
ts.tv_sec = system_time() / 1000000;
105 callback(userdata, &header, buffer);
116 strlcpy(handle->
errbuf,
"Sending packets isn't supported yet",
132 if (
ioctl(
socket, SIOCGIFSTATS, &request,
sizeof(
struct ifreq)) < 0) {
140 handlep->
stat.
ps_recv += request.ifr_stats.receive.packets;
141 handlep->
stat.
ps_drop += request.ifr_stats.receive.dropped;
142 *stats = handlep->
stat;
164 if (handlep->
device == NULL) {
175 if (handle->
buffer == NULL) {
177 errno,
"buffer malloc");
201 "The networking stack doesn't seem to be available.\n");
205 struct ifreq request;
208 "Interface name \"%s\" is too long.",
device);
214 if (
ioctl(
socket, SIOCGIFINDEX, &request,
sizeof(request)) < 0) {
216 "Interface \"%s\" does not exist.\n",
device);
234 if (
ioctl(
socket, SIOCSPACKETCAP, &request,
sizeof(
struct ifreq)) < 0) {
242 if (handle == NULL) {
u_int pcap_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen, u_int buflen)
int pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf, int(*check_usable)(const char *), get_if_flags_func get_flags_func)
void pcap_fmt_errmsg_for_errno(char *errbuf, size_t errbuflen, int errnum, const char *fmt,...)
int install_bpf_program(pcap_t *p, struct bpf_program *fp)
int snprintf(char *, size_t, const char *,...)
int recvfrom(int, char *, u_int, int, struct sockaddr *, int *)
int ioctl(int, int, caddr_t)
int socket(int, int, int)
static int pcap_stats_haiku(pcap_t *handle, struct pcap_stat *stats)
static int pcap_read_haiku(pcap_t *handle, int maxPackets, pcap_handler callback, u_char *userdata)
static int get_if_flags(const char *name, bpf_u_int32 *flags, char *errbuf)
static int pcap_inject_haiku(pcap_t *handle, const void *buffer, int size)
pcap_t * pcap_create_interface(const char *device, char *errorBuffer)
static int pcap_activate_haiku(pcap_t *handle)
int pcap_platform_finddevs(pcap_if_list_t *_allDevices, char *errorBuffer)
static int can_be_bound(const char *name)
bool prepare_request(struct ifreq &request, const char *name)
int pcap_getnonblock_fd(pcap_t *)
int pcap_setnonblock_fd(pcap_t *p, int)
#define PCAP_CREATE_COMMON(ebuf, type)
#define PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE
void(* pcap_handler)(u_char *, const struct pcap_pkthdr *, const u_char *)
struct bpf_insn * bf_insns
activate_op_t activate_op
setnonblock_op_t setnonblock_op
setfilter_op_t setfilter_op
getnonblock_op_t getnonblock_op