Kevin, If you want you can rewrite mtr to use the system library. It
would be preferable if you would allow us to switch at runtime between
the two (or more) DNS resolver modules.
Design suggestions:
-- modules. Allow easy replacement of a module by another one.
First module is of course the existing async DNS module.
-- (I don't think run-time-replaceable modules is useful, so just
compile time modules is fine. This is already implemented in the
output modules where you get to chose report, gtk or curses.)
-- Getting to know the code: Just use the system DNS resolver
function. This will "hang" mtr for seconds at a time when
the resolv happens.
-- The async version: fork a completely new process that does
the name resolving and reports back.
(the parent process can create a pipe, and have the children write
to the pipe, so that one select on the pipe read end will give you
if any of the resolves are finished.)
This means that the writes need to include the resolved IP address
as well as the results of the resolving. And to prevent races,
you need to write those in one go.
BAD:
printf ("%s ", inet_ntoa(input_ip_address));
printf ("%s\n", <the resolver result>);
BETTER:
printf ("%s %s\n", inet_ntoa(input_ip_address), <the resolver result>);
BEST:
sprintf (mybuf, "%s %s\n", inet_ntoa(input_ip_address), <the resolver result>);
write (1, mybuf, strlen (mybuf));
The children are probably very simple:
if (pid == 0) {
// call the resolver
// print the result
exit (0);
}
the parent is slightly more complex:
// if not already done: create the pipe.
Hmm. It seems easiest to just write to the write-end of the pipe,
(instead of redirecting stdout as I had originally thought)
so the printf's become "fprintf's" but easiest is to just use
the "BEST" option and write to the resolver_pipe[1].
so all in all it should become something like:
static int resolverpipe[2];
if (!resolverpipe[0]) { pipe(resolverpipe);
// check for error return;
}
if (!fork ()) {
// prepare "node" field.
getaddrinfo (node, ..., res);
sprintf (mybuf, ...);
write (resolverpipe[1], mybuf, strlen (mybuf));
exit (0);
}
that needs to be integrated into mtr....
--
** <email address hidden> ** http://www.BitWizard.nl/ ** +31-15-2600998 **
** Delftechpark 26 2628 XH Delft, The Netherlands. KVK: 27239233 **
*-- BitWizard writes Linux device drivers for any device you may have! --*
The plan was simple, like my brother-in-law Phil. But unlike
Phil, this plan just might work.
Kevin, If you want you can rewrite mtr to use the system library. It
would be preferable if you would allow us to switch at runtime between
the two (or more) DNS resolver modules.
Design suggestions: replaceable modules is useful, so just input_ip_ address) ); input_ip_ address) ,
< the resolver result>); input_ip_ address) ,
< the resolver result>);
-- modules. Allow easy replacement of a module by another one.
First module is of course the existing async DNS module.
-- (I don't think run-time-
compile time modules is fine. This is already implemented in the
output modules where you get to chose report, gtk or curses.)
-- Getting to know the code: Just use the system DNS resolver
function. This will "hang" mtr for seconds at a time when
the resolv happens.
-- The async version: fork a completely new process that does
the name resolving and reports back.
(the parent process can create a pipe, and have the children write
to the pipe, so that one select on the pipe read end will give you
if any of the resolves are finished.)
This means that the writes need to include the resolved IP address
as well as the results of the resolving. And to prevent races,
you need to write those in one go.
BAD:
printf ("%s ", inet_ntoa(
printf ("%s\n", <the resolver result>);
BETTER:
printf ("%s %s\n", inet_ntoa(
BEST:
sprintf (mybuf, "%s %s\n", inet_ntoa(
write (1, mybuf, strlen (mybuf));
The children are probably very simple:
if (pid == 0) {
// call the resolver
// print the result
exit (0);
}
the parent is slightly more complex:
// if not already done: create the pipe.
Hmm. It seems easiest to just write to the write-end of the pipe,
(instead of redirecting stdout as I had originally thought)
so the printf's become "fprintf's" but easiest is to just use
the "BEST" option and write to the resolver_pipe[1].
so all in all it should become something like:
static int resolverpipe[2];
pipe(resolverpi pe);
if (!resolverpipe[0]) {
// check for error return;
}
if (!fork ()) {
// prepare "node" field.
getaddrinfo (node, ..., res);
sprintf (mybuf, ...);
write (resolverpipe[1], mybuf, strlen (mybuf));
exit (0);
}
that needs to be integrated into mtr....
-- www.BitWizard. nl/ ** +31-15-2600998 **
** <email address hidden> ** http://
** Delftechpark 26 2628 XH Delft, The Netherlands. KVK: 27239233 **
*-- BitWizard writes Linux device drivers for any device you may have! --*
The plan was simple, like my brother-in-law Phil. But unlike
Phil, this plan just might work.