* 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:
Axel Dörfler 2010-11-23 21:05:32 +00:00
parent 2bd61a6f33
commit 01308f219b

View File

@ -167,21 +167,19 @@ media_parse_subtype(const char* string, int media, int* type)
}
static bool
get_address_family(const char* argument, int& family)
int
get_address_family(const char* argument)
{
for (int32 i = 0; kFamilies[i].family >= 0; i++) {
for (int32 j = 0; kFamilies[i].identifiers[j]; j++) {
if (!strcmp(argument, kFamilies[i].identifiers[j])) {
// found a match
family = kFamilies[i].family;
return true;
return kFamilies[i].family;
}
}
}
family = AF_UNSPEC;
return false;
return AF_UNSPEC;
}
@ -440,8 +438,8 @@ delete_interface(const char* name, char* const* args, int32 argCount)
BNetworkInterface interface(name);
for (int32 i = 0; i < argCount; i++) {
int family;
if (get_address_family(args[i], family))
int family = get_address_family(args[i]);
if (family != AF_UNSPEC)
i++;
BNetworkAddress address;
@ -477,9 +475,9 @@ configure_interface(const char* name, char* const* args,
{
// try to parse address family
int family;
int32 i = 0;
if (get_address_family(args[i], family))
int family = get_address_family(args[i]);
if (family != AF_UNSPEC)
i++;
// try to parse address
@ -702,28 +700,13 @@ configure_interface(const char* name, char* const* args,
// start auto configuration, if asked for
if (doAutoConfig) {
BMessage message(kMsgConfigureInterface);
message.AddString("device", name);
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 {
status_t status = interface.AutoConfigure(family);
if (status == B_BAD_PORT_ID) {
fprintf(stderr, "%s: The net_server needs to run for the auto "
"configuration!\n", kProgramName);
} else if (status != B_OK) {
fprintf(stderr, "%s: Auto-configuring failed: %s\n", kProgramName,
strerror(status));
}
}
}