Browse Source

remove Utils class's CLI dependency, add extra error checking and hide Utils class from public view

master
Brad Parker 11 years ago
parent
commit
80c0706dd9
  1. 1
      interface.cpp
  2. 3
      interface.h
  3. 2
      libip.pro
  4. 15
      libip_global.h
  5. 3
      neighbor.h
  6. 26
      utils.cpp
  7. 3
      utils.h
  8. 3
      wireless.h

1
interface.cpp

@ -8,7 +8,6 @@ extern "C" {
#include <linux/netlink.h>
#include <netlink/netlink.h>
#include <netlink/route/addr.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

3
interface.h

@ -2,8 +2,9 @@
#define LIBIP_INTERFACE_H
#include <QObject>
#include "libip_global.h"
class Q_DECL_EXPORT Interface : public QObject {
class LIBIP_EXPORT Interface : public QObject {
Q_OBJECT
public:

2
libip.pro

@ -7,6 +7,8 @@ TEMPLATE = lib
TARGET = ip
INCLUDEPATH += /usr/include/libnl3
DEFINES += LIBIP_LIBRARY
QMAKE_CXXFLAGS += -Wall -Wextra -Werror -fsanitize=address -fPIE
QMAKE_CFLAGS += -Wall -Wextra -Werror -fsanitize=address -fPIE

15
libip_global.h

@ -0,0 +1,15 @@
#include <QtGlobal>
#if defined(LIBIP_LIBRARY)
# define LIBIP_EXPORT Q_DECL_EXPORT
#else
# define LIBIP_EXPORT Q_DECL_IMPORT
#endif
#ifdef WIN32
#define LIBIP_LOCAL
#define LIBIP_PUBLIC
#else
#define LIBIP_LOCAL __attribute__((visibility("hidden")))
#define LIBIP_PUBLIC __attribute__((visibility("default")))
#endif

3
neighbor.h

@ -2,8 +2,9 @@
#define LIBIP_NEIGHBOR_H
#include <QObject>
#include "libip_global.h"
class Q_DECL_EXPORT Neighbor : public QObject {
class LIBIP_EXPORT Neighbor : public QObject {
Q_OBJECT
public:

26
utils.cpp

@ -1,9 +1,10 @@
extern "C" {
#include <netlink/cli/utils.h>
#include <netlink/cli/neigh.h>
#include <netlink/cli/addr.h>
#include <netlink/cli/link.h>
#include <pthread.h>
#include <netlink/socket.h>
#include <linux/netlink.h>
#include <netlink/netlink.h>
#include <netlink/route/addr.h>
#include <netlink/route/neighbour.h>
}
#include "utils.h"
@ -70,19 +71,18 @@ int Utils::alloc_neigh_cache(struct nl_sock *sock, struct nl_cache **cache) {
int Utils::interfaceIndex(QString interface) {
QByteArray array = interface.toLatin1();
struct nl_sock *sock = Utils::connect();
struct nl_sock *sock = nl_cli_alloc_socket();
nl_cli_connect(sock, NETLINK_ROUTE);
if(!sock) {
std::cerr << "could not allocate socket" << std::endl;
return -1;
}
const char *interfaceData = array.constData();
struct nl_cache *link_cache;
int ret = rtnl_link_alloc_cache(sock, AF_UNSPEC, &link_cache);
if(ret != 0) {
std::cerr << "could not allocate link cache" << std::endl;
QTimer::singleShot(0, qApp, SLOT(quit()));
struct nl_cache *link_cache = NULL;
if(!(Utils::alloc_link_cache(sock, &link_cache))) {
nl_socket_free(sock);
return -1;
}

3
utils.h

@ -2,8 +2,9 @@
#define LIBIP_UTILS_H
#include <QObject>
#include "libip_global.h"
class Q_DECL_EXPORT Utils : public QObject {
class LIBIP_LOCAL Utils : public QObject {
Q_OBJECT
public:

3
wireless.h

@ -3,8 +3,9 @@
#include <QObject>
#include <QMap>
#include "libip_global.h"
class Q_DECL_EXPORT Wireless : public QObject {
class LIBIP_EXPORT Wireless : public QObject {
Q_OBJECT
public:

Loading…
Cancel
Save