当前位置: 首页>>代码示例>>C++>>正文


C++ BNetworkAddress::LinkLevelType方法代码示例

本文整理汇总了C++中BNetworkAddress::LinkLevelType方法的典型用法代码示例。如果您正苦于以下问题:C++ BNetworkAddress::LinkLevelType方法的具体用法?C++ BNetworkAddress::LinkLevelType怎么用?C++ BNetworkAddress::LinkLevelType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BNetworkAddress的用法示例。


在下文中一共展示了BNetworkAddress::LinkLevelType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

static
status_t
show_all()
{
	BNetworkRoster& roster = BNetworkRoster::Default();

	BNetworkInterface interface;
	uint32 cookie = 0;

	while (roster.GetNextInterface(&cookie, interface) == B_OK) {
		BNetworkAddress linkAddress;
		status_t status = interface.GetHardwareAddress(linkAddress);
		if (status == B_OK && linkAddress.LinkLevelType() == IFT_TUN)
			show_interface(interface.Name());
	}
	return B_OK;
}
开发者ID:mmuman,项目名称:haiku,代码行数:17,代码来源:tunconfig.cpp

示例2: interface

bool
list_interface(const char* name)
{
	printf("%s", name);
	size_t length = strlen(name);
	if (length < 8)
		putchar('\t');
	else
		printf("\n\t");

	// get link level interface for this interface

	BNetworkInterface interface(name);
	if (!interface.Exists()) {
		printf("Interface not found!\n");
		return false;
	}

	BNetworkAddress linkAddress;
	status_t status = interface.GetHardwareAddress(linkAddress);
	if (status == B_OK) {
		const char *type = "unknown";
		switch (linkAddress.LinkLevelType()) {
			case IFT_ETHER:
				type = "Ethernet";
				break;
			case IFT_LOOP:
				type = "Local Loopback";
				break;
			case IFT_MODEM:
				type = "Modem";
				break;
		}

		BString address = linkAddress.ToString();
		if (address.Length() == 0)
			address = "none";

		printf("Hardware type: %s, Address: %s\n", type, address.String());
	} else
		printf("No link level: %s\n", strerror(status));

	int media = interface.Media();
	if ((media & IFM_ACTIVE) != 0) {
		// dump media state in case we're linked
		const char* type = "unknown";
		bool show = false;

		for (int32 i = 0; kMediaTypes[i].type >= 0; i++) {
			// loopback don't really have a media anyway
			if (IFM_TYPE(media) == 0/*IFT_LOOP*/)
				break;

			// only check for generic or correct subtypes
			if (kMediaTypes[i].type
				&& kMediaTypes[i].type != IFM_TYPE(media))
				continue;

			for (int32 j = 0; kMediaTypes[i].subtypes[j].subtype >= 0; j++) {
				if (kMediaTypes[i].subtypes[j].subtype == IFM_SUBTYPE(media)) {
					// found a match
					type = kMediaTypes[i].subtypes[j].pretty;
					show = true;
					break;
				}
			}
		}

		if (show)
			printf("\tMedia type: %s\n", type);
	}

	// Print associated wireless network(s)

	BNetworkDevice device(name);
	if (device.IsWireless()) {
		wireless_network network;
		bool first = true;
		uint32 cookie = 0;
		while (device.GetNextAssociatedNetwork(cookie, network) == B_OK) {
			if (first) {
				printf("\tNetwork: ");
				first = false;
			} else
				printf("\t\t");

			printf("%s, Address: %s, %s", network.name,
				network.address.ToString().String(),
				get_authentication_mode(network.authentication_mode,
					network.flags));
			const char* keyMode = get_key_mode(network.key_mode);
			if (keyMode != NULL)
				printf(", %s/%s", keyMode, get_cipher(network.cipher));
			putchar('\n');
		}
	}

	uint32 flags = interface.Flags();

	list_interface_addresses(interface, flags);
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


注:本文中的BNetworkAddress::LinkLevelType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。