added getPortNum
r1142 | ffr | 2006-10-13 15:44:20 +1000 (Fri, 13 Oct 2006) | 2 lines
This commit is contained in:
committed by
Douglas Clowes
parent
45f86cb928
commit
4ba40fd8bd
@@ -1,4 +1,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
#include <sics.h>
|
#include <sics.h>
|
||||||
#include "anstoutil.h"
|
#include "anstoutil.h"
|
||||||
|
|
||||||
@@ -23,3 +25,23 @@ char *getParam(SConnection *pCon, Tcl_Interp *pTcl, char *params, char *parName,
|
|||||||
}
|
}
|
||||||
return pPtr;
|
return pPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** \brief Lookup named port in /etc/services
|
||||||
|
* \param *pCon (r) connection object.
|
||||||
|
* \param *portName (r) name of port to look up
|
||||||
|
* \return
|
||||||
|
* - port number on success
|
||||||
|
* - 0 on failure
|
||||||
|
*/
|
||||||
|
int getPortNum(SConnection *pCon, char *portName) {
|
||||||
|
struct servent *sp=NULL;
|
||||||
|
char pError[ERRLEN];
|
||||||
|
|
||||||
|
sp = getservbyname(portName, "tcp");
|
||||||
|
if (sp == NULL) {
|
||||||
|
snprintf(pError, ERRLEN,"ERROR: '%s' service not found", portName);
|
||||||
|
SCWrite(pCon,pError, eError);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return ntohs(sp->s_port);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user