4
/* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation
9
* Copyright (C) Richard Sharpe 1996
14
* This program is free software; you can redistribute it and/or modify
15
* it under the terms of the GNU General Public License as published by
16
* the Free Software Foundation; either version 2 of the License, or
17
* (at your option) any later version.
19
* This program is distributed in the hope that it will be useful,
20
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
* GNU General Public License for more details.
24
* You should have received a copy of the GNU General Public License
25
* along with this program; if not, write to the Free Software
26
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33
#include "rfcnb-error.h"
34
#include "rfcnb-common.h"
35
#include "byteorder.h"
38
#define RFCNB_Default_Port RFCNB_PORT
40
#define RFCNB_Default_Port 139
43
#define RFCNB_MAX_STATS 1
45
/* Protocol defines we need */
47
#define RFCNB_SESSION_MESSAGE 0
48
#define RFCNB_SESSION_REQUEST 0x81
49
#define RFCNB_SESSION_ACK 0x82
50
#define RFCNB_SESSION_REJ 0x83
51
#define RFCNB_SESSION_RETARGET 0x84
52
#define RFCNB_SESSION_KEEP_ALIVE 0x85
56
typedef struct redirect_addr *redirect_ptr;
58
struct redirect_addr {
60
struct in_addr ip_addr;
66
typedef struct RFCNB_Con {
68
int fd; /* File descripter for TCP/IP connection */
69
int rfc_errno; /* last error */
70
int timeout; /* How many milli-secs before IO times out */
71
int redirects; /* How many times we were redirected */
72
struct redirect_addr *redirect_list; /* First is first address */
73
struct redirect_addr *last_addr;
77
typedef char RFCNB_Hdr[4]; /* The header is 4 bytes long with */
78
/* char[0] as the type, char[1] the */
79
/* flags, and char[2..3] the length */
81
/* Macros to extract things from the header. These are for portability
82
* between architecture types where we are worried about byte order */
84
#define RFCNB_Pkt_Hdr_Len 4
85
#define RFCNB_Pkt_Sess_Len 72
86
#define RFCNB_Pkt_Retarg_Len 10
87
#define RFCNB_Pkt_Nack_Len 5
88
#define RFCNB_Pkt_Type_Offset 0
89
#define RFCNB_Pkt_Flags_Offset 1
90
#define RFCNB_Pkt_Len_Offset 2 /* Length is 2 bytes plus a flag bit */
91
#define RFCNB_Pkt_N1Len_Offset 4
92
#define RFCNB_Pkt_Called_Offset 5
93
#define RFCNB_Pkt_N2Len_Offset 38
94
#define RFCNB_Pkt_Calling_Offset 39
95
#define RFCNB_Pkt_Error_Offset 4
96
#define RFCNB_Pkt_IP_Offset 4
97
#define RFCNB_Pkt_Port_Offset 8
99
/* The next macro isolates the length of a packet, including the bit in the
102
#define RFCNB_Pkt_Len(p) (PVAL(p, 3) | (PVAL(p, 2) << 8) | \
103
((PVAL(p, RFCNB_Pkt_Flags_Offset) & 0x01) << 16))
105
#define RFCNB_Put_Pkt_Len(p, v) (p[1] = (((v) >> 16) & 1)); \
106
(p[2] = (((v) >> 8) & 0xFF)); \
107
(p[3] = ((v) & 0xFF));
109
#define RFCNB_Pkt_Type(p) (CVAL(p, RFCNB_Pkt_Type_Offset))
111
/*typedef struct RFCNB_Hdr {
113
* unsigned char type;
114
* unsigned char flags;
119
* typedef struct RFCNB_Sess_Pkt {
120
* unsigned char type;
121
* unsigned char flags;
123
* unsigned char n1_len;
124
* char called_name[33];
125
* unsigned char n2_len;
126
* char calling_name[33];
130
* typedef struct RFCNB_Nack_Pkt {
132
* struct RFCNB_Hdr hdr;
133
* unsigned char error;
137
* typedef struct RFCNB_Retarget_Pkt {
139
* struct RFCNB_Hdr hdr;
141
* unsigned char port;
143
* } RFCNB_Redir_Pkt; */
145
/* Static variables */
147
/* Only declare this if not defined */
150
extern int RFCNB_errno;
151
extern int RFCNB_saved_errno; /* Save this from point of error */
154
#endif /* __RFCNB_H__ */