blob: 832cbcabd3ab9dab376f61387542d2922eb760b5 [file] [log] [blame]
San Mehat192331d2009-05-22 13:58:06 -07001/*
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
San Mehat3c5a6f02009-05-22 15:36:13 -070017#include <stdlib.h>
San Mehat192331d2009-05-22 13:58:06 -070018#include <string.h>
19
20#define LOG_TAG "InterfaceConfig"
21#include <cutils/log.h>
22
23#include "InterfaceConfig.h"
San Mehat3c5a6f02009-05-22 15:36:13 -070024#include "NetworkManager.h"
San Mehat192331d2009-05-22 13:58:06 -070025
San Mehatc4a895b2009-06-23 21:10:57 -070026InterfaceConfig::InterfaceConfig(bool propertiesReadOnly) {
27 mStaticProperties.propIp = new IPV4AddressPropertyHelper("Addr", propertiesReadOnly, &mIp);
28 mStaticProperties.propNetmask = new IPV4AddressPropertyHelper("Netmask", propertiesReadOnly, &mNetmask);
29 mStaticProperties.propGateway = new IPV4AddressPropertyHelper("Gateway", propertiesReadOnly, &mGateway);
30 mStaticProperties.propBroadcast = new IPV4AddressPropertyHelper("Broadcast", propertiesReadOnly, &mBroadcast);
31 mStaticProperties.propDns = new InterfaceDnsProperty(this, propertiesReadOnly);
San Mehat192331d2009-05-22 13:58:06 -070032}
33
34InterfaceConfig::~InterfaceConfig() {
San Mehatc4a895b2009-06-23 21:10:57 -070035 delete mStaticProperties.propIp;
36 delete mStaticProperties.propNetmask;
37 delete mStaticProperties.propGateway;
38 delete mStaticProperties.propBroadcast;
39 delete mStaticProperties.propDns;
San Mehat192331d2009-05-22 13:58:06 -070040}
41
San Mehatc4a895b2009-06-23 21:10:57 -070042void InterfaceConfig::setIp(struct in_addr *addr) {
43 memcpy(&mIp, addr, sizeof(struct in_addr));
San Mehat192331d2009-05-22 13:58:06 -070044}
45
San Mehatc4a895b2009-06-23 21:10:57 -070046void InterfaceConfig::setNetmask(struct in_addr *addr) {
47 memcpy(&mNetmask, addr, sizeof(struct in_addr));
San Mehat192331d2009-05-22 13:58:06 -070048}
49
San Mehatc4a895b2009-06-23 21:10:57 -070050void InterfaceConfig::setGateway(struct in_addr *addr) {
51 memcpy(&mGateway, addr, sizeof(struct in_addr));
52}
San Mehat3c5a6f02009-05-22 15:36:13 -070053
San Mehatc4a895b2009-06-23 21:10:57 -070054void InterfaceConfig::setBroadcast(struct in_addr *addr) {
55 memcpy(&mBroadcast, addr, sizeof(struct in_addr));
56}
57
58void InterfaceConfig::setDns(int idx, struct in_addr *addr) {
59 memcpy(&mDns[idx], addr, sizeof(struct in_addr));
60}
61
62int InterfaceConfig::attachProperties(PropertyManager *pm, const char *nsName) {
63 pm->attachProperty(nsName, mStaticProperties.propIp);
64 pm->attachProperty(nsName, mStaticProperties.propNetmask);
65 pm->attachProperty(nsName, mStaticProperties.propGateway);
66 pm->attachProperty(nsName, mStaticProperties.propBroadcast);
67 pm->attachProperty(nsName, mStaticProperties.propDns);
San Mehat3c5a6f02009-05-22 15:36:13 -070068 return 0;
69}
70
San Mehatc4a895b2009-06-23 21:10:57 -070071int InterfaceConfig::detachProperties(PropertyManager *pm, const char *nsName) {
72 pm->detachProperty(nsName, mStaticProperties.propIp);
73 pm->detachProperty(nsName, mStaticProperties.propNetmask);
74 pm->detachProperty(nsName, mStaticProperties.propGateway);
75 pm->detachProperty(nsName, mStaticProperties.propBroadcast);
76 pm->detachProperty(nsName, mStaticProperties.propDns);
San Mehat3c5a6f02009-05-22 15:36:13 -070077 return 0;
78}
79
San Mehatc4a895b2009-06-23 21:10:57 -070080InterfaceConfig::InterfaceDnsProperty::InterfaceDnsProperty(InterfaceConfig *c,
81 bool ro) :
82 IPV4AddressProperty("Dns", ro, 2) {
83 mCfg = c;
84}
San Mehat3c5a6f02009-05-22 15:36:13 -070085
San Mehatc4a895b2009-06-23 21:10:57 -070086int InterfaceConfig::InterfaceDnsProperty::set(int idx, struct in_addr *value) {
87 memcpy(&mCfg->mDns[idx], value, sizeof(struct in_addr));
San Mehat3c5a6f02009-05-22 15:36:13 -070088 return 0;
San Mehatc4a895b2009-06-23 21:10:57 -070089}
90int InterfaceConfig::InterfaceDnsProperty::get(int idx, struct in_addr *buf) {
91 memcpy(buf, &mCfg->mDns[idx], sizeof(struct in_addr));
92 return 0;
San Mehat3c5a6f02009-05-22 15:36:13 -070093}
94