Added portnum command

r1183 | ffr | 2006-10-26 10:28:49 +1000 (Thu, 26 Oct 2006) | 2 lines
This commit is contained in:
Ferdi Franceschini
2006-10-26 10:28:49 +10:00
committed by Douglas Clowes
parent 03a8c420c4
commit 29432a7f44
3 changed files with 35 additions and 15 deletions

View File

@@ -4,6 +4,8 @@
#include <sics.h>
#include "anstoutil.h"
#define MAXNUMCHAR 32
/** \brief Get configuration parameter
* \param *pCon (r) connection object.
* \param *pTcl (r) Tcl interpreter
@@ -37,7 +39,7 @@ int getPortNum(SConnection *pCon, char *portName) {
struct servent *sp=NULL;
char pError[ERRLEN];
sp = getservbyname(portName, "tcp");
sp = getservbyname(portName, NULL);
if (sp == NULL) {
snprintf(pError, ERRLEN,"ERROR: '%s' service not found", portName);
SCWrite(pCon,pError, eError);
@@ -45,3 +47,29 @@ int getPortNum(SConnection *pCon, char *portName) {
}
return ntohs(sp->s_port);
}
int portNumCmd(SConnection *pCon, SicsInterp *pInter, void *pData, int argc, char *argv[]) {
OutCode eOut = eWarning;
int pn;
int iMacro;
char portNum[MAXNUMCHAR];
assert(pCon != NULL);
assert(pInter != NULL);
switch (argc) {
case 2:
pn = getPortNum(pCon, argv[1]);
snprintf(portNum, MAXNUMCHAR, "%d", pn);
break;
default:
SCWrite(pCon,"Insufficient arguments to portNumCmd",eError);
return 0;
}
//iMacro = SCinMacro(pCon);
//SCsetMacro(pCon,0);
SCWrite(pCon,portNum,eValue);
//SCsetMacro(pCon,iMacro);
return 1;
}