-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathibp_rid_mode.c
More file actions
79 lines (63 loc) · 1.65 KB
/
ibp_rid_mode.c
File metadata and controls
79 lines (63 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/uio.h>
#include <fcntl.h>
#include <errno.h>
#include <assert.h>
#include "network.h"
#include "net_sock.h"
#include "log.h"
#include "dns_cache.h"
#include "string_token.h"
#include "cmd_send.h"
//**** Mode states
#define RES_MODE_WRITE 1
#define RES_MODE_READ 2
#define RES_MODE_MANAGE 4
//*************************************************************************
//*************************************************************************
int main(int argc, char **argv)
{
int bufsize = 1024*1024;
char buffer[bufsize], *bstate;
int i, port, mode, timeout;
char *host, *rid;
NetStream_t *ns;
if (argc < 4) {
printf("ibp_rid_mode host port RID [read] [write] [manage]\n");
printf("\n");
return(0);
}
timeout = 20;
i = 1;
host = argv[i]; i++;
port = atoi(argv[i]); i++;
rid = argv[i]; i++;
mode = 0;
while (i < argc) {
if (strcasecmp(argv[i], "read") == 0) {
mode |= RES_MODE_READ;
} else if (strcasecmp(argv[i], "write") == 0) {
mode |= RES_MODE_WRITE;
} else if (strcasecmp(argv[i], "manage") == 0) {
mode |= RES_MODE_MANAGE;
}
i++;
}
sprintf(buffer, "1 90 %s %d %d\n", rid, mode, timeout); // IBP_INTERNAL_SET_MODE command
assert(apr_initialize() == APR_SUCCESS);
dns_cache_init(10);
ns = cmd_send(host, port, buffer, &bstate, timeout);
if (ns == NULL) return(-1);
if (bstate != NULL) free(bstate);
//** Close the connection
close_netstream(ns);
apr_terminate();
return(0);
}