#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main (int argc, char **argv)
{
    char *cmd;

    if (argc!=3) {
	printf("Usage: wificmd add|delete ip_address.\n");
	exit(1);
    }

    if ( ( strcmp(argv[1], "add") != 0 ) && ( strcmp(argv[1], "delete") != 0 ) ) {
	printf("Invalid command.\n");
	exit(1);
    }

    if ( strlen(argv[2]) > 15 ) {
	printf("Invalid address.\n");
	exit(1);
    }

    cmd = malloc(512);
    sprintf(cmd, "/sbin/pfctl -t openwifi -T %s %s", argv[1], argv[2]);
    system(cmd);
    free(cmd);

    return 0;
}
