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


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

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


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

示例1: socket

status_t
SocketConnection::Connect(const char* server, uint32 port)
{
	if (fSocket >= 0)
		Disconnect();

	TRACE("SocketConnection to server %s:%i\n", server, (int)port);

	BNetworkAddress address;
	status_t status = address.SetTo(server, port);
	if (status != B_OK)
		return status;

	fSocket = socket(address.Family(), SOCK_STREAM, 0);
	if (fSocket < 0)
		return errno;

	int result = connect(fSocket, address, address.Length());
	if (result < 0) {
		close(fSocket);
		return errno;
	}

	TRACE("SocketConnection: connected\n");

	return B_OK;
}
开发者ID:,项目名称:,代码行数:27,代码来源:

示例2:

status_t
BNetworkAddressResolver::GetNextAddress(int family, uint32* cookie,
	BNetworkAddress& address) const
{
	if (fStatus != B_OK)
		return fStatus;

	// Skip previous info entries, and those that have a non-matching family

	addrinfo* info = fInfo;
	int32 first = *cookie;
	for (int32 index = 0; index < first && info != NULL; index++) {
		while (info != NULL && info->ai_family != family)
			info = info->ai_next;
	}

	if (info == NULL)
		return B_BAD_VALUE;

	// Return current

	address.SetTo(*info->ai_addr, info->ai_addrlen);
	(*cookie)++;

	return B_OK;
}
开发者ID:SummerSnail2014,项目名称:haiku,代码行数:26,代码来源:NetworkAddressResolver.cpp

示例3: strerror

status_t
SocketConnection::Connect(const char* server, uint32 port)
{
	if (fSocket >= 0)
		Disconnect();

	TRACE("SocketConnection to server %s:%i\n", server, (int)port);

	BNetworkAddress address;
	status_t status = address.SetTo(server, port);
	if (status != B_OK) {
		TRACE("%s: Address Error: %s\n", __func__, strerror(status));
		return status;
	}

	TRACE("Server resolves to %s\n", address.ToString().String());

	fSocket = socket(address.Family(), SOCK_STREAM, 0);
	if (fSocket < 0) {
		TRACE("%s: Socket Error: %s\n", __func__, strerror(errno));
		return errno;
	}

	int result = connect(fSocket, address, address.Length());
	if (result < 0) {
		TRACE("%s: Connect Error: %s\n", __func__, strerror(errno));
		close(fSocket);
		return errno;
	}

	TRACE("SocketConnection: connected\n");

	return B_OK;
}
开发者ID:mmadia,项目名称:Haiku-services-branch,代码行数:34,代码来源:ServerConnection.cpp

示例4:

/*!	Parses the \a argument as network \a address for the specified \a family.
	If \a family is \c AF_UNSPEC, \a family will be overwritten with the family
	of the successfully parsed address.
*/
bool
parse_address(int& family, const char* argument, BNetworkAddress& address)
{
	if (argument == NULL)
		return false;

	status_t status = address.SetTo(family, argument, (uint16)0,
		B_NO_ADDRESS_RESOLUTION);
	if (status != B_OK)
		return false;

	if (family == AF_UNSPEC) {
		// Test if we support the resulting address family
		bool supported = false;

		for (int32 i = 0; kFamilies[i].family >= 0; i++) {
			if (kFamilies[i].family == address.Family()) {
				supported = true;
				break;
			}
		}
		if (!supported)
			return false;

		// Take over family from address
		family = address.Family();
	}

	return true;
}
开发者ID:,项目名称:,代码行数:34,代码来源:

示例5:

