Files
sics/udpquieck.c
koennecke b26b8fc735 - Changed strncpy to strlcpy, strncat to strlcat
- Added strlcpy and strlcat to SICS
- Added a driver for the POLDI power supplies


SKIPPED:
	psi/A1931.c
	psi/autowin.c
	psi/bruker.c
	psi/docho.c
	psi/dornier2.c
	psi/dspcode.c
	psi/ease.c
	psi/ecb.c
	psi/ecbcounter.c
	psi/ecbdriv.c
	psi/el734dc.c
	psi/el734driv.c
	psi/el734hp.c
	psi/el737driv.c
	psi/el737hpdriv.c
	psi/el737hpdrivsps.c
	psi/el737hpv2driv.c
	psi/el755driv.c
	psi/eurodriv.c
	psi/haakedriv.c
	psi/itc4driv.c
	psi/julcho.c
	psi/linadriv.c
	psi/lmd200.c
	psi/lscsupport.c
	psi/ltc11.c
	psi/make_gen
	psi/oicom.c
	psi/oxinst.c
	psi/pimotor.c
	psi/pipiezo.c
	psi/polterwrite.c
	psi/psi.c
	psi/sanscook.c
	psi/sanslirebin.c
	psi/sanswave.c
	psi/sinqhmdriv.c
	psi/sinqhttp.c
	psi/slsecho.c
	psi/slsmagnet.c
	psi/slsvme.c
	psi/sps.c
	psi/swmotor.c
	psi/swmotor2.c
	psi/tabledrive.c
	psi/tasscan.c
	psi/tdchm.c
	psi/velodorn.c
	psi/velodornier.c
2010-04-13 15:08:38 +00:00

114 lines
2.7 KiB
C

/*-------------------------------------------------------------------------
U D P Q U I E C K
This file implements the UDP broadcasting of SICS messages. Especially
the update file message.
Mark Koennecke, August 1998
---------------------------------------------------------------------------*/
#include <stdlib.h>
#include <assert.h>
#include "fortify.h"
#include "sics.h"
#include "udpquieck.h"
/* the UDP port */
static mkChannel *port = NULL;
static char pError[256];
/* the UDP port number, -1 means not configured */
static int iPort = -1;
/*----------------------------------------------------------------------*/
void KillQuieck(void *pData)
{
if (port) {
free(port);
}
if (pData)
KillDummy(pData);
}
/*------------------------------------------------------------------------*/
int SendQuieck(int iType, char *pText)
{
char *pPtr = NULL;
int iRet;
char pMessage[512];
/* do we know the type */
if (iType != QUIECK) {
strcpy(pError, "ERROR: unknown UDP broadcast message type");
return 0;
}
/* if no port number, get it from ServerOptions */
if (iPort < 0) {
pPtr = IFindOption(pSICSOptions, "QuieckPort");
if (pPtr) {
iPort = atoi(pPtr);
} else {
iPort = 2108;
}
}
/* do we have a channel ? */
if (port == NULL) {
port = UDPConnect("localhost", iPort);
if (port == NULL) {
strcpy(pError,
"ERROR: cannot connect to UDP port, may be nobody listening");
return 0;
}
}
/* format a message and blast into space */
switch (iType) {
case QUIECK:
strcpy(pMessage, "QUIECK/");
strlcat(pMessage, pText,512);
break;
default:
strcpy(pMessage, "Error");
break;
}
iRet = UDPWrite(port, pMessage, strlen(pMessage));
if (iRet != 1) {
strcpy(pError, "ERROR: failed to send UDP message");
free(port);
port = NULL;
return 0;
}
return 1;
}
/*--------------------------------------------------------------------------*/
int QuieckAction(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[])
{
int iRet;
if (argc < 2) {
SCWrite(pCon, "ERROR: expected a message for udpquieck", eError);
return 0;
}
if (!SCMatchRights(pCon, usMugger)) {
SCWrite(pCon,
"ERROR: permission denied to use internal command udpquieck",
eError);
return 0;
}
iRet = SendQuieck(QUIECK, argv[1]);
if (iRet != 1) {
SCWrite(pCon, pError, eError);
return 0;
}
SCSendOK(pCon);
return 1;
}
/*--------------------------------------------------------------------------*/
void UdpInit(void)
{
AddCommand(pServ->pSics, "udpquieck", QuieckAction, KillQuieck, NULL);
}