import from branch_1_1:
[freeradius.git] / src / modules / rlm_smb / rfcnb-priv.h
1 /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation
2
3    Version 1.0
4    RFCNB Defines
5
6    Copyright (C) Richard Sharpe 1996
7    Copyright 2006 The FreeRADIUS server project
8
9 */
10
11 /*
12    This program is free software; you can redistribute it and/or modify
13    it under the terms of the GNU General Public License as published by
14    the Free Software Foundation; either version 2 of the License, or
15    (at your option) any later version.
16
17    This program is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20    GNU General Public License for more details.
21
22    You should have received a copy of the GNU General Public License
23    along with this program; if not, write to the Free Software
24    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
26
27 #include <freeradius-devel/ident.h>
28 RCSIDH(rfcnb_priv_h, "$Id$")
29
30 /* Defines we need */
31
32 typedef unsigned short uint16;
33
34 #define GLOBAL extern
35
36 #include "rfcnb-error.h"
37 #include "rfcnb-common.h"
38 #include "byteorder.h"
39
40 #ifdef RFCNB_PORT
41 #define RFCNB_Default_Port RFCNB_PORT
42 #else
43 #define RFCNB_Default_Port 139
44 #endif
45
46 #define RFCNB_MAX_STATS 1
47
48 /* Protocol defines we need */
49
50 #define RFCNB_SESSION_MESSAGE 0
51 #define RFCNB_SESSION_REQUEST 0x81
52 #define RFCNB_SESSION_ACK 0x82
53 #define RFCNB_SESSION_REJ 0x83
54 #define RFCNB_SESSION_RETARGET 0x84
55 #define RFCNB_SESSION_KEEP_ALIVE 0x85
56
57 /* Structures      */
58
59 typedef struct redirect_addr * redirect_ptr;
60
61 struct redirect_addr {
62
63   struct in_addr ip_addr;
64   int port;
65   redirect_ptr next;
66
67 };
68
69 typedef struct RFCNB_Con {
70
71   int fd;                     /* File descripter for TCP/IP connection */
72   int rfc_errno;                  /* last error                            */
73   int timeout;                /* How many milli-secs before IO times out */
74   int redirects;              /* How many times we were redirected     */
75   struct redirect_addr *redirect_list;  /* First is first address */
76   struct redirect_addr *last_addr;
77
78 } RFCNB_Con;
79
80 typedef char RFCNB_Hdr[4]; /* The header is 4 bytes long with  */
81                                     /* char[0] as the type, char[1] the */
82                                     /* flags, and char[2..3] the length */
83
84 /* Macros to extract things from the header. These are for portability
85    between architecture types where we are worried about byte order     */
86
87 #define RFCNB_Pkt_Hdr_Len        4
88 #define RFCNB_Pkt_Sess_Len       72
89 #define RFCNB_Pkt_Retarg_Len     10
90 #define RFCNB_Pkt_Nack_Len       5
91 #define RFCNB_Pkt_Type_Offset    0
92 #define RFCNB_Pkt_Flags_Offset   1
93 #define RFCNB_Pkt_Len_Offset     2   /* Length is 2 bytes plus a flag bit */
94 #define RFCNB_Pkt_N1Len_Offset   4
95 #define RFCNB_Pkt_Called_Offset  5
96 #define RFCNB_Pkt_N2Len_Offset   38
97 #define RFCNB_Pkt_Calling_Offset 39
98 #define RFCNB_Pkt_Error_Offset   4
99 #define RFCNB_Pkt_IP_Offset      4
100 #define RFCNB_Pkt_Port_Offset    8
101
102 /* The next macro isolates the length of a packet, including the bit in the
103    flags                                                                   */
104
105 #define RFCNB_Pkt_Len(p)  (PVAL(p, 3) | (PVAL(p, 2) << 8) |     \
106                           ((PVAL(p, RFCNB_Pkt_Flags_Offset) & 0x01) << 16))
107
108 #define RFCNB_Put_Pkt_Len(p, v) (p[1] = ((v >> 16) & 1)); \
109                                 (p[2] = ((v >> 8) & 0xFF)); \
110                                 (p[3] = (v & 0xFF));
111
112 #define RFCNB_Pkt_Type(p) (CVAL(p, RFCNB_Pkt_Type_Offset))
113
114 /*typedef struct RFCNB_Hdr {
115
116   unsigned char type;
117   unsigned char flags;
118   int16 len;
119
120   } RFCNB_Hdr;
121
122 typedef struct RFCNB_Sess_Pkt {
123     unsigned char type;
124     unsigned char flags;
125     int16 length;
126     unsigned char n1_len;
127     char called_name[33];
128     unsigned char n2_len;
129     char calling_name[33];
130   } RFCNB_Sess_Pkt;
131
132
133 typedef struct RFCNB_Nack_Pkt {
134
135   struct RFCNB_Hdr hdr;
136   unsigned char error;
137
138   } RFCNB_Nack_Pkt;
139
140 typedef struct RFCNB_Retarget_Pkt {
141
142   struct RFCNB_Hdr hdr;
143   int dest_ip;
144   unsigned char port;
145
146   } RFCNB_Redir_Pkt; */
147
148 /* Static variables */
149
150 /* Only declare this if not defined */
151
152 #ifndef RFCNB_ERRNO
153 extern int RFCNB_errno;
154 extern int RFCNB_saved_errno;    /* Save this from point of error */
155 #endif