Skip to content
Open
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM debian:stretch
# copy the data in

RUN apt-get update && apt-get -y install build-essential autoconf libtool-bin libsnmp-dev && rm -rf /var/lib/apt/lists/*

COPY . .

RUN ./autogen.sh

RUN ./configure

RUN make

EXPOSE 1661/udp

CMD [ "./replayd", "-d", "replays", "-v", "-v", "-v" ]
3 changes: 3 additions & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

docker build -t replayd . && docker run -p 1661:1661/udp replayd
1 change: 1 addition & 0 deletions parse_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type_atoi type_map[] = {
{"Timeticks", ASN_TIMETICKS},
{"Gauge32", ASN_GAUGE},
{"Counter32", ASN_COUNTER},
{"Counter64", ASN_COUNTER64},
{"IpAddress", ASN_IPADDRESS},
{"NULL", ASN_NULL},
{NULL, 0}, // Array end marker
Expand Down
18 changes: 18 additions & 0 deletions replayd.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <signal.h>
#include <stdlib.h>
#include <ctype.h>
#include <arpa/inet.h>

#include <sys/types.h>
#include <dirent.h>
Expand Down Expand Up @@ -63,6 +64,8 @@ netsnmp_variable_list *parse_reply(char *name) {
netsnmp_variable_list *list = NULL;
netsnmp_variable_list *lptr = NULL;

setbuf(stdout, NULL);

fname = malloc(strlen(directory) + strlen(name) + 2);
sprintf(fname, "%s/%s", directory, name);
fr = fopen(fname, "r");
Expand Down Expand Up @@ -103,6 +106,7 @@ netsnmp_variable_list *parse_reply(char *name) {
case ASN_TIMETICKS:
case ASN_GAUGE:
case ASN_COUNTER:
case ASN_COUNTER64:
lptr->val.integer = malloc(sizeof(long));
if (strchr(value, (int)'(')) {
value = strchr(value, (int)'(');
Expand Down Expand Up @@ -142,6 +146,17 @@ netsnmp_variable_list *parse_reply(char *name) {
snmp_parse_oid(value, lptr->val.objid, &(lptr->val_len));
lptr->val_len *= sizeof(oid);
break;
case ASN_IPADDRESS:
lptr->val.integer = malloc(sizeof(struct in_addr));

if (inet_pton(AF_INET, value, (struct in_addr *)lptr->val.integer) != 1){
fprintf(stderr, "Invalid address: %s\n", value);
}
lptr->val_len = sizeof(struct in_addr);
break;
default:
fprintf(stderr, "Don't know how to parse %s\n", type_str);
break;
}

}
Expand Down Expand Up @@ -226,6 +241,9 @@ int main(int argc, char *argv[]) {
struct dirent *dEnt;
replay_entry *rEnt;

// disable output buffering
setbuf(stdout, NULL);

// Process options
while ((arg = getopt(argc, argv, "vd:L::")) != EOF) {
switch (arg) {
Expand Down
2 changes: 2 additions & 0 deletions replays/unittest
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
.1.3.6.1.2.1.1.9.1.4.6 = Timeticks: (2) 0:00:00.02
.1.3.6.1.2.1.1.9.1.4.7 = Timeticks: (2) 0:00:00.02
.1.3.6.1.2.1.1.9.1.4.8 = Timeticks: (2) 0:00:00.02
.1.3.6.1.2.1.15.3.1.7.0.0.0.0 = IpAddress: 0.0.0.0
.1.3.6.1.2.1.15.3.1.7.10.1.159.251 = IpAddress: 10.1.159.251
.1.3.6.1.4.1.31865.9999.42.2.1 = INTEGER: test(1)
.1.3.6.1.4.1.31865.9999.42.2.2 = INTEGER: test(-2)
.1.3.6.1.4.1.31865.9999.42.2.4 = INTEGER: 4
Expand Down