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 * $FreeBSD: src/lib/libncp/ncpl_misc.c,v 1.3 1999/10/31 03:39:03 bp Exp $
33 * $DragonFly: src/lib/libncp/ncpl_misc.c,v 1.2 2003/06/17 04:26:50 dillon Exp $
35 * calls that don't fit to any other category
38 #include <sys/types.h>
44 #include <netncp/ncp_lib.h>
47 ncp_nw_to_ctime(struct nw_time_buffer
*source
) {
50 bzero(&u_time
,sizeof(struct tm
));
52 * XXX: NW 4.x tracks daylight automatically
55 u_time
.tm_sec
= source
->second
;
56 u_time
.tm_min
= source
->minute
;
57 u_time
.tm_hour
= source
->hour
;
58 u_time
.tm_mday
= source
->day
;
59 u_time
.tm_mon
= source
->month
- 1;
60 u_time
.tm_year
= source
->year
;
62 if (u_time
.tm_year
< 80) {
63 u_time
.tm_year
+= 100;
65 return mktime(&u_time
);
69 ncp_get_file_server_information(NWCONN_HANDLE connid
,
70 struct ncp_file_server_info
*target
)
75 ncp_init_request_s(conn
, 17);
76 if ((error
= ncp_request(connid
, 23, conn
)) != 0)
78 memcpy(target
, ncp_reply_data(conn
, 0), sizeof(*target
));
79 target
->MaximumServiceConnections
80 = htons(target
->MaximumServiceConnections
);
81 target
->ConnectionsInUse
82 = htons(target
->ConnectionsInUse
);
83 target
->MaxConnectionsEverUsed
84 = htons(target
->MaxConnectionsEverUsed
);
85 target
->NumberMountedVolumes
86 = htons(target
->NumberMountedVolumes
);
91 ncp_get_stations_logged_info(NWCONN_HANDLE connid
, u_int32_t connection
,
92 struct ncp_bindery_object
*target
, time_t *login_time
)
97 ncp_init_request_s(conn
, 28);
98 ncp_add_dword_lh(conn
, connection
);
100 if ((error
= ncp_request(connid
, 23, conn
)) != 0)
102 bzero(target
, sizeof(*target
));
103 target
->object_id
= ncp_reply_dword_hl(conn
, 0);
104 target
->object_type
= ncp_reply_word_hl(conn
, 4);
105 memcpy(target
->object_name
, ncp_reply_data(conn
, 6),
106 sizeof(target
->object_name
));
107 *login_time
= ncp_nw_to_ctime((struct nw_time_buffer
*)ncp_reply_data(conn
, 54));
112 ncp_get_internet_address(NWCONN_HANDLE connid
, u_int32_t connection
,
113 struct ipx_addr
*target
, u_int8_t
* conn_type
)
118 ncp_init_request_s(conn
, 26);
119 ncp_add_dword_lh(conn
, connection
);
120 error
= ncp_request(connid
, 23, conn
);
121 if (error
) return error
;
122 bzero(target
, sizeof(*target
));
123 ipx_netlong(*target
) = ncp_reply_dword_lh(conn
, 0);
124 memcpy(&(target
->x_host
), ncp_reply_data(conn
, 4), 6);
125 target
->x_port
= ncp_reply_word_lh(conn
, 10);
126 *conn_type
= ncp_reply_byte(conn
, 12);
131 NWGetObjectConnectionNumbers(NWCONN_HANDLE connHandle
,
132 pnstr8 pObjName
, nuint16 objType
,
133 pnuint16 pNumConns
, pnuint16 pConnHandleList
,
141 ncp_init_request_s(conn
, 27);
142 ncp_add_dword_lh(conn
, lastconn
);
143 ncp_add_word_hl(conn
, objType
);
144 ncp_add_pstring(conn
, pObjName
);
145 if ((error
= ncp_request(connHandle
, 23, conn
)) != 0) return error
;
146 n
= min(ncp_reply_byte(conn
, 0), maxConns
);
148 for (i
= 0; i
< n
; i
++) {
149 *pConnHandleList
++ = ncp_reply_dword_lh(conn
, i
* 4 + 1);
155 NWUnpackDateTime(nuint32 dateTime
, NW_DATE
*sDate
, NW_TIME
*sTime
) {
156 NWUnpackDate(dateTime
>> 16, sDate
);
157 NWUnpackTime(dateTime
& 0xffff, sTime
);
161 NWUnpackDate(nuint16 date
, NW_DATE
*sDate
) {
162 sDate
->day
= date
& 0x1f;
163 sDate
->month
= (date
>> 5) & 0xf;
164 sDate
->year
= ((date
>> 9) & 0x7f) + 1980;
168 NWUnpackTime(nuint16 time
, NW_TIME
*sTime
) {
169 sTime
->seconds
= time
& 0x1f;
170 sTime
->minutes
= (time
>> 5) & 0x3f;
171 sTime
->hours
= (time
>> 11) & 0x1f;
175 NWPackDateTime(NW_DATE
*sDate
, NW_TIME
*sTime
) {
180 NWPackDate(NW_DATE
*sDate
) {
185 NWPackTime(NW_TIME
*sTime
) {
190 ncp_UnpackDateTime(nuint32 dateTime
) {
195 NWUnpackDateTime(dateTime
, &d
, &t
);
196 bzero(&u_time
,sizeof(struct tm
));
197 u_time
.tm_isdst
= -1;
198 u_time
.tm_sec
= t
.seconds
;
199 u_time
.tm_min
= t
.minutes
;
200 u_time
.tm_hour
= t
.hours
;
201 u_time
.tm_mday
= d
.day
;
202 u_time
.tm_mon
= d
.month
- 1;
203 u_time
.tm_year
= d
.year
- 1900;
205 return mktime(&u_time
);
209 ncp_GetFileServerDateAndTime(NWCONN_HANDLE cH
, time_t *target
) {
213 ncp_init_request(conn
);
214 if ((error
= ncp_request(cH
, 20, conn
)) != 0)
216 *target
= ncp_nw_to_ctime((struct nw_time_buffer
*) ncp_reply_data(conn
, 0));
221 ncp_SetFileServerDateAndTime(NWCONN_HANDLE cH
, time_t * source
) {
223 struct tm
*utime
= localtime(source
);
226 year
= utime
->tm_year
;
230 ncp_init_request_s(conn
, 202);
231 ncp_add_byte(conn
, year
);
232 ncp_add_byte(conn
, utime
->tm_mon
+ 1);
233 ncp_add_byte(conn
, utime
->tm_mday
);
234 ncp_add_byte(conn
, utime
->tm_hour
);
235 ncp_add_byte(conn
, utime
->tm_min
);
236 ncp_add_byte(conn
, utime
->tm_sec
);
237 return ncp_request(cH
, 23, conn
);
241 NWDownFileServer(NWCONN_HANDLE cH
, int force
) {
244 ncp_init_request_s(conn
, 211);
245 ncp_add_byte(conn
, force
? 0 : 0xff);
246 return ncp_request(cH
, 23, conn
);
250 NWCloseBindery(NWCONN_HANDLE cH
) {
253 ncp_init_request_s(conn
, 68);
254 return ncp_request(cH
, 23, conn
);
258 NWOpenBindery(NWCONN_HANDLE cH
) {
261 ncp_init_request_s(conn
, 69);
262 return ncp_request(cH
, 23, conn
);
266 NWDisableTTS(NWCONN_HANDLE cH
) {
269 ncp_init_request_s(conn
, 207);
270 return ncp_request(cH
, 23, conn
);
274 NWEnableTTS(NWCONN_HANDLE cH
) {
277 ncp_init_request_s(conn
, 208);
278 return ncp_request(cH
, 23, conn
);
282 NWDisableFileServerLogin(NWCONN_HANDLE cH
) {
285 ncp_init_request_s(conn
, 203);
286 return ncp_request(cH
, 23, conn
);
290 NWEnableFileServerLogin(NWCONN_HANDLE cH
) {
293 ncp_init_request_s(conn
, 204);
294 return ncp_request(cH
, 23, conn
);