San Mehat | 192331d | 2009-05-22 13:58:06 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <string.h> |
| 18 | |
| 19 | #define LOG_TAG "InterfaceConfig" |
| 20 | #include <cutils/log.h> |
| 21 | |
| 22 | #include "InterfaceConfig.h" |
| 23 | |
| 24 | InterfaceConfig::InterfaceConfig(const char *name) { |
| 25 | mName = strdup(name); |
| 26 | mUseDhcp = true; |
| 27 | } |
| 28 | |
| 29 | InterfaceConfig::~InterfaceConfig() { |
| 30 | free(mName); |
| 31 | } |
| 32 | |
| 33 | InterfaceConfig::InterfaceConfig(const char *name, const char *ip, const char *nm, |
| 34 | const char *gw, const char *dns1, const char *dns2, |
| 35 | const char *dns3) { |
| 36 | mName = strdup(name); |
| 37 | mUseDhcp = false; |
| 38 | |
| 39 | if (!inet_aton(ip, &mIp)) |
| 40 | LOGW("Unable to parse ip (%s)", ip); |
| 41 | if (!inet_aton(nm, &mIp)) |
| 42 | LOGW("Unable to parse netmask (%s)", nm); |
| 43 | if (!inet_aton(gw, &mIp)) |
| 44 | LOGW("Unable to parse gateway (%s)", gw); |
| 45 | if (!inet_aton(dns1, &mIp)) |
| 46 | LOGW("Unable to parse dns1 (%s)", dns1); |
| 47 | if (!inet_aton(dns2, &mIp)) |
| 48 | LOGW("Unable to parse dns2 (%s)", dns2); |
| 49 | if (!inet_aton(dns3, &mIp)) |
| 50 | LOGW("Unable to parse dns3 (%s)", dns3); |
| 51 | } |
| 52 | |
| 53 | InterfaceConfig::InterfaceConfig(const char *name, const struct in_addr *ip, |
| 54 | const struct in_addr *nm, const struct in_addr *gw, |
| 55 | const struct in_addr *dns1, const struct in_addr *dns2, |
| 56 | const struct in_addr *dns3) { |
| 57 | mName = strdup(name); |
| 58 | mUseDhcp = false; |
| 59 | |
| 60 | memcpy(&mIp, ip, sizeof(struct in_addr)); |
| 61 | memcpy(&mNetmask, nm, sizeof(struct in_addr)); |
| 62 | memcpy(&mGateway, gw, sizeof(struct in_addr)); |
| 63 | memcpy(&mDns1, dns1, sizeof(struct in_addr)); |
| 64 | memcpy(&mDns2, dns2, sizeof(struct in_addr)); |
| 65 | memcpy(&mDns3, dns3, sizeof(struct in_addr)); |
| 66 | } |
| 67 | |