Page 1 of 1

How to utilise macros "HOSTADDRESS" in my code

Posted: Mon Jan 03, 2022 10:36 pm
by dhlao
I'm going to create a check command that is written in C. Like those built-in ones that come with Nagios Core, I want to make it able to get the argument such as hostaddress, warning and critical threshold.
I've checked check_ping and check_snmp, then I found that they all rely on an unknown variable "optarg". It's not declared in the codes so I assume it's included in one of those headers (common.h, utils.h, etc.).
The problem is those headers have dependency with the other headers that make it impossible to include all of them.
If I know where and how that "optarg" is declared, I can just simply skip those unnecessary library/header. My problem is, I've no idea where it is.

Re: How to utilise macros "HOSTADDRESS" in my code

Posted: Tue Jan 04, 2022 11:00 am
by mcapra
I think this is what you're looking for:
https://github.com/nagios-plugins/nagio ... l/getopt.c

But there's a variety of ways to handle command-line arguments in C.