home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 3 / hamradioversion3.0examsandprograms1992.iso / misc / 9q920411 / iface.h < prev    next >
C/C++ Source or Header  |  1992-04-06  |  5KB  |  144 lines

  1. #ifndef    _IFACE_H
  2. #define    _IFACE_H
  3.  
  4. #ifndef    _GLOBAL_H
  5. #include "global.h"
  6. #endif
  7.  
  8. #ifndef    _MBUF_H
  9. #include "mbuf.h"
  10. #endif
  11.  
  12. #ifndef _PROC_H
  13. #include "proc.h"
  14. #endif
  15.  
  16. /* Interface encapsulation mode table entry. An array of these structures
  17.  * are initialized in config.c with all of the information necessary
  18.  * to attach a device.
  19.  */
  20. struct iftype {
  21.     char *name;        /* Name of encapsulation technique */
  22.     int (*send) __ARGS((struct mbuf *,struct iface *,int32,int));
  23.                 /* Routine to send an IP datagram */
  24.     int (*output) __ARGS((struct iface *,char *,char *,int16,struct mbuf *));
  25.                 /* Routine to send link packet */
  26.     char *(*format) __ARGS((char *,char *));
  27.                 /* Function that formats addresses */
  28.     int (*scan) __ARGS((char *,char *));
  29.                 /* Reverse of format */
  30.     int type;        /* Type field for network process */
  31.     int hwalen;        /* Length of hardware address, if any */
  32. };
  33. #define    NULLIFT    (struct iftype *)0
  34. extern struct iftype Iftypes[];
  35.  
  36.  
  37. /* Interface control structure */
  38. struct iface {
  39.     struct iface *next;    /* Linked list pointer */
  40.     char *name;        /* Ascii string with interface name */
  41.  
  42.     int32 addr;        /* IP address */
  43.     int32 broadcast;    /* Broadcast address */
  44.     int32 netmask;        /* Network mask */
  45.  
  46.     int16 mtu;        /* Maximum transmission unit size */
  47.  
  48.     int16 flags;        /* Configuration flags */
  49. #define    DATAGRAM_MODE    0    /* Send datagrams in raw link frames */
  50. #define    CONNECT_MODE    1    /* Send datagrams in connected mode */
  51.     int16 trace;        /* Trace flags */
  52. #define    IF_TRACE_OUT    0x01    /* Output packets */
  53. #define    IF_TRACE_IN    0x10    /* Packets to me except broadcast */
  54. #define    IF_TRACE_ASCII    0x100    /* Dump packets in ascii */
  55. #define    IF_TRACE_HEX    0x200    /* Dump packets in hex/ascii */
  56. #define    IF_TRACE_NOBC    0x1000    /* Suppress broadcasts */
  57. #define    IF_TRACE_RAW    0x2000    /* Raw dump, if supported */
  58.     char *trfile;        /* Trace file name, if any */
  59.     FILE *trfp;        /* Stream to trace to */
  60.  
  61.     struct iface *forw;    /* Forwarding interface for output, if rx only */
  62.  
  63.     struct proc *rxproc;    /* Receiver process, if any */
  64.     struct proc *txproc;    /* IP send process */
  65.     struct proc *supv;    /* Supervisory process, if any */
  66.  
  67.     struct mbuf *outq;    /* IP datagram transmission queue */
  68.  
  69.     /* Device dependent */
  70.     int dev;        /* Subdevice number to pass to send */
  71.                 /* To device -- control */
  72.     int32 (*ioctl) __ARGS((struct iface *,int cmd,int set,int32 val));
  73.                 /* From device -- when status changes */
  74.     int (*iostatus) __ARGS((struct iface *,int cmd,int32 val));
  75.                 /* Call before detaching */
  76.     int (*stop) __ARGS((struct iface *));
  77.     char *hwaddr;        /* Device hardware address, if any */
  78.  
  79.     /* Encapsulation dependent */
  80.     void *edv;        /* Pointer to protocol extension block, if any */
  81.     int type;        /* Link header type for phdr */
  82.     int xdev;        /* Associated Slip or Nrs channel, if any */
  83.     struct iftype *iftype;    /* Pointer to appropriate iftype entry */
  84.  
  85.                 /* Routine to send an IP datagram */
  86.     int (*send) __ARGS((struct mbuf *,struct iface *,int32,int));
  87.             /* Encapsulate any link packet */
  88.     int (*output) __ARGS((struct iface *,char *,char *,int16,struct mbuf *));
  89.             /* Send raw packet */
  90.     int (*raw)        __ARGS((struct iface *,struct mbuf *));
  91.             /* Display status */
  92.     void (*show)        __ARGS((struct iface *));
  93.  
  94.     int (*discard)        __ARGS((struct iface *,struct mbuf *));
  95.     int (*echo)        __ARGS((struct iface *,struct mbuf *));
  96.  
  97.     /* Counters */
  98.     int32 ipsndcnt;     /* IP datagrams sent */
  99.     int32 rawsndcnt;    /* Raw packets sent */
  100.     int32 iprecvcnt;    /* IP datagrams received */
  101.     int32 rawrecvcnt;    /* Raw packets received */
  102.     int32 lastsent;        /* Clock time of last send */
  103.     int32 lastrecv;        /* Clock time of last receive */
  104. };
  105. #define    NULLIF    (struct iface *)0
  106. extern struct iface *Ifaces;    /* Head of interface list */
  107. extern struct iface  Loopback;    /* Optional loopback interface */
  108. extern struct iface  Encap;    /* IP-in-IP pseudo interface */
  109.  
  110. /* Header put on front of each packet in input queue */
  111. struct phdr {
  112.     struct iface *iface;
  113.     unsigned short type;    /* Use pktdrvr "class" values */
  114. };
  115. /* Header put on front of each packet sent to an interface */
  116. struct qhdr {
  117.     char tos;
  118.     int32 gateway;
  119. };
  120. /* List of link-level receive functions, initialized in config.c */
  121. struct rfunc {
  122.     int class;
  123.     void (*rcvf) __ARGS((struct iface *,struct mbuf *));
  124. };
  125. extern struct rfunc Rfunc[];
  126.  
  127. extern char Noipaddr[];
  128. extern struct mbuf *Hopper;
  129.  
  130. /* In iface.c: */
  131. struct iface *if_lookup __ARGS((char *name));
  132. struct iface *ismyaddr __ARGS((int32 addr));
  133. int if_detach __ARGS((struct iface *ifp));
  134. int setencap __ARGS((struct iface *ifp,char *mode));
  135. char *if_name __ARGS((struct iface *ifp,char *comment));
  136. int bitbucket __ARGS((struct iface *ifp,struct mbuf *bp));
  137. void if_tx __ARGS((int dev,void *arg1,void *unused));
  138. void network __ARGS((int i,void *v1,void *v2));
  139.  
  140. /* In config.c: */
  141. int net_route __ARGS((struct iface *ifp,int type,struct mbuf *bp));
  142.  
  143. #endif    /* _IFACE_H */
  144.