Skip to content

Commit

Permalink
Merge remote-tracking branch 'github/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
rgerhards committed Jan 22, 2015
2 parents 0737b3e + b21cad3 commit 63eebbb
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
60 changes: 60 additions & 0 deletions example/receive.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* A minimal RELP receiver using librelp
*
* Copyright 2014 Mathias Nyman
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include "librelp.h"

#define TRY(f) if(f != RELP_RET_OK) { printf("%s\n", #f); return 1; }

static relpEngine_t *pRelpEngine;

static void dbgprintf(char __attribute__((unused)) *fmt, ...) {
printf(fmt);
}

static relpRetVal onSyslogRcv(unsigned char *pHostname, unsigned char *pIP, unsigned char *msg, size_t lenMsg) {
printf("%s\n", msg);
fflush(stdout);

return RELP_RET_OK;
}

int main(int argc, char *argv[]) {

relpSrv_t *pRelpSrv;
unsigned char *port = argv[1];
int protFamily = 2; /* IPv4=2, IPv6=10 */

TRY(relpEngineConstruct(&pRelpEngine));
TRY(relpEngineSetDbgprint(pRelpEngine, dbgprintf));
TRY(relpEngineSetEnableCmd(pRelpEngine, (unsigned char*) "syslog", 3)); /* 3=required */
TRY(relpEngineSetFamily(pRelpEngine, protFamily));
TRY(relpEngineSetSyslogRcv(pRelpEngine, onSyslogRcv));
TRY(relpEngineSetDnsLookupMode(pRelpEngine, 0)); /* 0=disable */

TRY(relpEngineListnerConstruct(pRelpEngine, &pRelpSrv));
TRY(relpSrvSetLstnPort(pRelpSrv, port));
TRY(relpEngineListnerConstructFinalize(pRelpEngine, pRelpSrv));

TRY(relpEngineRun(pRelpEngine)); /* Abort with ctrl-c */

TRY(relpEngineSetStop(pRelpEngine));
TRY(relpEngineDestruct(&pRelpEngine));
}

53 changes: 53 additions & 0 deletions example/send.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* A minimal RELP sender using librelp
*
* Copyright 2014 Mathias Nyman
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include "librelp.h"

#define TRY(f) if(f != RELP_RET_OK) { printf("%s\n", #f); return 1; }

static relpEngine_t *pRelpEngine;

static void dbgprintf(char __attribute__((unused)) *fmt, ...) {
printf(fmt);
}

int main(int argc, char *argv[]) {

relpClt_t *pRelpClt;
unsigned char *target = argv[1];
unsigned char *port = argv[2];
unsigned timeout = 90;
int protFamily = 2; /* IPv4=2, IPv6=10 */

TRY(relpEngineConstruct(&pRelpEngine));
TRY(relpEngineSetDbgprint(pRelpEngine, dbgprintf));
TRY(relpEngineSetEnableCmd(pRelpEngine, (unsigned char*) "syslog", 3)); /* 3=required */
TRY(relpEngineCltConstruct(pRelpEngine, &pRelpClt));
TRY(relpCltSetTimeout(pRelpClt, timeout));
TRY(relpCltConnect(pRelpClt, protFamily, port, target));

unsigned char *pMsg = argv[3];
size_t lenMsg = strlen((char*) pMsg);
TRY(relpCltSendSyslog(pRelpClt, pMsg, lenMsg));

TRY(relpEngineCltDestruct(pRelpEngine, &pRelpClt));
TRY(relpEngineDestruct(&pRelpEngine));
}

0 comments on commit 63eebbb

Please sign in to comment.