From 60c07d258a7369557655625bfed813bcb29b30be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Tue, 26 Sep 2017 17:45:51 +0000 Subject: [PATCH] clean up magic constants --- src/arp.c | 5 +++-- src/arp.h | 3 --- src/routemgr.h | 2 ++ src/wifistations.c | 17 +++++------------ 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/arp.c b/src/arp.c index 9a2dd05..42982e0 100644 --- a/src/arp.c +++ b/src/arp.c @@ -6,6 +6,7 @@ #include #include #include +#include void arp_handle_in(arp_ctx *ctx, int fd) { struct msghdr msghdr; @@ -36,7 +37,7 @@ void arp_handle_in(arp_ctx *ctx, int fd) { if (rc == -1) return; - if (packet.op != htons(ARP_REPLY)) + if (packet.op != htons(ARPOP_REPLY)) return; uint8_t *mac = lladdr.sll_addr; @@ -58,7 +59,7 @@ void arp_send_request(arp_ctx *ctx, const struct in6_addr *addr) { .pr = htons(0x800), .hdl = 6, .prl = 4, - .op = htons(ARP_REQUEST) + .op = htons(ARPOP_REQUEST) }; memcpy(&packet.sha, ctx->mac, 6); diff --git a/src/arp.h b/src/arp.h index 866fdb5..95be207 100644 --- a/src/arp.h +++ b/src/arp.h @@ -5,9 +5,6 @@ #include #include -#define ARP_REQUEST 1 -#define ARP_REPLY 2 - struct __attribute__((packed)) arp_packet { uint16_t hd; uint16_t pr; diff --git a/src/routemgr.h b/src/routemgr.h index f2a801b..565d28b 100644 --- a/src/routemgr.h +++ b/src/routemgr.h @@ -12,7 +12,9 @@ ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg)))) #endif +#ifndef RTA_ALIGNTO #define RTA_ALIGNTO 4 +#endif #define RTA_ALIGN(len) ( ((len)+RTA_ALIGNTO-1) & ~(RTA_ALIGNTO-1) ) #define RTA_LENGTH(len) (RTA_ALIGN(sizeof(struct rtattr)) + (len)) #define RTA_DATA(rta) ((void*)(((char*)(rta)) + RTA_LENGTH(0))) diff --git a/src/wifistations.c b/src/wifistations.c index 69e0cf9..5e88397 100644 --- a/src/wifistations.c +++ b/src/wifistations.c @@ -20,14 +20,7 @@ #include #include -#define NL80211_CMD_NEW_STATION 19 -#define NL80211_CMD_DEL_STATION 20 -#define NL80211_ATTR_IFINDEX 3 -#define NL80211_ATTR_MAC 6 - -static int no_seq_check(struct nl_msg *msg, void *arg) { - return NL_OK; -} +#include void wifistations_handle_in(wifistations_ctx *ctx) { nl_recvmsgs(ctx->nl_sock, ctx->cb); @@ -79,13 +72,15 @@ void wifistations_init(wifistations_ctx *ctx) { exit_error("Failed to allocate netlink socket.\n"); nl_socket_set_buffer_size(ctx->nl_sock, 8192, 8192); + /* no sequence checking for multicast messages */ + nl_socket_disable_seq_check(ctx->nl_sock); if (genl_connect(ctx->nl_sock)) { fprintf(stderr, "Failed to connect to generic netlink.\n"); goto fail; } - int nl80211_id = genl_ctrl_resolve(ctx->nl_sock, "nl80211"); + int nl80211_id = genl_ctrl_resolve(ctx->nl_sock, NL80211_GENL_NAME); if (nl80211_id < 0) { fprintf(stderr, "nl80211 not found.\n"); /* To resolve issue #29 we do not bail out, but return with an @@ -98,7 +93,7 @@ void wifistations_init(wifistations_ctx *ctx) { } /* MLME multicast group */ - int mcid = nl_get_multicast_id(ctx->nl_sock, "nl80211", "mlme"); + int mcid = nl_get_multicast_id(ctx->nl_sock, NL80211_GENL_NAME, NL80211_MULTICAST_GROUP_MLME); if (mcid >= 0) { int ret = nl_socket_add_membership(ctx->nl_sock, mcid); if (ret) @@ -110,8 +105,6 @@ void wifistations_init(wifistations_ctx *ctx) { if (!ctx->cb) exit_error("failed to allocate netlink callbacks\n"); - /* no sequence checking for multicast messages */ - nl_cb_set(ctx->cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL); nl_cb_set(ctx->cb, NL_CB_VALID, NL_CB_CUSTOM, wifistations_handle_event, ctx); ctx->fd = nl_socket_get_fd(ctx->nl_sock);