Skip to content

Commit

Permalink
Fix build on FreeBSD
Browse files Browse the repository at this point in the history
Closes #47
  • Loading branch information
baruch committed Oct 30, 2015
1 parent bfd7571 commit a2cf697
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
61 changes: 61 additions & 0 deletions arch/arch-freebsd.c
Expand Up @@ -5,6 +5,20 @@
#include <sys/types.h>

#include "arch-posix.c"
#include <net/if.h>

int disk_dev_identify(disk_dev_t *dev, char *vendor, char *model, char *fw_rev, char *serial, bool *is_ata, unsigned char *ata_buf, unsigned *ata_buf_len)
{
(void)dev;
strcpy(vendor, "UNKNOWN");
strcpy(model, "UNKNOWN");
strcpy(fw_rev, "UNKN");
strcpy(serial, "UNKNOWN");
*is_ata = 0;
*ata_buf_len = 0;
*ata_buf = 0;
return 0;
}

int disk_dev_read_cap(disk_dev_t *dev, uint64_t *size_bytes, uint64_t *sector_size)
{
Expand All @@ -18,3 +32,50 @@ int disk_dev_read_cap(disk_dev_t *dev, uint64_t *size_bytes, uint64_t *sector_si

return 0;
}

void mac_read(unsigned char *buf, int len)
{
struct ifreq ifr;
struct ifconf ifc;
char data[1024];
int success = 0;

buf[0] = 0;

int sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock == -1) {
return;
};

ifc.ifc_len = sizeof(data);
ifc.ifc_buf = data;
if (ioctl(sock, SIOCGIFCONF, &ifc) == -1) {
/* handle error */
goto Exit;
}

struct ifreq* it = ifc.ifc_req;
const struct ifreq* const end = it + (ifc.ifc_len / sizeof(struct ifreq));

for (; it != end; ++it) {
strcpy(ifr.ifr_name, it->ifr_name);
if (ioctl(sock, SIOCGIFFLAGS, &ifr) == 0) {
if (! (ifr.ifr_flags & IFF_LOOPBACK)) { // don't count loopback
if (ioctl(sock, SIOCGIFMAC, &ifr) == 0) {
success = 1;
break;
}
}
}
else { /* handle error */ }
}

if (success) {
memcpy(buf, ifr.ifr_ifru.ifru_data, len >= 6 ? 6 : len);
} else {
memset(buf, 0, len);
}

Exit:
close(sock);
}
12 changes: 11 additions & 1 deletion arch/arch-posix.c
Expand Up @@ -72,7 +72,17 @@ ssize_t disk_dev_write(disk_dev_t *dev, uint64_t offset_bytes, uint32_t len_byte

void disk_dev_cdb_in(disk_dev_t *dev, unsigned char *cdb, unsigned cdb_len, unsigned char *buf, unsigned buf_size, unsigned *buf_read, unsigned char *sense, unsigned sense_size, unsigned *sense_read, io_result_t *io_res)
{
(void)sense_size;
(void)sense;
(void)buf_size;
(void)buf;
(void)cdb_len;
(void)cdb;
(void)dev;

*sense_read = 0;
*buf_read = 0;
memset(&io_res, 0, sizeof(*io_res));
io_res->data = DATA_NONE;
io_res->error = ERROR_UNKNOWN;
io_res->error = ERROR_NONE;
}
2 changes: 1 addition & 1 deletion hdrhistogram/src/hdr_histogram_log.c
Expand Up @@ -39,7 +39,7 @@
#define be64toh(x) OSSwapBigToHostInt64(x)
#define le64toh(x) OSSwapLittleToHostInt64(x)

#elif defined(FREEBSD)
#elif defined(__FreeBSD__)

#include <sys/endian.h>

Expand Down

0 comments on commit a2cf697

Please sign in to comment.