2 * Copyright (c) 1999, Boris Popov
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Boris Popov.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * calls that don't fit to any other category
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include <sys/types.h>
40 #include <arpa/inet.h>
45 #include <netncp/ncp_lib.h>
48 ncp_nw_to_ctime(struct nw_time_buffer *source) {
51 bzero(&u_time,sizeof(struct tm));
53 * XXX: NW 4.x tracks daylight automatically
56 u_time.tm_sec = source->second;
57 u_time.tm_min = source->minute;
58 u_time.tm_hour = source->hour;
59 u_time.tm_mday = source->day;
60 u_time.tm_mon = source->month - 1;
61 u_time.tm_year = source->year;
63 if (u_time.tm_year < 80) {
64 u_time.tm_year += 100;
66 return mktime(&u_time);
70 ncp_get_file_server_information(NWCONN_HANDLE connid,
71 struct ncp_file_server_info *target)
76 ncp_init_request_s(conn, 17);
77 if ((error = ncp_request(connid, 23, conn)) != 0)
79 memcpy(target, ncp_reply_data(conn, 0), sizeof(*target));
80 target->MaximumServiceConnections
81 = htons(target->MaximumServiceConnections);
82 target->ConnectionsInUse
83 = htons(target->ConnectionsInUse);
84 target->MaxConnectionsEverUsed
85 = htons(target->MaxConnectionsEverUsed);
86 target->NumberMountedVolumes
87 = htons(target->NumberMountedVolumes);
92 ncp_get_stations_logged_info(NWCONN_HANDLE connid, u_int32_t connection,
93 struct ncp_bindery_object *target, time_t *login_time)
98 ncp_init_request_s(conn, 28);
99 ncp_add_dword_lh(conn, connection);
101 if ((error = ncp_request(connid, 23, conn)) != 0)
103 bzero(target, sizeof(*target));
104 target->object_id = ncp_reply_dword_hl(conn, 0);
105 target->object_type = ncp_reply_word_hl(conn, 4);
106 memcpy(target->object_name, ncp_reply_data(conn, 6),
107 sizeof(target->object_name));
108 *login_time = ncp_nw_to_ctime((struct nw_time_buffer *)ncp_reply_data(conn, 54));
113 ncp_get_internet_address(NWCONN_HANDLE connid, u_int32_t connection,
114 struct ipx_addr *target, u_int8_t * conn_type)
119 ncp_init_request_s(conn, 26);
120 ncp_add_dword_lh(conn, connection);
121 error = ncp_request(connid, 23, conn);
122 if (error) return error;
123 bzero(target, sizeof(*target));
124 ipx_netlong(*target) = ncp_reply_dword_lh(conn, 0);
125 memcpy(&(target->x_host), ncp_reply_data(conn, 4), 6);
126 target->x_port = ncp_reply_word_lh(conn, 10);
127 *conn_type = ncp_reply_byte(conn, 12);
132 NWGetObjectConnectionNumbers(NWCONN_HANDLE connHandle,
133 pnstr8 pObjName, nuint16 objType,
134 pnuint16 pNumConns, pnuint16 pConnHandleList,
142 ncp_init_request_s(conn, 27);
143 ncp_add_dword_lh(conn, lastconn);
144 ncp_add_word_hl(conn, objType);
145 ncp_add_pstring(conn, pObjName);
146 if ((error = ncp_request(connHandle, 23, conn)) != 0) return error;
147 n = min(ncp_reply_byte(conn, 0), maxConns);
149 for (i = 0; i < n ; i++) {
150 *pConnHandleList++ = ncp_reply_dword_lh(conn, i * 4 + 1);
156 NWUnpackDateTime(nuint32 dateTime, NW_DATE *sDate, NW_TIME *sTime) {
157 NWUnpackDate(dateTime >> 16, sDate);
158 NWUnpackTime(dateTime & 0xffff, sTime);
162 NWUnpackDate(nuint16 date, NW_DATE *sDate) {
163 sDate->day = date & 0x1f;
164 sDate->month = (date >> 5) & 0xf;
165 sDate->year = ((date >> 9) & 0x7f) + 1980;
169 NWUnpackTime(nuint16 time, NW_TIME *sTime) {
170 sTime->seconds = time & 0x1f;
171 sTime->minutes = (time >> 5) & 0x3f;
172 sTime->hours = (time >> 11) & 0x1f;
176 NWPackDateTime(NW_DATE *sDate, NW_TIME *sTime) {
181 NWPackDate(NW_DATE *sDate) {
186 NWPackTime(NW_TIME *sTime) {
191 ncp_UnpackDateTime(nuint32 dateTime) {
196 NWUnpackDateTime(dateTime, &d, &t);
197 bzero(&u_time,sizeof(struct tm));
198 u_time.tm_isdst = -1;
199 u_time.tm_sec = t.seconds;
200 u_time.tm_min = t.minutes;
201 u_time.tm_hour = t.hours;
202 u_time.tm_mday = d.day;
203 u_time.tm_mon = d.month - 1;
204 u_time.tm_year = d.year - 1900;
206 return mktime(&u_time);
210 ncp_GetFileServerDateAndTime(NWCONN_HANDLE cH, time_t *target) {
214 ncp_init_request(conn);
215 if ((error = ncp_request(cH, 20, conn)) != 0)
217 *target = ncp_nw_to_ctime((struct nw_time_buffer *) ncp_reply_data(conn, 0));
222 ncp_SetFileServerDateAndTime(NWCONN_HANDLE cH, time_t * source) {
224 struct tm *utime = localtime(source);
227 year = utime->tm_year;
231 ncp_init_request_s(conn, 202);
232 ncp_add_byte(conn, year);
233 ncp_add_byte(conn, utime->tm_mon + 1);
234 ncp_add_byte(conn, utime->tm_mday);
235 ncp_add_byte(conn, utime->tm_hour);
236 ncp_add_byte(conn, utime->tm_min);
237 ncp_add_byte(conn, utime->tm_sec);
238 return ncp_request(cH, 23, conn);
242 NWDownFileServer(NWCONN_HANDLE cH, int force) {
245 ncp_init_request_s(conn, 211);
246 ncp_add_byte(conn, force ? 0 : 0xff);
247 return ncp_request(cH, 23, conn);
251 NWCloseBindery(NWCONN_HANDLE cH) {
254 ncp_init_request_s(conn, 68);
255 return ncp_request(cH, 23, conn);
259 NWOpenBindery(NWCONN_HANDLE cH) {
262 ncp_init_request_s(conn, 69);
263 return ncp_request(cH, 23, conn);
267 NWDisableTTS(NWCONN_HANDLE cH) {
270 ncp_init_request_s(conn, 207);
271 return ncp_request(cH, 23, conn);
275 NWEnableTTS(NWCONN_HANDLE cH) {
278 ncp_init_request_s(conn, 208);
279 return ncp_request(cH, 23, conn);
283 NWDisableFileServerLogin(NWCONN_HANDLE cH) {
286 ncp_init_request_s(conn, 203);
287 return ncp_request(cH, 23, conn);
291 NWEnableFileServerLogin(NWCONN_HANDLE cH) {
294 ncp_init_request_s(conn, 204);
295 return ncp_request(cH, 23, conn);