本文整理汇总了C++中BNetworkAddress类的典型用法代码示例。如果您正苦于以下问题:C++ BNetworkAddress类的具体用法?C++ BNetworkAddress怎么用?C++ BNetworkAddress使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BNetworkAddress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Disconnect
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;
}
示例2: _Setup
status_t
BProxySecureSocket::Connect(const BNetworkAddress& peer, bigtime_t timeout)
{
status_t status = InitCheck();
if (status != B_OK)
return status;
BSocket::Connect(fProxyAddress, timeout);
if (status != B_OK)
return status;
BString connectRequest;
connectRequest.SetToFormat("CONNECT %s:%d HTTP/1.0\r\n\r\n",
peer.HostName().String(), peer.Port());
BSocket::Write(connectRequest.String(), connectRequest.Length());
char buffer[256];
ssize_t length = BSocket::Read(buffer, sizeof(buffer) - 1);
if (length <= 0)
return length;
buffer[length] = '\0';
int httpStatus = 0;
int matches = scanf(buffer, "HTTP/1.0 %d %*[^\r\n]\r\n\r\n", httpStatus);
if (matches != 2)
return B_BAD_DATA;
if (httpStatus < 200 || httpStatus > 299)
return B_BAD_VALUE;
return _Setup();
}
示例3: Disconnect
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: memcmp
bool
BNetworkAddress::Equals(const BNetworkAddress& other, bool includePort) const
{
if (IsEmpty() && other.IsEmpty())
return true;
if (Family() != other.Family()
|| (includePort && Port() != other.Port())) {
return false;
}
switch (fAddress.ss_family) {
case AF_INET:
{
sockaddr_in& address = (sockaddr_in&)fAddress;
sockaddr_in& otherAddress = (sockaddr_in&)other.fAddress;
return memcmp(&address.sin_addr, &otherAddress.sin_addr,
sizeof(address.sin_addr)) == 0;
}
case AF_INET6:
{
sockaddr_in6& address = (sockaddr_in6&)fAddress;
sockaddr_in6& otherAddress = (sockaddr_in6&)other.fAddress;
return memcmp(&address.sin6_addr, &otherAddress.sin6_addr,
sizeof(address.sin6_addr)) == 0;
}
default:
if (fAddress.ss_len != other.fAddress.ss_len)
return false;
return memcmp(&fAddress, &other.fAddress, fAddress.ss_len);
}
}
示例5: parse_address
/*! 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;
}
示例6: do_request
status_t
BNetworkInterface::RemoveAddress(const BNetworkAddress& address)
{
ifreq request;
memcpy(&request.ifr_addr, &address.SockAddr(), address.Length());
return do_request(address.Family(), request, Name(), B_SOCKET_REMOVE_ALIAS);
}
示例7:
const char*
NetworkSettings::HardwareAddress()
{
BNetworkAddress macAddress;
if (fNetworkInterface->GetHardwareAddress(macAddress) == B_OK)
return macAddress.ToString();
return NULL;
}
示例8: MarkAsInvalid
void
IPAddressControl::_UpdateMark()
{
if (TextLength() == 0) {
MarkAsInvalid(!fAllowEmpty);
return;
}
BNetworkAddress address;
bool success = address.SetTo(fFamily, Text()) == B_OK;
MarkAsInvalid(!success);
}
示例9: Disconnect
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;
}
示例10:
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());
}
示例11: MarkAsInvalid
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);
}
示例12:
status_t
BAbstractSocket::Bind(const BNetworkAddress& local, int type)
{
fInitStatus = _OpenIfNeeded(local.Family(), type);
if (fInitStatus != B_OK)
return fInitStatus;
if (bind(fSocket, local, local.Length()) != 0)
return fInitStatus = errno;
fIsBound = true;
_UpdateLocalAddress();
return B_OK;
}
示例13:
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;
}
示例14: message
status_t
BNetworkDevice::JoinNetwork(const BNetworkAddress& address,
const char* password)
{
if (address.InitCheck() != B_OK)
return B_BAD_VALUE;
BMessage message(kMsgJoinNetwork);
status_t status = message.AddString("device", Name());
if (status == B_OK) {
status = message.AddFlat("address",
const_cast<BNetworkAddress*>(&address));
}
if (status == B_OK && password != NULL)
status = message.AddString("password", password);
if (status != B_OK)
return status;
// Send message to the net_server
BMessenger networkServer(kNetServerSignature);
BMessage reply;
status = networkServer.SendMessage(&message, &reply);
if (status == B_OK)
reply.FindInt32("status", &status);
return status;
}
示例15: 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];
}
}