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 | #ifndef _INTERFACE_CONFIG_H |
| 18 | #define _INTERFACE_CONFIG_H |
| 19 | |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 20 | #include <unistd.h> |
| 21 | #include <sys/types.h> |
San Mehat | 192331d | 2009-05-22 13:58:06 -0700 | [diff] [blame] | 22 | #include <netinet/in.h> |
| 23 | #include <arpa/inet.h> |
| 24 | |
San Mehat | c4a895b | 2009-06-23 21:10:57 -0700 | [diff] [blame] | 25 | #include "Property.h" |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 26 | class PropertyManager; |
| 27 | |
San Mehat | c4a895b | 2009-06-23 21:10:57 -0700 | [diff] [blame] | 28 | class InterfaceConfig { |
| 29 | class InterfaceDnsProperty; |
| 30 | friend class InterfaceConfig::InterfaceDnsProperty; |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 31 | |
San Mehat | c4a895b | 2009-06-23 21:10:57 -0700 | [diff] [blame] | 32 | struct { |
| 33 | IPV4AddressPropertyHelper *propIp; |
| 34 | IPV4AddressPropertyHelper *propNetmask; |
| 35 | IPV4AddressPropertyHelper *propGateway; |
| 36 | IPV4AddressPropertyHelper *propBroadcast; |
| 37 | InterfaceDnsProperty *propDns; |
| 38 | } mStaticProperties; |
| 39 | |
San Mehat | 192331d | 2009-05-22 13:58:06 -0700 | [diff] [blame] | 40 | struct in_addr mIp; |
| 41 | struct in_addr mNetmask; |
| 42 | struct in_addr mGateway; |
San Mehat | c4a895b | 2009-06-23 21:10:57 -0700 | [diff] [blame] | 43 | struct in_addr mBroadcast; |
| 44 | struct in_addr mDns[2]; |
San Mehat | 192331d | 2009-05-22 13:58:06 -0700 | [diff] [blame] | 45 | |
| 46 | public: |
San Mehat | c4a895b | 2009-06-23 21:10:57 -0700 | [diff] [blame] | 47 | InterfaceConfig(bool propertiesReadOnly); |
San Mehat | 192331d | 2009-05-22 13:58:06 -0700 | [diff] [blame] | 48 | virtual ~InterfaceConfig(); |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 49 | |
| 50 | int set(const char *name, const char *value); |
| 51 | const char *get(const char *name, char *buffer, size_t maxsize); |
San Mehat | 192331d | 2009-05-22 13:58:06 -0700 | [diff] [blame] | 52 | |
San Mehat | 192331d | 2009-05-22 13:58:06 -0700 | [diff] [blame] | 53 | 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 Mehat | c4a895b | 2009-06-23 21:10:57 -0700 | [diff] [blame] | 56 | 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 Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 67 | |
| 68 | private: |
San Mehat | c4a895b | 2009-06-23 21:10:57 -0700 | [diff] [blame] | 69 | |
| 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 Mehat | 192331d | 2009-05-22 13:58:06 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | |
| 80 | #endif |