Skip to content

Commit

Permalink
barebones netctl monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
sunflsks committed Feb 18, 2022
1 parent 8d12d28 commit 8e5c02d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ NO_WIFI ?= 0
NO_AIRDROP ?= 0
NO_AIRPLANE ?= 0

ifeq ($(BUILD_FOR_MACOSX),1)
NO_CELLULAR = 1
NO_WIFI = 1
NO_AIRPLANE = 1
endif

CFLAGS += -DNO_CELLULAR=$(NO_CELLULAR) -DNO_WIFI=$(NO_WIFI) -DNO_AIRDROP=$(NO_AIRDROP) -DNO_AIRPLANE=$(NO_AIRPLANE)

SRC := netctl.c
Expand Down
15 changes: 13 additions & 2 deletions monitor/monitor.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#include <Foundation/Foundation.h>
#import <NetworkStatistics/NetworkStatistics.h>

void(^callback)(void*, void*) = ^(NStatSourceRef ref, void* arg2) {
static int ctr = 0;
printf("HELLO %d\n", ctr);
ctr++;
};

int nctl_monitor(int argc, char** argv) {
printf("Not supported yet\n");
return 1;
NStatManagerRef ref = NStatManagerCreate(kCFAllocatorDefault, dispatch_get_main_queue(), callback);
NStatManagerSetFlags(ref, 0);

NStatManagerAddAllTCPWithFilter(ref, 0, 0);

dispatch_main();
}
2 changes: 1 addition & 1 deletion netctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int main(int argc, char *argv[]) {

#if NO_MONITOR == 0
if (!strcmp(argv[1], "monitor"))
return nctl_monitor(argc, argv);
return nctl_monitor(argc-1, argv+1);
#endif

usage();
Expand Down

0 comments on commit 8e5c02d

Please sign in to comment.