/*
 * fwset: commands to insert things into a firewall
 *
 * functions: fwopen() opens a control socket
 *            fwcmd() does a command
 *            fwclose() closes a control socket
 */

#include <stdio.h>
#include <errno.h>
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <netdb.h>
#include <netinet/in.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/udp.h>
#include <linux/icmp.h>
#include <linux/if.h>
#include <linux/ip_fw.h>
#include <sys/param.h>


int
fwopen(int fw)
{
    int sock;

    if ((sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) == -1) {
	perror("ipfw: control socket open");
	return EOF;
    }
    return sock;
} /* fwopen */


int
fwclose(int sock)
{
    return close(sock);
} /* fwclose */


int
fwcmd(int sock, int cmd, char *data, int len)
{
    int rc;

    if ( (rc = setsockopt(sock, IPPROTO_IP, cmd, data, len)) == 0)
	return 0;
    perror("fwcmd");
    return EOF;
}
