home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1 / HamRadio.cdr / misc / tcpipsrc / usock.h < prev    next >
C/C++ Source or Header  |  1990-11-10  |  5KB  |  211 lines

  1. #ifndef    _USOCK_H
  2. #define    _USOCK_H
  3.  
  4. #ifndef    _MBUF_H
  5. #include "mbuf.h"
  6. #endif
  7.  
  8. #ifndef    _LZW_H
  9. #include "lzw.h"
  10. #endif
  11.  
  12. #ifndef _PROC_H
  13. #include "proc.h"
  14. #endif
  15.  
  16. #ifndef _TCP_H
  17. #include "tcp.h"
  18. #endif
  19.  
  20. #ifndef _UDP_H
  21. #include "udp.h"
  22. #endif
  23.  
  24. #ifndef _IP_H
  25. #include "ip.h"
  26. #endif
  27.  
  28. #ifndef _NETROM_H
  29. #include "netrom.h"
  30. #endif
  31.  
  32. /* Local IP wildcard address */
  33. #define    INADDR_ANY    0x0L
  34.  
  35. /* IP protocol numbers */
  36. #define    IPPROTO_ICMP    1
  37. #define    IPPROTO_TCP    6
  38. #define    IPPROTO_UDP    17
  39.  
  40. /* TCP port numbers */
  41. #define    IPPORT_ECHO    7    /* Echo data port */
  42. #define    IPPORT_DISCARD    9    /* Discard data port */
  43. #define    IPPORT_FTPD    20    /* FTP Data port */
  44. #define    IPPORT_FTP    21    /* FTP Control port */
  45. #define IPPORT_TELNET    23    /* Telnet port */
  46. #define IPPORT_SMTP    25    /* Mail port */
  47. #define    IPPORT_FINGER    79    /* Finger port */
  48. #define    IPPORT_TTYLINK    87    /* Chat port */
  49. #define    IPPORT_NNTP    119    /* Netnews port */
  50.  
  51. /* UDP port numbers */
  52. #define    IPPORT_DOMAIN    53
  53. #define    IPPORT_RIP    520
  54. #define    IPPORT_REMOTE    1234    /* Pulled out of the air */
  55.  
  56. #define    AF_INET        0
  57. #define    AF_AX25        1
  58. #define AF_NETROM    2
  59. #define    AF_LOCAL    3
  60.  
  61. #define    SOCK_STREAM    0
  62. #define    SOCK_DGRAM    1
  63. #define    SOCK_RAW    2
  64. #define SOCK_SEQPACKET    3
  65.  
  66. /* Socket flag values - controls newline mapping */
  67. #define    SOCK_BINARY    0    /* socket in raw (binary) mode */
  68. #define    SOCK_ASCII    1    /* socket in cooked (newline mapping) mode */
  69. #define    SOCK_QUERY    2    /* Return setting without change */
  70.  
  71. #define    EMFILE    1
  72. #define    EBADF    2
  73. #define    EINVAL    3
  74. #define    ESOCKTNOSUPPORT    4
  75. #define    EAFNOSUPPORT    5
  76. #define    EOPNOTSUPP    6
  77. #define    EFAULT        7
  78. #define    ENOTCONN    8
  79. #define    ECONNREFUSED    9
  80. #define EAFNOSUPP    10
  81. #define    EISCONN        11
  82. #define    EWOULDBLOCK    12
  83. #define    EINTR        13
  84. #define    EADDRINUSE    14
  85. #define    ENOMEM        15
  86. #define EMSGSIZE    16
  87. #define    EALARM        17
  88. #define    EABORT        18
  89.  
  90. extern int Axi_sock;    /* Socket listening to AX25 (there can be only one) */
  91.  
  92. /* Berkeley format socket address structures. These things were rather
  93.  * poorly thought out, but compatibility is important (or so they say).
  94.  * Note that all the sockaddr variants must be of the same size, 16 bytes
  95.  * to be specific. Although attempts have been made to account for alignment
  96.  * requirements (notably in sockaddr_ax), porters should check each
  97.  * structure.
  98.  */
  99.  
  100. /* Generic socket address structure */
  101. struct sockaddr {
  102.     short sa_family;
  103.     char sa_data[14];
  104. };
  105.  
  106. /* This is a structure for "historical" reasons (whatever they are) */
  107. struct in_addr {
  108.     unsigned long s_addr;
  109. };
  110.  
  111. /* Socket address, DARPA Internet style */
  112. struct sockaddr_in {
  113.     short sin_family;
  114.     unsigned short sin_port;
  115.     struct in_addr sin_addr;
  116.     char sin_zero[8];
  117. };
  118.  
  119. /* Number of chars in interface field. The involved definition takes possible
  120.  * alignment requirements into account, since ax25_addr is of an odd size.
  121.  */
  122. #define    ILEN    (sizeof(struct sockaddr) - sizeof(short) - AXALEN)
  123.  
  124. /* Socket address, AX.25 style */
  125. struct sockaddr_ax {
  126.     short sax_family;        /* 2 bytes */
  127.     char ax25_addr[AXALEN];
  128.     char iface[ILEN];        /* Interface name */
  129. };
  130.  
  131. struct sockaddr_nr {
  132.     short nr_family;
  133.     struct nr4_addr nr_addr;
  134. };
  135.  
  136. #define    SOCKSIZE    (sizeof(struct sockaddr))
  137. #define MAXSOCKSIZE    SOCKSIZE /* All sockets are of the same size for now */
  138. struct loc {
  139.     struct usock *peer;
  140.     struct mbuf *q;
  141.     int hiwat;        /* Flow control point */
  142.     int flags;
  143. #define    LOC_SHUTDOWN    1
  144. };
  145. #define    NULLLOC    (struct loc *)0
  146. #define    LOCDFLOW    5    /* dgram socket flow-control point, packets */
  147. #define    LOCSFLOW    2048    /* stream socket flow control point, bytes */
  148. #define    SOBUF        256    /* Size of buffer for usputc()/usprintf() */
  149. #define    SOCKBASE    128    /* Start of socket indexes */
  150.  
  151. union cb {
  152.     struct tcb *tcb;
  153.     struct ax25_cb *ax25;
  154.     struct udp_cb *udp;
  155.     struct raw_ip *rip;
  156.     struct raw_nr *rnr;
  157.     struct nr4cb *nr4;
  158.     struct loc *local;
  159.     char *p;
  160. };
  161. union sp {
  162.     struct sockaddr *sa;
  163.     struct sockaddr_in *in;
  164.     struct sockaddr_ax *ax;
  165.     struct sockaddr_nr *nr;
  166.     char *p;
  167. };
  168.  
  169. /* User sockets */
  170. struct usock {
  171.     struct proc *owner;
  172.     int refcnt;
  173.     char noblock;
  174.     char type;
  175. #define    NOTUSED            0
  176. #define    TYPE_TCP        1
  177. #define    TYPE_UDP        2
  178. #define    TYPE_AX25I        3
  179. #define    TYPE_AX25UI        4
  180. #define TYPE_RAW        5
  181. #define TYPE_NETROML3        6
  182. #define TYPE_NETROML4        7
  183. #define    TYPE_LOCAL_STREAM    8
  184. #define    TYPE_LOCAL_DGRAM    9
  185.     int rdysock;
  186.     union cb cb;
  187.     char *name;
  188.     int namelen;
  189.     char *peername;
  190.     int peernamelen;
  191.     char errcodes[4];    /* Protocol-specific error codes */
  192.     struct mbuf *obuf;    /* Output buffer */
  193.     struct mbuf *ibuf;    /* Input buffer */
  194.     char eol[3];        /* Text mode end-of-line sequence, if any */
  195.     int flag;        /* Mode flags, defined in socket.h */
  196.     int flush;        /* Character to trigger flush, if any */
  197.     struct lzw *zout;    /* Pointer to compression structure */
  198.     struct lzw *zin;
  199. };
  200. #define    NULLUSOCK    ((struct usock *)0)
  201.  
  202. extern char Badsocket[];
  203. extern char *Socktypes[];
  204. extern struct usock *Usock;
  205. extern int Nusock;
  206.  
  207. struct usock *itop __ARGS((int s));
  208. void st_garbage __ARGS((int red));
  209.  
  210. #endif /* _USOCK_H */
  211.