home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
IBM Presents OS/2 Software Hits 1995
/
OS-2_SW_HITS_2ND_EDITION_1995.ISO
/
i17
/
tliex2.exe
/
TLISVIPX.CPP
< prev
Wrap
C/C++ Source or Header
|
1994-11-09
|
4KB
|
155 lines
/* ************************************************************************ */
/* TLISVIPX.CPP
This example is the server side of a simple connectionless mode TLI example.
In this example, a simple message string is sent by the server, and
received by the client. The client prints this message out and continues
listening. The server terminates at this point.
*/
/* ************************************************************************ */
#define INCL_BASE
#define INCL_DOS
#define INCL_VIO
#include <os2.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <fcntl.h>
#include <malloc.h>
#include <string.h>
#define NWOS2 /* These defines are necessary for 32 bit compilation in */
#define IS32BIT /* Borland C++. Comparable includes are required for CSET2 */
#define BCPP /* and Watcom C++ */
#include <nwcaldef.h>
#include <tispxipx.h>
extern "C"{
#include <tiuser.h>
}
#define IPX_SOCKET 0x4645 /* Arbitrary Socket Number */
#define IPX_BUF 1000 /* Arbitrary Buffer Size */
int ParseAddress( char *address, IPX_ADDR *destination );
int PutAddress( char *string, char *buf, int hexBytes );
/* ParseAddress and PutAddress build an internetwork address from an
input address from the user. This address is then inserted into a
IPX_ADDR structure for use later in the program. */
int ParseAddress( char *addr, IPX_ADDR *destination )
{
if ( strlen( addr ) == 21 && addr[ 8 ] == '/' )
if ( PutAddress( addr, destination->ipxa_net, 4 ) )
if ( PutAddress( &addr[ 9 ], destination->ipxa_node, 6 ) )
return 1;
return 0;
} /* ParseAddress */
int PutAddress( char *string, char *buf, int hexBytes )
{
int i, j, value;
char c;
for ( i = 0; i < hexBytes; i++ )
{
value = 0; /* build a byte from two nibbles */
for ( j = 0; j < 2; j++ )
{
value <<= 4;
if ( ( c = toupper( *string ) ) >= '0' && c <= '9')
value += c - '0';
else if ( c >= 'A' && c <= 'F' )
value += c - 'A' + 10;
else
return 0;
string++;
}
*buf++ = value;
}
return 1;
} /* PutAddress */
void main ( int argc, char *argv[] )
{
IPX_ADDR ipx_addr; /* server address from command line */
SPX_OPTS spx_options;
int fd, bufSize, bufPos;
char dataBuf[IPX_BUF];
struct t_unitdata *unitdata;
BOOL moreData;
if ( argc != 2 || !ParseAddress( argv[ 1 ], &ipx_addr ) )
{
printf( "Usage:\tTLISVIPX Client Address\n" );
printf( "\tClient Address = Net/Node (in hex, leading zero's required)\n" );
printf( "\tExample:\"TLISVIPX 00001234/00001b02362e\"\n" );
exit( 1 );
}
/* NULL is used for the t_info parameter since the */
/* program is not making use of that information */
if (( fd = t_open( "/dev/nipx", O_RDWR, ( struct t_info * )0) ) == -1 )
{
t_error( "open of /dev/nipx failed" );
exit( 2 );
}
/* No need to bind to a specific socket since */
/* this application is only sending, not receiving */
/* The send socket is configured below in the */
/* ipx_addr.ipxa_socket variable */
if ( t_bind( fd, ( struct t_bind * )0, ( struct t_bind * )0 )== -1 )
{
t_error( "bind failed" );
exit( 2 );
}
unitdata=(struct t_unitdata *)t_alloc(fd, T_UNITDATA, T_ALL);
if(unitdata==NULL)
{
t_error( "t_alloc failed" );
exit( 2 );
}
/* This message will be sent out */
/* set dataBuf to whatever data you want sent out */
memset(dataBuf, 'A', IPX_BUF);
ipx_addr.ipxa_socket[ 0 ] = (IPX_SOCKET & 0xFF00)>>8;
ipx_addr.ipxa_socket[ 1 ] = IPX_SOCKET & 0x00FF;
unitdata->addr.buf = ( char * )&ipx_addr;
bufPos=0;
moreData=TRUE;
while(moreData){
if(unitdata->udata.maxlen < (sizeof(dataBuf)- bufPos))
{
bufSize=unitdata->udata.maxlen;
moreData=TRUE;
}
else
{
bufSize=sizeof(dataBuf)-bufPos;
moreData=FALSE;
}
memcpy(unitdata->udata.buf,&dataBuf[bufPos],bufSize);
bufPos +=bufSize;
unitdata->udata.len=bufSize;
if (t_sndudata(fd, unitdata) == -1)
{
t_error("Send Failed ");
exit(1);
}
} //end while moreData
}