-
Notifications
You must be signed in to change notification settings - Fork 14
/
PortmapProg.cpp
57 lines (49 loc) · 1.17 KB
/
PortmapProg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "PortmapProg.h"
#include <string.h>
#define MIN_PROG_NUM 100000
enum
{
MAPPROC_NULL = 0,
MAPPROC_SET = 1,
MAPPROC_UNSET = 2,
MAPPROC_GETPORT = 3,
MAPPROC_DUMP = 4,
MAPPROC_CALLIT = 5
};
CPortmapProg::CPortmapProg() : CRPCProg()
{
memset(m_nPortTable, 0, PORT_NUM * sizeof(int));
}
CPortmapProg::~CPortmapProg()
{
}
void CPortmapProg::Set(unsigned long nProg, unsigned long nPort)
{
m_nPortTable[nProg - MIN_PROG_NUM] = nPort; //set port for program
}
int CPortmapProg::Process(IInputStream *pInStream, IOutputStream *pOutStream, ProcessParam *pParam)
{
PrintLog("PORTMAP ");
m_pInStream = pInStream;
m_pOutStream = pOutStream;
if (pParam->nProc != MAPPROC_GETPORT)
{
PrintLog("NOTIMP\n");
return PRC_NOTIMP;
}
ProcedureGETPORT();
PrintLog("\n");
return PRC_OK;
}
bool CPortmapProg::ProcedureGETPORT(void)
{
PORTMAP_HEADER header;
unsigned long nPort;
PrintLog("GETPORT");
m_pInStream->Read(&header.prog); //program
m_pInStream->Skip(12);
nPort = header.prog >= MIN_PROG_NUM && header.prog < MIN_PROG_NUM + PORT_NUM? m_nPortTable[header.prog - MIN_PROG_NUM] : 0;
PrintLog(" %d %d", header.prog, nPort);
m_pOutStream->Write(nPort); //port
return true;
}