#ifndef _QUESO_H
#define _QUESO_H

#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/utility.h>
#include <proto/locale.h>
#include <proto/socket.h>
#include <proto/miami.h>

#include <libraries/miami.h>
#include <bsdsocket/socketbasetags.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/tcp.h>
#include <netinet/ip.h>
#include <net/pcap.h>
#include <net/if.h>
#include <net/route.h>
#include <netdb.h>

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <dos.h>
#include <ctype.h>
#include <time.h>

#include "macros.h"
#define CATCOMP_NUMBERS
#include "loc.h"
#include "queso_rev.h"

/***************************************************************************/

extern struct Library *SocketBase;
extern struct Library *MiamiBase;
extern struct LocaleBase *LocalBase;
extern struct Catalog *cat;

/***************************************************************************/

#define MAXPKT 6

enum
{
    YYY = 0x80,
    XXX = 0x40,
    URG = 0x20,
    ACK = 0x10,
    PSH = 0x08,
    RST = 0x04,
    SYN = 0x02,
    FIN = 0x01,
};

struct spoofrec
{
    struct sockaddr_in  from;
    struct sockaddr_in  dest;
    u_short             sport;
    u_short             dport;
    u_long              seq;
    u_long              ack;
};

struct answer
{
    u_short set;
    u_long  seq;
    u_long  ack;
    u_short urg;
    u_short win;
    u_short flag;
};

struct dMsg
{
    struct Message  link;
    struct tcphdr   tcp;
    int             ptype;
};

struct global
{
    char                    *optarg;
    int                     optind;
    int                     opterr;
    int                     optopt;

    struct SignalSemaphore  sem;
    struct MsgPort          port;
    struct dMsg             ma[MAXPKT+1];
    ULONG                   sigBit;
    struct Process          *this;
    ULONG                   flags;

    int                     sock;
    struct answer           a[MAXPKT+1];
    int                     count;
    u_long                  srch;
    u_long                  dsth;
    u_short                 srcp;
    u_short                 dstp;
    u_short                 start;

    struct MsgPort          timerPort;
    LONG                    tsigBit;
    struct timerequest      timerReq;

    struct sockaddr_in      dest;
    struct sockaddr_in      from;
    u_long                  addr;

    struct Hook             hook;
    APTR                    handle;
    char                    device[IFNAMSIZ+1];

    BPTR                    cfile;
    BPTR                    stdOut;
    BPTR                    stdErr;

    char                    *cfgFile;
    int                     timeout;
    int                     times;
    int                     delay;
    int                     defPort;
};

enum
{
    QFLG_CloseStderr = 1<<0,
    QFLG_FreeSig     = 1<<1,

    QFLG_Verbose     = 1<<8,
    QFLG_Debug       = 1<<9,
    QFLG_CfgDebug    = 1<<10,
    QFLG_CfgUpdate   = 1<<11,

    QFLG_TimerOpened = 1<<16,
    QFLG_TimerTiming = 1<<17,
};

/***************************************************************************/

#define CATNAME     "QueSO.catalog"
#define CFGFILENAME "QueSO.conf"

#define DEF_CFGFILE "PROGDIR:"CFGFILENAME
#define DEF_TIMEOUT 5
#define DEF_TIMES   1
#define DEF_DELAY   0
#define DEF_PORT    80

/***************************************************************************/

#include "queso_protos.h"

/***************************************************************************/

#endif /* _QUESO_H */
