本文整理汇总了C++中BNetworkAddress::ToString方法的典型用法代码示例。如果您正苦于以下问题:C++ BNetworkAddress::ToString方法的具体用法?C++ BNetworkAddress::ToString怎么用?C++ BNetworkAddress::ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BNetworkAddress
的用法示例。
在下文中一共展示了BNetworkAddress::ToString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetTimeout
status_t
BAbstractSocket::Connect(const BNetworkAddress& peer, int type,
bigtime_t timeout)
{
Disconnect();
fInitStatus = _OpenIfNeeded(peer.Family(), type);
if (fInitStatus == B_OK)
fInitStatus = SetTimeout(timeout);
if (fInitStatus == B_OK && !IsBound()) {
BNetworkAddress local;
local.SetToWildcard(peer.Family());
fInitStatus = Bind(local);
}
if (fInitStatus != B_OK)
return fInitStatus;
BNetworkAddress normalized = peer;
if (connect(fSocket, normalized, normalized.Length()) != 0) {
TRACE("%p: connecting to %s: %s\n", this,
normalized.ToString().c_str(), strerror(errno));
return fInitStatus = errno;
}
fIsConnected = true;
fPeer = normalized;
_UpdateLocalAddress();
TRACE("%p: connected to %s (local %s)\n", this, peer.ToString().c_str(),
fLocal.ToString().c_str());
return fInitStatus = B_OK;
}
示例2:
void
BSocket::_SetTo(int fd, const BNetworkAddress& local,
const BNetworkAddress& peer)
{
Disconnect();
fInitStatus = B_OK;
fSocket = fd;
fLocal = local;
fPeer = peer;
TRACE("%p: accepted from %s to %s\n", this, local.ToString().c_str(),
peer.ToString().c_str());
}
示例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;
}
示例4: interface
void
Settings::ReadConfiguration()
{
BNetworkInterface interface(fName);
BNetworkAddress hardwareAddress;
if (interface.GetHardwareAddress(hardwareAddress) != B_OK)
return;
fHardwareAddress = hardwareAddress.ToString();
BNetworkInterfaceAddress address;
// TODO: We only get the first address
if (interface.GetAddressAt(0, address) != B_OK)
return;
fIP = address.Address().ToString();
fNetmask = address.Mask().ToString();
int family = AF_INET;
if (address.Address().Family() != AF_UNSPEC)
family = address.Address().Family();
BNetworkAddress gatewayAddress;
if (interface.GetDefaultRoute(family, gatewayAddress) != B_OK)
return;
fGateway = gatewayAddress.ToString();
uint32 flags = interface.Flags();
fAuto = (flags & (IFF_AUTO_CONFIGURED | IFF_CONFIGURING)) != 0;
fDisabled = (flags & IFF_UP) == 0;
// read resolv.conf for the dns.
fNameServers.MakeEmpty();
res_init();
res_state state = __res_state();
if (state != NULL) {
for (int i = 0; i < state->nscount; i++) {
fNameServers.AddItem(
new BString(inet_ntoa(state->nsaddr_list[i].sin_addr)));
}
fDomain = state->dnsrch[0];
}
}
示例5:
const char*
NetworkSettings::HardwareAddress()
{
BNetworkAddress macAddress;
if (fNetworkInterface->GetHardwareAddress(macAddress) == B_OK)
return macAddress.ToString();
return NULL;
}
示例6: 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"},
//.........这里部分代码省略.........