Skip to content

Commit

Permalink
Merge pull request tcatm#15 from t-8ch/master
Browse files Browse the repository at this point in the history
clean up magic constants
  • Loading branch information
christf authored Sep 26, 2017
2 parents b647386 + 60c07d2 commit e31cc19
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
5 changes: 3 additions & 2 deletions src/arp.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <linux/netlink.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>
#include <linux/if_arp.h>

void arp_handle_in(arp_ctx *ctx, int fd) {
struct msghdr msghdr;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions src/arp.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#include <netinet/in.h>
#include <linux/rtnetlink.h>

#define ARP_REQUEST 1
#define ARP_REPLY 2

struct __attribute__((packed)) arp_packet {
uint16_t hd;
uint16_t pr;
Expand Down
2 changes: 2 additions & 0 deletions src/routemgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
17 changes: 5 additions & 12 deletions src/wifistations.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,7 @@
#include <netlink/msg.h>
#include <netlink/attr.h>

#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 <linux/nl80211.h>

void wifistations_handle_in(wifistations_ctx *ctx) {
nl_recvmsgs(ctx->nl_sock, ctx->cb);
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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);
Expand Down

0 comments on commit e31cc19

Please sign in to comment.