?? lqrp.c
字號:
#include <string.h>
#include "net.h"
#include "local.h"
#include "support.h"
#include "ppp.h"
#ifdef LQRP
extern struct NET nets[];
extern struct CONNECT connblo[];
extern struct NETCONF netconf[];
extern GLOBALCONST PTABLE ussLQRPTable;
/* This is the link quality report. The last 5 fields are present after
a read, but are not written. LQRP sets packet size automatically, so
the application can write the whole structure if that is convenient.
The structure isn't used in the protocol module, because the alignments
are not right.
*/
struct LQreport {
unsigned long MagicNumber;/* RFC has a hyphen */
unsigned long LastOutLQRs;
unsigned long LastOutPackets;
unsigned long LastOutOctets;
unsigned long PeerINLQRs;
unsigned long PeerInPackets;
unsigned long PeerInDiscards;
unsigned long PeerInErrors;
unsigned long PeerInOctets;
unsigned long PeerOutLQRs;
unsigned long PeerOutPackets;
unsigned long PeerOutOctets;
unsigned long SaveInLQRs; /* these read but not written */
unsigned long SaveInPackets;
unsigned long SaveInDiscards;
unsigned long SaveInErrors;
unsigned long SaveInOctets;
};
#ifndef LITTLE
#define STORE32(addr, val) Nmemcpy(addr, &(char *)val, 4)
#else
#define STORE32(addr, val) un.ul=val, \
(addr)[0] = un.c[3], (addr)[1] = un.c[2], \
(addr)[2] = un.c[1], (addr)[3] = un.c[0]
#endif
static int writE(int conno, MESS *mess)
{
int netno;
unsigned char *cp;
unsigned long ul1;
struct NET *netp;
union {
unsigned long ul;
char c[4];
} un;
netno = mess->netno;
netp = &nets[netno];
if ((netp->hw.remopts & (1 << 4)) == 0)
return ENOPROTOOPT;
netp->OutLQRs++;
cp = (char *) mess + MESSH_SZ + LHDRSZ;
*(unsigned short *) (cp - 2) = NC2(PROTlqp);
memset(cp, 0, 100);
Nmemcpy(cp + 4, netp->lastins, 32);
STORE32(cp + 36, netp->OutLQRs);
ul1 = netp->ifOutUcastPkts + 1;
STORE32(cp + 40, ul1);
ul1 = netp->ifOutOctets + 48;
STORE32(cp + 44, ul1);
mess->mlen = 48 + MESSH_SZ + LHDRSZ;
return netp->protoc[0]->writE(conno, mess);
}
/* ===========================================================================
Screen an arrived serial message. Returns:
-3 call write
-2 no further action
-1 error occured
n please enter in queue number n
*/
static int screen(MESS *mess)
{
int i1, conno, netno;
char cc, *cp;
struct CONNECT *conp;
struct NET *netp;
/**
** Look for the connection block. If the user specified this protocol,
** we give the message to the user.
**/
netno = mess->netno;
netp = &nets[netno];
if (mess->mlen - MESSH_SZ - LHDRSZ < 48)
goto ret9;
cp = (unsigned char *) mess + MESSH_SZ + LHDRSZ + 4;
Nmemcpy(netp->lastins, cp, 32);
for (conno = 0; conno < NCONNS; conno++) {
conp = &connblo[conno];
if (conp->blockstat == 0)
continue;
if (netno != conp->netno)
continue;
if (conp->protoc[0] == &ussLQRPTable)
goto take1;
}
ret9:
return -1;
take1:
#ifdef LITTLE
/* convert to native byte order if needed */
cp = (unsigned char *) mess + MESSH_SZ + LHDRSZ + 4;
for (i1 = 0; i1 < 11; i1++) {
cc = cp[3], cp[3] = cp[0], cp[0] = cc;
cc = cp[2], cp[2] = cp[1], cp[1] = cc;
cp += 4;
}
#endif
/* add the synthetic data */
netp->InLQRs++;
Nmemcpy(cp + 48, &(char *) netp->InLQRs, 4);
Nmemcpy(cp + 52, &(char *) netp->ifInUcastPkts, 4);
Nmemcpy(cp + 56, &(char *) netp->ifInDiscards, 4);
Nmemcpy(cp + 60, &(char *) netp->ifInErrors, 4);
Nmemcpy(cp + 64, &(char *) netp->InGoodOctets, 4);
mess->mlen = MESSH_SZ + LHDRSZ + 68;
return conno;
}
static int opeN(int conno, int flags)
{
(void) conno;
(void) flags;
return 0;
}
static int closE(int conno)
{
(void) conno;
return 0;
}
/** * * * * * *
** ioctl() I/O control function
**
** int ioctl(int handle, int request, void *arg);
**
** PARAMETERS:
** (in) void *handle A handle to the layer being called
** (in) int request Constant for the command to perform
** (in/out) void *arg Pointer to command parameters
** (in) size_t size The size of the command parameters
**
** RETURNS:
** 0 Success
** USS_ERR_INVAL Support for the request not implemented
**
** DESCRIPTION:
** This function allows special purpose functions specific to this
** network layer to be performed. At the moment, there are no functions
** defined for this layer.
** * * * * * */
static int ioctl(void *handle, enum ioctlreq request, void *arg, size_t size)
{
(void)handle; /* quietly ignore this argument */
(void)request; /* quietly ignore this argument */
(void)arg; /* quietly ignore this argument */
(void)size; /* quietly ignore this argument */
return ussErrInval;
}
GLOBALCONST PTABLE ussLQRPTable = {
"LQRP", 0, 0, screen, 0, 0, 0, writE, ioctl, NC2(PROTlqp), LHDRSZ
};
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -