* Simplified get_address_family() function.
* Use new BNetworkInterface::AutoConfigure() method. * Automatic whitespace cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39594 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
2bd61a6f33
commit
01308f219b
@ -167,21 +167,19 @@ media_parse_subtype(const char* string, int media, int* type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool
|
int
|
||||||
get_address_family(const char* argument, int& family)
|
get_address_family(const char* argument)
|
||||||
{
|
{
|
||||||
for (int32 i = 0; kFamilies[i].family >= 0; i++) {
|
for (int32 i = 0; kFamilies[i].family >= 0; i++) {
|
||||||
for (int32 j = 0; kFamilies[i].identifiers[j]; j++) {
|
for (int32 j = 0; kFamilies[i].identifiers[j]; j++) {
|
||||||
if (!strcmp(argument, kFamilies[i].identifiers[j])) {
|
if (!strcmp(argument, kFamilies[i].identifiers[j])) {
|
||||||
// found a match
|
// found a match
|
||||||
family = kFamilies[i].family;
|
return kFamilies[i].family;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
family = AF_UNSPEC;
|
return AF_UNSPEC;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -440,8 +438,8 @@ delete_interface(const char* name, char* const* args, int32 argCount)
|
|||||||
BNetworkInterface interface(name);
|
BNetworkInterface interface(name);
|
||||||
|
|
||||||
for (int32 i = 0; i < argCount; i++) {
|
for (int32 i = 0; i < argCount; i++) {
|
||||||
int family;
|
int family = get_address_family(args[i]);
|
||||||
if (get_address_family(args[i], family))
|
if (family != AF_UNSPEC)
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
BNetworkAddress address;
|
BNetworkAddress address;
|
||||||
@ -477,9 +475,9 @@ configure_interface(const char* name, char* const* args,
|
|||||||
{
|
{
|
||||||
// try to parse address family
|
// try to parse address family
|
||||||
|
|
||||||
int family;
|
|
||||||
int32 i = 0;
|
int32 i = 0;
|
||||||
if (get_address_family(args[i], family))
|
int family = get_address_family(args[i]);
|
||||||
|
if (family != AF_UNSPEC)
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
// try to parse address
|
// try to parse address
|
||||||
@ -702,28 +700,13 @@ configure_interface(const char* name, char* const* args,
|
|||||||
// start auto configuration, if asked for
|
// start auto configuration, if asked for
|
||||||
|
|
||||||
if (doAutoConfig) {
|
if (doAutoConfig) {
|
||||||
BMessage message(kMsgConfigureInterface);
|
status_t status = interface.AutoConfigure(family);
|
||||||
message.AddString("device", name);
|
if (status == B_BAD_PORT_ID) {
|
||||||
BMessage address;
|
|
||||||
address.AddString("family", address_family_for(family)->name);
|
|
||||||
address.AddBool("auto_config", true);
|
|
||||||
message.AddMessage("address", &address);
|
|
||||||
|
|
||||||
BMessenger networkServer(kNetServerSignature);
|
|
||||||
if (networkServer.IsValid()) {
|
|
||||||
BMessage reply;
|
|
||||||
status_t status = networkServer.SendMessage(&message, &reply);
|
|
||||||
if (status != B_OK) {
|
|
||||||
fprintf(stderr, "%s: Sending auto-config message failed: %s\n",
|
|
||||||
kProgramName, strerror(status));
|
|
||||||
} else if (reply.FindInt32("status", &status) == B_OK
|
|
||||||
&& status != B_OK) {
|
|
||||||
fprintf(stderr, "%s: Auto-configuring failed: %s\n",
|
|
||||||
kProgramName, strerror(status));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "%s: The net_server needs to run for the auto "
|
fprintf(stderr, "%s: The net_server needs to run for the auto "
|
||||||
"configuration!\n", kProgramName);
|
"configuration!\n", kProgramName);
|
||||||
|
} else if (status != B_OK) {
|
||||||
|
fprintf(stderr, "%s: Auto-configuring failed: %s\n", kProgramName,
|
||||||
|
strerror(status));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user