home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
xtli1.exe
/
FILERX.C
next >
Wrap
Text File
|
1994-09-13
|
10KB
|
389 lines
/****************************************************************************
** File: FILERX.C
**
** Desc:
**
** This is an example of TLI communication for a DOS client. It compiles
** fine using MSC 6.0., just make sure you link the appropriate libraries:
**
** nwcalls+sTLI+sNWIPXSP (for small memory model).
**
** It recives a file from the server endpoint. It's companion program
** is called FILETX (FILETX.C & FILETX.NLM).
**
** Disclaimer:
**
** Novell, Inc. makes no representations or warranties with respect to
** any NetWare software, and specifically disclaims any express or
** implied warranties of merchantability, title, or fitness for a
** particular purpose.
**
** Distribution of any NetWare software is forbidden without the
** express written consent of Novell, Inc. Further, Novell reserves
** the right to discontinue distribution of any NetWare software.
**
** Novell is not responsible for lost profits or revenue, loss of use
** of the software, loss of data, costs of re-creating lost data, the
** cost of any substitute equipment or program, or claims by any party
** other than you. Novell strongly recommends a backup be made before
** any software is installed. Technical support for this software
** may be provided at the discretion of Novell.
**
** Programmers:
**
** Ini Who Firm
** --------------------------------------------------------------------------
** ABJ Adam B. Jerome Novell Developer Support.
**
** History:
**
** When Who What
** --------------------------------------------------------------------------
** 06-29-94 ABJ First code.
*/
/****************************************************************************
** Include headers, macros, etc.
*/
/*------------------------------------------------------------------------
** Standard Library.
*/
#include <stdlib.h> /* exit() */
#include <stdio.h> /* printf() */
#include <string.h> /* memset(), strupr(), memcpy() */
/*------------------------------------------------------------------------
** NetWare.
*/
#define NWDOS
#define O_RDWR 0x02
#include <nwcalls.h> /* NWReadPropertyValue(), NWWordSwap() */
#include <tiuser.h> /* t_open(), t_info, t_errno, TSYSERR, t_error(),... */
/*------------------------------------------------------------------------
** Module
*/
#define SERVER_TYPE 0x0275 /* Novell Developer Support test server type */
/****************************************************************************
** Get the Network:node:socket address of a server.
**
** NODE: This method assumes that we are attached to a NetWare fileserver.
*/
int GetIPXServerAddress(void *serverAddress, char *serverName, unsigned short serverType)
{
BYTE propValue[128];
int cCode;
BYTE moreSegments;
BYTE propertyFlags;
if(serverAddress != NULL)
memset(serverAddress, 0x00, 4+6+2);
cCode=NWReadPropertyValue(
/* connection */ 0, /* default connection */
/* objectName */ strupr(serverName),
/* objectType */ NWWordSwap(serverType),
/* propertyName */ "NET_ADDRESS",
/* dataSetIndex */ 1,
/* dataBuffer */ propValue,
/* moreFlag */ &moreSegments,
/* propertyFlags */ &propertyFlags
);
if(serverAddress != NULL)
if(!cCode) memcpy(serverAddress, propValue, 4+6+2);
return(cCode);
}
/****************************************************************************
** Program start
*/
void main(int argc, char **argv)
{
struct t_info tInfo;
struct t_call *tCall = NULL;
int flags = 0;
int bindFlag = (-1);
int connectFlag = (-1);
int i;
int fh;
int cCode;
char buf[47+1];
int keepLooping = 1;
/*------------------------------------------------------------------------
** Check command line args.
*/
if(argc != 2)
{
printf("Usage: %s <server's name>\n", argv[0]);
goto ERR_DONE;
}
/*------------------------------------------------------------------------
** Initialize a TLI endpoint.
*/
fh=t_open(
/* I- path */ "/dev/nspx",
/* I- oflag */ O_RDWR,
/* -O info */ &tInfo
);
if(fh == -1)
{
switch(t_errno)
{
case TSYSERR:
case TBADFLAG:
case TBADNAME:
default:
t_error("ERROR");
break;
}
goto ERR_DONE;
}
/*------------------------------------------------------------------------
** Have TLI assign an endpoint address (IPX socket Number).
*/
bindFlag=t_bind(fh, NULL, NULL);
if(bindFlag == -1)
{
t_error("ERROR: t_bind");
goto ERR_DONE;
}
/*------------------------------------------------------------------------
** Allocate and initialize TLI structures.
*/
tCall = (struct t_call *)t_alloc(
/* fd */ fh,
/* struct_type */ T_CALL,
/* fields */ T_ADDR
);
if(tCall == NULL)
{
switch(t_errno)
{
case TBADF:
case TSYSERR:
case TNOTSUPPORT:
case TNOSTRUCTYPE:
default:
t_error("ERROR:");
}
goto ERR_DONE;
}
/*------------------------------------------------------------------------
** Get the server's Net:node:socket via BINDERY query.
*/
tCall->addr.len = sizeof(IPX_ADDR);
cCode=GetIPXServerAddress(tCall->addr.buf, argv[1], SERVER_TYPE);
switch(cCode)
{
case 0:
break;
case 252:
printf("ERROR: No such object. [%s:%04hX]\n", argv[1], SERVER_TYPE);
goto ERR_DONE;
default:
printf("ERROR: GetServerAddress() returned 0x%04X\n", cCode);
goto ERR_DONE;
}
/*------------------------------------------------------------------------
** Establish connection.
*/
connectFlag=t_connect(
/* I- fd */ fh,
/* I- tCall */ tCall,
/* -O rcvcall */ NULL
);
if(connectFlag == -1) switch(t_errno)
{
case TBADF:
case TOUTSTATE:
case TNODATA:
case TBADADDR:
case TBADOPT:
case TBADDATA:
case TBUFOVFLW:
case TLOOK:
case TNOTSUPPORT:
case TSYSERR:
default:
t_error("ERROR");
goto ERR_DONE;
}
/*------------------------------------------------------------------------
** Recieve file.
*/
while(keepLooping)
{
memset(buf, 0x00, sizeof(buf));
cCode=t_rcv(
/* I- fd */ fh,
/* -O buf */ buf,
/* I- nbytes */ sizeof(buf)-1,
/* -O flags */ &flags
);
if(cCode == (-1))
{
switch(t_errno)
{
case TLOOK:
/*------------------------------------------------------------
** WHAT DO YOU WANT NOW!
*/
cCode = t_look(fh);
switch(cCode)
{
/*------------------------------------------------------------
** Disconnect request recieved?
*/
case T_DISCONNECT:
keepLooping=0;
continue;
/*------------------------------------------------------------
** Nothing happened. Try again.
*/
case 0:
break;
/*------------------------------------------------------------
** We don't expect these things to happen.
*/
case (-1):
case T_LISTEN:
case T_CONNECT:
case T_DATA:
case T_EXDATA:
case T_UDERR:
case T_ORDREL:
case T_GODATA:
case T_GOEXDATA:
default:
printf("ERROR: #%d\n", cCode);
keepLooping=0;
continue;
}
break;
/*---------------------------------------------------------------
** We don't expect these things to happen.
*/
case TBADF:
case TNODATA:
case TNOTSUPPORT:
case TOUTSTATE:
case TSYSERR:
default:
t_error("ERROR: ");
keepLooping=0;
continue;
}
}
else
printf("%s", buf);
}
ERR_DONE:
/*------------------------------------------------------------------------
** Destroy connection.
*/
if(connectFlag != (-1))
{
/*------------------------------------------------------------------
** Get connection status.
*/
cCode = !(T_DISCONNECT);
for(i=0; (i<60) && (cCode != T_DISCONNECT); i++)
{
cCode = t_look(fh);
switch(cCode)
{
/*------------------------------------------------------------
** Disconnect yet?
*/
case T_DISCONNECT:
continue; /* to top of (timmer) for loop */
/*------------------------------------------------------------
** Nothing happened. Try again.
*/
case 0:
break;
/*------------------------------------------------------------
** We don't expect these things to happen.
*/
case (-1):
case T_LISTEN:
case T_CONNECT:
case T_DATA:
case T_EXDATA:
case T_UDERR:
case T_ORDREL:
case T_GODATA:
case T_GOEXDATA:
default:
printf("ERROR: #%d\n", cCode);
i=1000;
continue;
}
}
if(i == 60) printf("ERROR: Discconnect timeout\n");
/*---------------------------------------------------------------------
** Disconnect.
*/
cCode=t_rcvdis(fh, NULL);
if(cCode == -1) switch(t_errno)
{
/*------------------------------------------------------------------
** We expect none of these.
*/
case TBADF:
case TNODIS:
case TBUFOVFLW:
case TNOTSUPPORT:
case TOUTSTATE:
case TSYSERR:
default:
t_error("ERROR");
break;
}
}
/*------------------------------------------------------------------------
** Release address. (SPX socket).
*/
if(bindFlag != (-1))
if(t_unbind(fh) == (-1)) t_error("ERROR: t_unbind");
/*------------------------------------------------------------------------
** Free up memory as needed.
*/
if(tCall != NULL)
if(t_free((char *)tCall, T_CALL) == -1) t_error("ERROR: t_free");
/*------------------------------------------------------------------------
** Close the TLI endpoint.
*/
if(fh != -1)
if(t_close(fh) == -1) t_error("ERROR: t_close");
exit(0);
}