• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  
20  #include <unistd.h>
21  #include <sys/types.h>
22  #include <netinet/in.h>
23  #include <arpa/inet.h>
24  
25  #include "Property.h"
26  class PropertyManager;
27  
28  class InterfaceConfig {
29      class InterfaceDnsProperty;
30      friend class InterfaceConfig::InterfaceDnsProperty;
31  
32      struct {
33          IPV4AddressPropertyHelper *propIp;
34          IPV4AddressPropertyHelper *propNetmask;
35          IPV4AddressPropertyHelper *propGateway;
36          IPV4AddressPropertyHelper *propBroadcast;
37          InterfaceDnsProperty      *propDns;
38      } mStaticProperties;
39  
40      struct in_addr mIp;
41      struct in_addr mNetmask;
42      struct in_addr mGateway;
43      struct in_addr mBroadcast;
44      struct in_addr mDns[2];
45  
46  public:
47      InterfaceConfig(bool propertiesReadOnly);
48      virtual ~InterfaceConfig();
49  
50      int set(const char *name, const char *value);
51      const char *get(const char *name, char *buffer, size_t maxsize);
52  
getIp()53      const struct in_addr &getIp() const { return mIp; }
getNetmask()54      const struct in_addr &getNetmask() const { return mNetmask; }
getGateway()55      const struct in_addr &getGateway() const { return mGateway; }
getBroadcast()56      const struct in_addr &getBroadcast() const { return mBroadcast; }
getDns(int idx)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);
67  
68  private:
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      };
77  };
78  
79  
80  #endif
81