if ((argc == 4) || ((argc == 3) && (expand == 0) ) ) /* Requested port number - decimal */
addr.sin_port = atoi( argv[2] );
else
addr.sin_port = DSTPORT; /* Default port number */
addr.sin_port = htons(addr.sin_port); /* Byte flip port number */
addr.sin_family = AF_INET;
/* Create a communication end point*/
if ((sock = socket( AF_INET, SOCK_STREAM, 0 )) < 0)
error (”socket failed”);
/* linger a second after close request before chopping connection, in case */
/* of any buffer flushing probs
optval.l_onoff = 1;
optval.l_linger = LINGER_TIME;
if (setsockopt(sock,SOL_SOCKET,SO_LINGER,&optval,sizeof(optval))<0)
error( ”failed to set LINGER option”);
/* Make a connection request */
if (connect( sock, &addr, sizeof(addr) ) < 0 )
error( ”connect failed”);
/* Transfer the data */
• write( sock, “\033\065\001”,3); /* ESC 5 1 (Begin Autoline Feed mode) */
while (more_data( buff, &size ))
{
if (write( sock, buff, size ) != size) /* While not EOF write away buffer */
error (”write failed”);
}
if (size)
{
if (write( sock, buff, size) != size)
error(”write failed”);
}
• write (sock, “\014”,1); /* Write FF */
close( sock );
}
/* .............. MORE_DATA .............. */
int more_data( array, size)
register char *array; /* Data buffer filled from stdin */
register int *size; /* Returns number of bytes in data buffer */
{
register int c; /* temp storage for characters */
/* Put data into buffer from standard input stream */
/* TELNET requires CR LF to be sent as ”\r” + ”\r\n” to ”\r */
for ( *size = 0 ; *size < BUFF_SIZE ; (*size)++ )
{
if (expand)
{ /* option to convert \n to \000\n */
X870-300351 Issue 1 H-3 Rev.0