San Mehat | dc26607 | 2009-05-06 11:16:52 -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 | */ |
San Mehat | 5d6d417 | 2009-05-14 15:00:06 -0700 | [diff] [blame] | 16 | |
San Mehat | 4876567 | 2009-05-20 15:28:43 -0700 | [diff] [blame^] | 17 | #include <stdio.h> |
San Mehat | 5d6d417 | 2009-05-14 15:00:06 -0700 | [diff] [blame] | 18 | #include <string.h> |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 19 | #include <errno.h> |
San Mehat | 5d6d417 | 2009-05-14 15:00:06 -0700 | [diff] [blame] | 20 | #include <sys/socket.h> |
| 21 | #include <netinet/in.h> |
| 22 | #include <arpa/inet.h> |
| 23 | |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 24 | #include "VpnController.h" |
| 25 | |
| 26 | VpnController::VpnController() : |
San Mehat | 4876567 | 2009-05-20 15:28:43 -0700 | [diff] [blame^] | 27 | Controller("VPN", "vpn") { |
| 28 | registerProperty("gateway"); |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | int VpnController::start() { |
San Mehat | 5d6d417 | 2009-05-14 15:00:06 -0700 | [diff] [blame] | 32 | errno = ENOSYS; |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 33 | return -1; |
| 34 | } |
| 35 | |
| 36 | int VpnController::stop() { |
San Mehat | 5d6d417 | 2009-05-14 15:00:06 -0700 | [diff] [blame] | 37 | errno = ENOSYS; |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 38 | return -1; |
| 39 | } |
| 40 | |
| 41 | int VpnController::enable() { |
San Mehat | 5d6d417 | 2009-05-14 15:00:06 -0700 | [diff] [blame] | 42 | errno = ENOSYS; |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 43 | return -1; |
| 44 | } |
| 45 | |
| 46 | int VpnController::disable() { |
San Mehat | 5d6d417 | 2009-05-14 15:00:06 -0700 | [diff] [blame] | 47 | errno = ENOSYS; |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 48 | return -1; |
| 49 | } |
San Mehat | 5d6d417 | 2009-05-14 15:00:06 -0700 | [diff] [blame] | 50 | |
San Mehat | 4876567 | 2009-05-20 15:28:43 -0700 | [diff] [blame^] | 51 | int VpnController::setProperty(const char *name, char *value) { |
| 52 | if (!strcmp(name, "gateway")) { |
| 53 | if (!inet_aton(value, &mVpnGateway)) { |
| 54 | errno = EINVAL; |
| 55 | return -1; |
| 56 | } |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | return Controller::setProperty(name, value); |
San Mehat | 5d6d417 | 2009-05-14 15:00:06 -0700 | [diff] [blame] | 61 | } |
| 62 | |
San Mehat | 4876567 | 2009-05-20 15:28:43 -0700 | [diff] [blame^] | 63 | const char *VpnController::getProperty(const char *name, char *buffer, size_t maxsize) { |
| 64 | if (!strcmp(name, "gateway")) { |
| 65 | snprintf(buffer, maxsize, "%s", inet_ntoa(mVpnGateway)); |
| 66 | return buffer; |
| 67 | } |
| 68 | |
| 69 | return Controller::getProperty(name, buffer, maxsize); |
San Mehat | 5d6d417 | 2009-05-14 15:00:06 -0700 | [diff] [blame] | 70 | } |