blob: 3fc73909c5545dca8df526b5b9bc8db88db3250f [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
17#ifndef _INTERFACE_CONFIG_H
18#define _INTERFACE_CONFIG_H
19
San Mehat3c5a6f02009-05-22 15:36:13 -070020#include <unistd.h>
21#include <sys/types.h>
San Mehat192331d2009-05-22 13:58:06 -070022#include <netinet/in.h>
23#include <arpa/inet.h>
24
San Mehatc4a895b2009-06-23 21:10:57 -070025#include "Property.h"
San Mehat3c5a6f02009-05-22 15:36:13 -070026class PropertyManager;
27
San Mehatc4a895b2009-06-23 21:10:57 -070028class InterfaceConfig {
29 class InterfaceDnsProperty;
30 friend class InterfaceConfig::InterfaceDnsProperty;
San Mehat3c5a6f02009-05-22 15:36:13 -070031
San Mehatc4a895b2009-06-23 21:10:57 -070032 struct {
33 IPV4AddressPropertyHelper *propIp;
34 IPV4AddressPropertyHelper *propNetmask;
35 IPV4AddressPropertyHelper *propGateway;
36 IPV4AddressPropertyHelper *propBroadcast;
37 InterfaceDnsProperty *propDns;
38 } mStaticProperties;
39
San Mehat192331d2009-05-22 13:58:06 -070040 struct in_addr mIp;
41 struct in_addr mNetmask;
42 struct in_addr mGateway;
San Mehatc4a895b2009-06-23 21:10:57 -070043 struct in_addr mBroadcast;
44 struct in_addr mDns[2];
San Mehat192331d2009-05-22 13:58:06 -070045
46public:
San Mehatc4a895b2009-06-23 21:10:57 -070047 InterfaceConfig(bool propertiesReadOnly);
San Mehat192331d2009-05-22 13:58:06 -070048 virtual ~InterfaceConfig();
San Mehat3c5a6f02009-05-22 15:36:13 -070049
50 int set(const char *name, const char *value);
51 const char *get(const char *name, char *buffer, size_t maxsize);
San Mehat192331d2009-05-22 13:58:06 -070052
San Mehat192331d2009-05-22 13:58:06 -070053 const struct in_addr &getIp() const { return mIp; }
54 const struct in_addr &getNetmask() const { return mNetmask; }
55 const struct in_addr &getGateway() const { return mGateway; }
San Mehatc4a895b2009-06-23 21:10:57 -070056 const struct in_addr &getBroadcast() const { return mBroadcast; }
57 const struct in_addr &getDns(int idx) const { return mDns[idx]; }
58
59 void setIp(struct in_addr *addr);
60 void setNetmask(struct in_addr *addr);
61 void setGateway(struct in_addr *addr);
62 void setBroadcast(struct in_addr *addr);
63 void setDns(int idx, struct in_addr *addr);
64
65 int attachProperties(PropertyManager *pm, const char *nsName);
66 int detachProperties(PropertyManager *pm, const char *nsName);
San Mehat3c5a6f02009-05-22 15:36:13 -070067
68private:
San Mehatc4a895b2009-06-23 21:10:57 -070069
70 class InterfaceDnsProperty : public IPV4AddressProperty {
71 InterfaceConfig *mCfg;
72 public:
73 InterfaceDnsProperty(InterfaceConfig *cfg, bool ro);
74 int set(int idx, struct in_addr *value);
75 int get(int idx, struct in_addr *buffer);
76 };
San Mehat192331d2009-05-22 13:58:06 -070077};
78
79
80#endif