📄 dcpfpkt.c
字号:
/*--------------------------------------------------------------------*/
/* d c p f p k t . c */
/* */
/* UUCP 'f' protocol support */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* Changes Copyright (c) 1989-1993 by Kendra Electronic */
/* Wonderworks. */
/* */
/* All rights reserved except those explicitly granted by */
/* the UUPC/extended license agreement. */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* RCS Information */
/*--------------------------------------------------------------------*/
/*
* $Id: dcpfpkt.c 1.12 1993/10/02 19:07:49 ahd Exp $
*
* Revision history:
* $Log: dcpfpkt.c $
* Revision 1.12 1993/10/02 19:07:49 ahd
* Suppress compiler warning
*
* Revision 1.11 1993/09/20 04:41:54 ahd
* OS/2 2.x support
*
* Revision 1.10 1993/07/31 16:27:49 ahd
* Changes in support of Robert Denny's Windows support
*
* Revision 1.9 1993/07/22 23:22:27 ahd
* First pass at changes for Robert Denny's Windows 3.1 support
*
* Revision 1.8 1993/05/30 00:01:47 ahd
* Multiple communications driver support
*
* Revision 1.7 1993/04/05 12:26:01 ahd
* Correct prototypes to match gpkt
*
* Revision 1.6 1993/04/05 04:35:40 ahd
* Allow unique send/receive packet sizes
*
* Revision 1.3 1992/11/19 02:36:29 ahd
* Revision 1.2 1992/11/15 20:10:47 ahd
* Clean up modem file support for different protocols
*/
/*--------------------------------------------------------------------*/
/* Flow control ("f") protocol. */
/* */
/* This protocol relies on flow control of the data stream. It */
/* is meant for working over links that can (almost) be */
/* guaranteed to be errorfree, specifically X.25/PAD links. A */
/* sumcheck is carried out over a whole file only. If a */
/* transport fails the receiver can request retransmission(s). */
/* This protocol uses a 7-bit datapath only, so it can be used */
/* on links that are not 8-bit transparent. */
/* */
/* When using this protocol with an X.25 PAD: Although this */
/* protocol uses no control chars except CR, control chars NULL */
/* and ^P are used before this protocol is started; since ^P is */
/* the default char for accessing PAD X.28 command mode, be */
/* sure to disable that access (PAD par 1). Also make sure */
/* both flow control pars (5 and 12) are set. The CR used in */
/* this proto is meant to trigger packet transmission, hence */
/* par 3 should be set to 2; a good value for the Idle Timer */
/* (par 4) is 10. All other pars should be set to 0. */
/* */
/* Normally a calling site will take care of setting the local */
/* PAD pars via an X.28 command and those of the remote PAD via */
/* an X.29 command, unless the remote site has a special */
/* channel assigned for this protocol with the proper par */
/* settings. */
/* */
/* Author: Piet Beertema, CWI, Amsterdam, Sep 1984 */
/* */
/* Adapted to uupc 3.0 and THINK C 4.0 by Dave Platt, Jul 1991 */
/* */
/* Adapted to UUPC/extended by Drew Derbyshire, 1992 */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* System include files */
/*--------------------------------------------------------------------*/
#include <stdio.h>
#include <time.h>
#include <string.h>
/*--------------------------------------------------------------------*/
/* UUPC/extended include files */
/*--------------------------------------------------------------------*/
#include "lib.h"
#include "dcp.h"
#include "dcpfpkt.h"
#include "dcpsys.h"
#include "hostable.h"
#include "security.h"
#include "ssleep.h"
#include "modem.h"
#include "commlib.h"
/*--------------------------------------------------------------------*/
/* Defines */
/*--------------------------------------------------------------------*/
#ifndef MAXMSGLEN
#define MAXMSGLEN BUFSIZ
#endif /* MAXMSGLEN */
currentfile();
/*--------------------------------------------------------------------*/
/* Internal function prototypes */
/*--------------------------------------------------------------------*/
static short fsendresp(short state);
/*--------------------------------------------------------------------*/
/* Global variables */
/*--------------------------------------------------------------------*/
static short chksum;
/*--------------------------------------------------------------------*/
/* f o p e n p k */
/* */
/* Open "f" protocol to other system */
/*--------------------------------------------------------------------*/
#ifdef __TURBOC__
#pragma argsused
#endif
short fopenpk(const boolean master)
{
flowcontrol(TRUE);
if ( M_fPacketSize > MAXPACK)
M_fPacketSize = MAXPACK;
r_pktsize = s_pktsize = M_fPacketSize;
ssleep(2); /* Give peer time to perform corresponding port setup */
return DCP_OK;
} /* fopenpk */
/*--------------------------------------------------------------------*/
/* f c l o s e p k */
/* */
/* Shutdown "f" procotol with other system */
/*--------------------------------------------------------------------*/
short fclosepk()
{
flowcontrol(FALSE);
return DCP_OK;
} /* fclosepk */
/*--------------------------------------------------------------------*/
/* f w r m s g */
/* */
/* Send a control message to remote system with "f" procotol */
/*--------------------------------------------------------------------*/
short fwrmsg(char *str)
{
char bufr[MAXMSGLEN];
char *s = bufr;
while (*str)
*s++ = *str++;
if (*(s-1) == '\n')
s--;
*s++ = '\r';
if (swrite(bufr, (unsigned int) (s - bufr)) == (unsigned int)(s - bufr))
return DCP_OK;
else
return DCP_FAILED;
} /* fwrmsg */
/*--------------------------------------------------------------------*/
/* f r d m s g */
/* */
/* Read a control message from remote host with "f" protocol */
/*--------------------------------------------------------------------*/
short frdmsg(char *str)
{
char *smax;
char *s = str;
smax = s + MAXPACK - 1;
for (;;) {
if (sread(s, 1, M_fPacketTimeout) <= 0)
{
printmsg(0,"frdmsg: timeout reading message");
*s++ = '\0';
goto msgerr;
}
if (*s == '\r')
break;
if (*s < ' ')
continue;
if (s++ >= smax)
{
printmsg(0,"frdmsg: buffer overflow");
*--s = '\0';
goto msgerr;
} /* if (s++ >= smax) */
}
*s = '\0';
return DCP_OK;
msgerr:
printmsg(0,"frdmsg: Message received \"%s\"", str);
return DCP_FAILED;
} /* frdmsg */
/*--------------------------------------------------------------------*/
/* f g e t p k t */
/* */
/* Receive an "f" protocol packet of data from the other system */
/*--------------------------------------------------------------------*/
short fgetpkt(char *packet, short *bytes)
{
char *op, c, *ip;
short sum, len, left;
char buf[5], tbuf[1];
short i;
static char special = 0;
static boolean eof = FALSE;
/*--------------------------------------------------------------------*/
/* Handle EOF on previous call */
/*--------------------------------------------------------------------*/
if ( eof )
{
eof = FALSE;
printmsg(2,"fgetpkt: EOF from other host");
*bytes = 0;
if (fsendresp(DCP_OK) == DCP_OK)
return DCP_OK;
else
return DCP_FAILED;
} /* if ( eof ) */
left = s_pktsize;
op = packet;
sum = chksum;
/*--------------------------------------------------------------------*/
/* Loop to fill up one packet */
/*--------------------------------------------------------------------*/
do {
ip = tbuf;
len = sread(ip, 1, M_fPacketTimeout); /* single-byte reads for now */
if (len == 0) {
printmsg(0,"fgetpkt: Timeout after %d seconds", M_fPacketTimeout);
return DCP_FAILED; /* Fail if timed out */
}
if ((*ip &= 0177) >= '\172') {
if (special) {
special = 0;
if (*ip++ != '\176')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -