How to utilise macros "HOSTADDRESS" in my code

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
dhlao
Posts: 14
Joined: Thu Apr 29, 2021 10:23 am

How to utilise macros "HOSTADDRESS" in my code

Post 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.
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

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

Post 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.
Former Nagios employee
https://www.mcapra.com/
Locked