コード例 #1
0
int main (int argc, char const * argv [])

{
	extern struct channel channel;
	extern const struct _term_ devices [];
	static char const * optv [] =
	{
		"i:bnqrsv",
		"device [device] [...] [> stdout]",
		"Qualcomm Atheros Device Statistics Utility",
		"b\tprint bridge devices; exclude remote devices",

#if defined (WINPCAP) || defined (LIBPCAP)

		"i n\thost interface is (n) [" LITERAL (CHANNEL_ETHNUMBER) "]",

#else

		"i s\thost interface is (s) [" LITERAL (CHANNEL_ETHDEVICE) "]",

#endif

		"n\tappend newline to output",
		"q\tquiet mode",
		"r\tprint remote devices; exclude bridge devices",
		"s\tprint newlines instead of spaces",
		"v\tverbose mode",
		(char const *) (0)
	};

#include "../plc/plc.c"

	char const * space = " ";
	char const * comma = "\0";
	signed c;
	if (getenv (PLCDEVICE))
	{

#if defined (WINPCAP) || defined (LIBPCAP)

		channel.ifindex = atoi (getenv (PLCDEVICE));

#else

		channel.ifname = strdup (getenv (PLCDEVICE));

#endif

	}
	optind = 1;
	while ((c = getoptv (argc, argv, optv)) != -1)
	{
		switch (c)
		{
		case 'b':
			_setbits (plc.flags, PLC_BRIDGE_LIST);
			break;
		case 'i':

#if defined (WINPCAP) || defined (LIBPCAP)

			channel.ifindex = atoi (optarg);

#else

			channel.ifname = optarg;

#endif

			break;
		case 'n':
			comma = "\n";
			break;
		case 'r':
			_setbits (plc.flags, PLC_REMOTE_LIST);
			break;
		case 's':
			space = "\n";
			break;
		case 'q':
			_setbits (channel.flags, CHANNEL_SILENCE);
			_setbits (plc.flags, PLC_SILENCE);
			break;
		case 'v':
			_setbits (channel.flags, CHANNEL_VERBOSE);
			_setbits (plc.flags, PLC_VERBOSE);
			break;
		default:
			break;
		}
	}
	argc -= optind;
	argv += optind;
	if (_allclr (plc.flags, (PLC_BRIDGE_LIST|PLC_REMOTE_LIST)))
	{
		_setbits (plc.flags, (PLC_BRIDGE_LIST|PLC_REMOTE_LIST));
	}
	openchannel (&channel);
	if (!(plc.message = malloc (sizeof (* plc.message))))
	{
		error (1, errno, PLC_NOMEMORY);
	}
	if (!argc)
	{
		ListLocalDevices (&plc, space, comma);
	}
	while ((argc) && (* argv))
	{
		if (!hexencode (channel.peer, sizeof (channel.peer), synonym (* argv, devices, SIZEOF (devices))))
		{
			error (1, errno, PLC_BAD_MAC, * argv);
		}
		ListRemoteDevices1 (&plc, space, comma);
		argc--;
		argv++;
	}
	closechannel (&channel);
	return (0);
}
コード例 #2
0
signed ListRemoteDevices (struct plc * plc, char const * space, char const * comma)

{
	return ((plc->hardwareID < CHIPSET_AR7400)? ListRemoteDevices1 (plc, space, comma): ListRemoteDevices2 (plc, space, comma));
}