Handle SAP responces in a more correct way. Allow connection number

greater than 255 in the broadcast messages.
This commit is contained in:
Boris Popov 1999-10-29 12:59:59 +00:00
parent fb9d6e45d1
commit 4d6357abda
4 changed files with 30 additions and 21 deletions

View File

@ -71,7 +71,7 @@ static char *server_name; /* need a better way ! */
int
ncp_li_setserver(struct ncp_conn_loginfo *li, const char *arg) {
if (strlen(arg) >= NCP_BINDERY_NAME_LEN) {
fprintf(stderr, "Server name too long:%s\n", arg);
ncp_error("server name '%s' too long", 0, arg);
return ENAMETOOLONG;
}
ncp_str_upper(strcpy(li->server, arg));
@ -81,7 +81,7 @@ ncp_li_setserver(struct ncp_conn_loginfo *li, const char *arg) {
int
ncp_li_setuser(struct ncp_conn_loginfo *li, char *arg) {
if (arg && strlen(arg) >= NCP_BINDERY_NAME_LEN) {
fprintf(stderr, "User name too long:%s\n", arg);
ncp_error("user name '%s' too long", 0, arg);
return ENAMETOOLONG;
}
if (li->user)
@ -99,7 +99,7 @@ ncp_li_setuser(struct ncp_conn_loginfo *li, char *arg) {
int
ncp_li_setpassword(struct ncp_conn_loginfo *li, const char *passwd) {
if (passwd && strlen(passwd) >= 127) {
fprintf(stderr, "Password too long:%s\n", passwd);
ncp_error("password too long", 0);
return ENAMETOOLONG;
}
if (li->password) {
@ -134,7 +134,7 @@ ncp_li_init(struct ncp_conn_loginfo *li, int argc, char *argv[]) {
li->group = NCP_DEFAULT_GROUP;
server_name = NULL;
if (argv == NULL) return 0;
while ((opt = ncp_getopt(argc, argv, ":S:U:")) != -1) {
while (error == 0 && (opt = ncp_getopt(argc, argv, ":S:U:")) != -1) {
arg = ncp_optarg;
switch (opt) {
case 'S':
@ -201,7 +201,7 @@ ncp_li_readrc(struct ncp_conn_loginfo *li) {
struct ncp_conn_stat cs;
if ((error = ncp_conn_scan(li, &connHandle)) != 0) {
fprintf(stderr, "no default connection found: %s\n",strerror(errno));
ncp_error("no default connection found", errno);
return error;
}
ncp_conn_getinfo(connHandle, &cs);
@ -247,18 +247,19 @@ ncp_li_check(struct ncp_conn_loginfo *li) {
do {
if (li->server[0] == 0) {
fprintf(stderr, "no server name specified\n");
ncp_error("no server name specified", 0);
error = 1;
break;
}
error = ncp_find_fileserver(li,
(server_name==NULL) ? AF_IPX : AF_INET, server_name);
if (error) {
fprintf(stderr,"Can't find server %s, error=%s\n",li->server,strerror(errno));
ncp_error("can't find server %s", error, li->server);
break;
}
if (li->user == NULL || li->user[0] == 0) {
fprintf(stderr, "no user name specified for server %s\n",li->server);
ncp_error("no user name specified for server %s",
0, li->server);
error = 1;
break;
}
@ -332,7 +333,8 @@ ncp_li_arg(struct ncp_conn_loginfo *li, int opt, char *arg) {
case 'I':
sig_level = atoi(arg);
if (sig_level < 0 || sig_level > 3) {
fprintf(stderr, "Invalid NCP signature level option `%s' (must be number between 0 and 3)\n", arg);
ncp_error("invalid NCP signature level option `%s'\
(must be a number between 0 and 3)", 0, arg);
error = 1;
}
li->sig_level = sig_level;

View File

@ -131,16 +131,20 @@ NWGetObjectConnectionNumbers(NWCONN_HANDLE connHandle,
pnuint16 pNumConns, pnuint16 pConnHandleList,
nuint16 maxConns)
{
int error, i;
int error, i, n;
nuint32 lastconn;
DECLARE_RQ;
ncp_init_request_s(conn, 21);
lastconn = 0;
ncp_init_request_s(conn, 27);
ncp_add_dword_lh(conn, lastconn);
ncp_add_word_hl(conn, objType);
ncp_add_pstring(conn, pObjName);
if ((error = ncp_request(connHandle, 23, conn)) != 0) return error;
i = ncp_reply_byte(conn,0);
*pNumConns = i;
for (i = min(i, maxConns); i; i--) {
pConnHandleList[i-1] = ncp_reply_byte(conn, i);
n = min(ncp_reply_byte(conn, 0), maxConns);
*pNumConns = n;
for (i = 0; i < n ; i++) {
*pConnHandleList++ = ncp_reply_dword_lh(conn, i * 4 + 1);
}
return 0;
}

View File

@ -50,6 +50,8 @@
/*#include <netncp/ncp_cfg.h>*/
#include "ncp_mod.h"
extern char *__progname;
int sysentoffset;
void
@ -437,6 +439,7 @@ void
ncp_error(char *fmt, int error,...) {
va_list ap;
fprintf(stderr, "%s: ", __progname);
va_start(ap, error);
vfprintf(stderr, fmt, ap);
va_end(ap);

View File

@ -280,12 +280,12 @@ sap_find_nearest(int server_type, struct sockaddr_ipx *daddr, char *server_name)
packets = 5;
do {
len = sap_recv(sock, data, sizeof(data), 0, 1);
if (len < 66) {
packets++;
continue;
}
} while (ntohs(reply->operation) != IPX_SAP_NEAREST_RESPONSE &&
packets > 0);
if (len >= 66 &&
ntohs(reply->operation) == IPX_SAP_NEAREST_RESPONSE)
break;
if (len < 0)
packets--;
} while (packets > 0);
if (packets == 0) {
close(sock);