bool
parse_address(int32 familyIndex, const char* argument, BNetworkAddress& address)
{
	if (argument == NULL)
		return false;

	return address.SetTo(kFamilies[familyIndex].family, argument,
		(uint16)0, B_NO_ADDRESS_RESOLUTION) == B_OK;
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:9,代码来源:route.cpp

示例6: Name

status_t
BNetworkDevice::GetHardwareAddress(BNetworkAddress& address)
{
	ifreq request;
	status_t status = do_request(request, Name(), SIOCGIFADDR);
	if (status != B_OK)
		return status;

	address.SetTo(request.ifr_addr);
	return B_OK;
}
开发者ID:SummerSnail2014,项目名称:haiku,代码行数:11,代码来源:NetworkDevice.cpp

示例7: Text

void
IPAddressControl::_UpdateMark()
{
	if (TextLength() == 0) {
		MarkAsInvalid(!fAllowEmpty);
		return;
	}

	BNetworkAddress address;
	bool success = address.SetTo(fFamily, Text()) == B_OK;

	MarkAsInvalid(!success);
}
开发者ID:SummerSnail2014,项目名称:haiku,代码行数:13,代码来源:IPAddressControl.cpp

示例8: Text

void
IPAddressControl::_UpdateMark()
{
	if (TextLength() == 0) {
		MarkAsInvalid(!fAllowEmpty);
		return;
	}

	BNetworkAddress address;
	bool success = address.SetTo(fFamily, Text(), (char*)NULL,
		B_NO_ADDRESS_RESOLUTION) == B_OK;

	MarkAsInvalid(!success);
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:14,代码来源:IPAddressControl.cpp

示例9: routes

status_t
BNetworkInterface::GetDefaultRoute(int family, BNetworkAddress& gateway) const
{
	BObjectList<route_entry> routes(1, true);
	status_t status = GetRoutes(family, routes);
	if (status != B_OK)
		return status;

	for (int32 i = routes.CountItems() - 1; i >= 0; i--) {
		route_entry* entry = routes.ItemAt(i);
		if (entry->flags & RTF_DEFAULT) {
			gateway.SetTo(*entry->gateway);
			break;
		}
	}

	return B_OK;
}
开发者ID:,项目名称:,代码行数:18,代码来源:

示例10: closer

status_t
BNetworkInterface::GetHardwareAddress(BNetworkAddress& address)
{
	int socket = ::socket(AF_LINK, SOCK_DGRAM, 0);
	if (socket < 0)
		return errno;

	FileDescriptorCloser closer(socket);

	ifreq request;
	strlcpy(request.ifr_name, Name(), IF_NAMESIZE);

	if (ioctl(socket, SIOCGIFADDR, &request, sizeof(struct ifreq)) < 0)
		return errno;

	address.SetTo(request.ifr_addr);
	return B_OK;
}
开发者ID:,项目名称:,代码行数:18,代码来源:

示例11: if

bool
configure_wireless(const char* name, char* const* args, int32 argCount)
{
	enum {
		NONE,
		LIST,
		JOIN,
		LEAVE
	} mode = NONE;

	if (!strcmp(args[0], "list") || !strcmp(args[0], "scan"))
		mode = LIST;
	else if (!strcmp(args[0], "join"))
		mode = JOIN;
	else if (!strcmp(args[0], "leave"))
		mode = LEAVE;

	if (mode == NONE)
		return false;

	BNetworkDevice device(name);
	if (!device.Exists()) {
		fprintf(stderr, "%s: \"%s\" does not exist!\n", kProgramName, name);
		exit(1);
	}
	if (!device.IsWireless()) {
		fprintf(stderr, "%s: \"%s\" is not a WLAN device!\n", kProgramName,
			name);
		exit(1);
	}

	args++;
	argCount--;

	switch (mode) {
		case LIST:
		{
			// list wireless network(s)

			bool verbose = false;
			if (argCount > 0 && !strcmp(args[0], "-v")) {
				verbose = true;
				args++;
				argCount--;
			}
			show_wireless_network_header(verbose);

			if (argCount > 0) {
				// list the named entries
				for (int32 i = 0; i < argCount; i++) {
					wireless_network network;
					BNetworkAddress link;
					status_t status;
					if (link.SetTo(AF_LINK, args[i]) == B_OK)
						status = device.GetNetwork(link, network);
					else
						status = device.GetNetwork(args[i], network);
					if (status != B_OK) {
						fprintf(stderr, "%s: Getting network failed: %s\n",
							kProgramName, strerror(status));
					} else
						show_wireless_network(network, verbose);
				}
			} else {
				// list them all
				wireless_network network;
				uint32 cookie = 0;
				while (device.GetNextNetwork(cookie, network) == B_OK)
					show_wireless_network(network, verbose);
			}
			break;
		}

		case JOIN:
		{
			// join a wireless network
			if (argCount > 2) {
				fprintf(stderr, "usage: %s %s join <network> [<password>]\n",
					kProgramName, name);
				exit(1);
			}

			const char* password = NULL;
			if (argCount == 2)
				password = args[1];

			BNetworkAddress link;
			status_t status;
			if (link.SetTo(AF_LINK, args[0]) == B_OK)
				status = device.JoinNetwork(link, password);
			else
				status = device.JoinNetwork(args[0], password);
			if (status != B_OK) {
				fprintf(stderr, "%s: Joining network failed: %s\n",
					kProgramName, strerror(status));
				exit(1);
			}
			break;
		}

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

示例12: device

int
main(int argc, char** argv)
{
	if (argc < 2)
		usage();

	BNetworkDevice device(argv[1]);
	if (!device.Exists()) {
		fprintf(stderr, "\"%s\" does not exist!\n", argv[1]);
		return 1;
	}
	if (!device.IsWireless()) {
		fprintf(stderr, "\"%s\" is not a WLAN device!\n", argv[1]);
		return 1;
	}

	if (argc > 2) {
		if (!strcmp(argv[2], "join")) {
			if (argc < 4)
				usage();
			const char* password = NULL;
			if (argc == 5)
				password = argv[4];

			status_t status = device.JoinNetwork(argv[3], password);
			if (status != B_OK) {
				fprintf(stderr, "joining network failed: %s\n",
					strerror(status));
				return 1;
			}
		} else if (!strcmp(argv[2], "leave")) {
			if (argc < 4)
				usage();

			status_t status = device.LeaveNetwork(argv[3]);
			if (status != B_OK) {
				fprintf(stderr, "leaving network failed: %s\n",
					strerror(status));
				return 1;
			}
		} else if (!strcmp(argv[2], "list")) {
			if (argc == 4) {
				// list the named entry
				wireless_network network;
				BNetworkAddress link;
				status_t status = link.SetTo(AF_LINK, argv[3]);
				if (status == B_OK)
					status = device.GetNetwork(link, network);
				else
					status = device.GetNetwork(argv[3], network);
				if (status != B_OK) {
					fprintf(stderr, "getting network failed: %s\n",
						strerror(status));
					return 1;
				}
				show(network);
			} else {
				// list all
				wireless_network network;
				uint32 cookie = 0;
				while (device.GetNextNetwork(cookie, network) == B_OK)
					show(network);
			}
		} else
			usage();
	} else {
		// show associated networks
		wireless_network network;
		uint32 cookie = 0;
		while (device.GetNextAssociatedNetwork(cookie, network) == B_OK) {
			show(network);
		}
		if (cookie == 0)
			puts("no associated networks found.");
	}

	return 0;
}
开发者ID:SummerSnail2014,项目名称:haiku,代码行数:78,代码来源:wlan_test.cpp

示例13: destination

void
list_routes(int socket, const char *interfaceName, route_entry &route)
{
	// get a list of all routes

	ifconf config;
	config.ifc_len = sizeof(config.ifc_value);
	if (ioctl(socket, SIOCGRTSIZE, &config, sizeof(struct ifconf)) < 0)
		return;

	uint32 size = (uint32)config.ifc_value;
	if (size == 0)
		return;

	void *buffer = malloc(size);
	if (buffer == NULL) {
		fprintf(stderr, "%s: Out of memory.\n", kProgramName);
		return;
	}

	config.ifc_len = size;
	config.ifc_buf = buffer;
	if (ioctl(socket, SIOCGRTTABLE, &config, sizeof(struct ifconf)) < 0)
		return;

	ifreq *interface = (ifreq*)buffer;
	ifreq *end = (ifreq*)((uint8*)buffer + size);

	// find family (we use the family of the first address as this is
	// called on a socket for a single family)
	const address_family *family = NULL;
	for (int32 i = 0; kFamilies[i].family >= 0; i++) {
		if (interface->ifr_route.destination->sa_family
				== kFamilies[i].family) {
			family = &kFamilies[i];
			break;
		}
	}

	int addressLength = family->maxAddressLength;

	printf("%s routing table:\n", family->name);

	if (family->preferredPrefixFormat == PREFIX_PREFER_NETMASK) {
		printf("%*s %*s %*s Flags  Interface\n", addressLength, "Destination",
			addressLength, "Netmask", addressLength, "Gateway");
	} else {
		printf("%*s     %*s Flags  Interface\n", addressLength, "Destination",
			addressLength, "Gateway");
	}

	while (interface < end) {
		route_entry& route = interface->ifr_route;

		// apply filters
		if (interfaceName == NULL
			|| !strcmp(interfaceName, interface->ifr_name)) {

			if (family != NULL) {
				BNetworkAddress destination(*route.destination);
				printf("%*s", addressLength, destination.ToString().String());
				if (route.mask != NULL) {
					BNetworkAddress mask;
					mask.SetTo(*route.mask);
					if (family->preferredPrefixFormat
							== PREFIX_PREFER_NETMASK) {
						printf(" %*s ", addressLength,
							mask.ToString().String());
					} else {
						printf("/%-3zd ", mask.PrefixLength());
					}
				} else {
					if (family->preferredPrefixFormat
							== PREFIX_PREFER_NETMASK) {
						printf(" %*s ", addressLength, "-");
					} else
						printf("     ");
				}

				if ((route.flags & RTF_GATEWAY) != 0) {
					BNetworkAddress gateway;
					if (route.gateway != NULL)
						gateway.SetTo(*route.gateway);
					printf("%*s ", addressLength, gateway.ToString().String());
				} else
					printf("%*s ", family->maxAddressLength, "-");
			} else
				printf("unknown family ");

			if (route.flags != 0) {
				const struct {
					int			value;
					const char	*name;
				} kFlags[] = {
					{RTF_DEFAULT, "D"},
					{RTF_REJECT, "R"},
					{RTF_HOST, "H"},
					{RTF_LOCAL, "L"},
					{RTF_DYNAMIC, "D"},
					{RTF_MODIFIED, "M"},
//.........这里部分代码省略.........
开发者ID:AmirAbrams,项目名称:haiku,代码行数:101,代码来源:route.cpp


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