Skip to content

Commit 8e13275

Browse files
committed
fix input params for rtr_mgr_init
1 parent ad579c6 commit 8e13275

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

bird-rtrlib-cli.c

+19-19
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ int main(int argc, char *argv[]) {
217217
}
218218

219219
struct tr_socket tr_sock;
220-
struct tr_tcp_config *tcp_config;
221-
struct tr_ssh_config *ssh_config;
220+
struct tr_tcp_config *tcp_config;
221+
struct tr_ssh_config *ssh_config;
222222

223223
// Try to connect to the RTR server depending on the requested connection
224224
// type.
@@ -241,27 +241,27 @@ int main(int argc, char *argv[]) {
241241
}
242242

243243
struct rtr_socket rtr;
244-
struct rtr_mgr_config *conf;
245-
struct rtr_mgr_group groups[1];
244+
struct rtr_mgr_config *conf;
245+
struct rtr_mgr_group groups[1];
246246

247-
rtr.tr_socket = &tr_sock;
248-
groups[0].sockets_len = 1;
249-
groups[0].sockets = malloc(1 * sizeof(rtr));
250-
groups[0].sockets[0] = &rtr;
251-
groups[0].preference = 1;
247+
rtr.tr_socket = &tr_sock;
248+
groups[0].sockets_len = 1;
249+
groups[0].sockets = malloc(1 * sizeof(rtr));
250+
groups[0].sockets[0] = &rtr;
251+
groups[0].preference = 1;
252252

253-
int ret = rtr_mgr_init(&conf, groups, 1, 240, 520, 600,
253+
int ret = rtr_mgr_init(&conf, groups, 1, 30, 600, 600,
254254
pfx_update_callback, NULL, NULL, NULL);
255255

256-
if (ret == RTR_ERROR)
257-
printf("Error in rtr_mgr_init!\n");
258-
else if (ret == RTR_INVALID_PARAM)
259-
printf("Invalid params passed to rtr_mgr_init\n");
256+
if (ret == RTR_ERROR)
257+
printf("Error in rtr_mgr_init!\n");
258+
else if (ret == RTR_INVALID_PARAM)
259+
printf("Invalid params passed to rtr_mgr_init\n");
260260

261-
if (!conf)
262-
return EXIT_FAILURE;
261+
if (!conf)
262+
return EXIT_FAILURE;
263263

264-
rtr_mgr_start(conf);
264+
rtr_mgr_start(conf);
265265

266266
// Server loop. Read commands from stdin.
267267
while (getline(&command, &command_len, stdin) != -1) {
@@ -271,8 +271,8 @@ int main(int argc, char *argv[]) {
271271

272272
// Clean up RTRLIB memory.
273273
rtr_mgr_stop(conf);
274-
rtr_mgr_free(conf);
275-
free(groups[0].sockets);
274+
rtr_mgr_free(conf);
275+
free(groups[0].sockets);
276276

277277
// Close BIRD socket.
278278
close(bird_socket);

rtr.c

+14-7
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@ struct tr_ssh_config *rtr_create_ssh_config(const char *host,
3737
memset(result, 0, sizeof (struct tr_ssh_config));
3838

3939
// Assign host, port and username (mandatory).
40-
result->host = strdup(host);
41-
unsigned int iport = atoi(port);
42-
result->port = iport;
43-
result->username = strdup(username);
40+
if (host)
41+
result->host = strdup(host);
42+
if (port) {
43+
unsigned int iport = atoi(port);
44+
result->port = iport;
45+
}
46+
if (username)
47+
result->username = strdup(username);
4448

4549
// Assign bind address if available.
4650
if (bindaddr)
@@ -64,9 +68,12 @@ struct tr_tcp_config *rtr_create_tcp_config(
6468
memset(result, 0, sizeof (struct tr_tcp_config));
6569

6670
// Populate result.
67-
result->host = strdup(host);
68-
result->port = strdup(port);
69-
result->bindaddr = strdup(bindaddr);
71+
if(host)
72+
result->host = strdup(host);
73+
if (port)
74+
result->port = strdup(port);
75+
if (bindaddr)
76+
result->bindaddr = strdup(bindaddr);
7077

7178
// Return result.
7279
return result;

0 commit comments

Comments
 (0)