From 1a85d9f6918b84ae03df9592274f241b1d5c2e3c Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Tue, 10 Jan 2012 09:31:52 +0000 Subject: [PATCH] changed the setClientIP function and included 2 header files for IP validation git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@81 951219d9-93cf-4727-9268-0efd64621fa3 --- slsDetectorSoftware/slsDetector/slsDetector.cpp | 14 +++++++++++--- slsDetectorSoftware/slsDetector/slsDetector.h | 4 ++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 9e7112598..157087487 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -3,7 +3,8 @@ #include #include #include - +#include +#include int slsDetector::initSharedMemory(detectorType type, int id) { @@ -4915,8 +4916,15 @@ int slsDetector::getScanPrecision(int iscan){ } - - +char* slsDetector::setClientIP(string clientIP){ + struct sockaddr_in sa; + int result = inet_pton(AF_INET, clientIP.c_str(), &(sa.sin_addr)); + if((!result)||(clientIP.length()>15)) + sprintf(thisDetector->clientIP,"IP Address should be VALID and in xxx.xxx.xxx.xxx format"); + else + sprintf(thisDetector->clientIP,clientIP.c_str()); + return thisDetector->clientIP; +}; diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 7b1ec3f6e..50fa9ee29 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -446,8 +446,8 @@ typedef struct sharedSlsDetector { char* getClientIP() {return thisDetector->clientIP;}; /** returns the client MAC address for gotthard \sa sharedSlsDetector */ char* getClientMAC() {return thisDetector->clientMAC;}; - /** sets the client IP address for gotthard \sa sharedSlsDetector */ - char* setClientIP(string clientIP) {sprintf(thisDetector->clientIP,clientIP.c_str()); return thisDetector->clientIP;}; + /** validates and sets the client IP address for gotthard \sa sharedSlsDetector */ + char* setClientIP(string clientIP); /** sets the client MAC address for gotthard \sa sharedSlsDetector */ char* setClientMAC(string clientMAC) {sprintf(thisDetector->clientMAC,clientMAC.c_str());return thisDetector->clientMAC;};