CommandListener.cpp revision d18304287dbabc7835be771400b85d4ae8b63de6
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#include <stdlib.h>
18#include <sys/socket.h>
19#include <sys/types.h>
20#include <netinet/in.h>
21#include <arpa/inet.h>
22#include <dirent.h>
23#include <errno.h>
24
25#define LOG_TAG "CommandListener"
26#include <cutils/log.h>
27
28#include <sysutils/SocketClient.h>
29
30#include "CommandListener.h"
31#include "ResponseCode.h"
32
33CommandListener::CommandListener() :
34                 FrameworkListener("netd") {
35    registerCmd(new ListInterfacesCmd());
36    registerCmd(new IpFwdCmd());
37    registerCmd(new TetherCmd());
38    registerCmd(new NatCmd());
39}
40
41CommandListener::ListInterfacesCmd::ListInterfacesCmd() :
42                 NetdCommand("list_interfaces") {
43}
44
45int CommandListener::ListInterfacesCmd::runCommand(SocketClient *cli,
46                                                      int argc, char **argv) {
47    cli->sendMsg(ResponseCode::CommandOkay, "Interfaces listed.", false);
48    return 0;
49}
50
51CommandListener::IpFwdCmd::IpFwdCmd() :
52                 NetdCommand("ipfwd") {
53}
54
55int CommandListener::IpFwdCmd::runCommand(SocketClient *cli,
56                                                      int argc, char **argv) {
57
58    return 0;
59}
60
61CommandListener::TetherCmd::TetherCmd() :
62                 NetdCommand("tether") {
63}
64
65int CommandListener::TetherCmd::runCommand(SocketClient *cli,
66                                                      int argc, char **argv) {
67    if (argc < 2) {
68        cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false);
69        return 0;
70    }
71
72    if (!strcmp(argv[1], "start")) {
73    } else if (!strcmp(argv[1], "stop")) {
74    } else if (!strcmp(argv[1], "status")) {
75    } else if (!strcmp(argv[1], "interface")) {
76    } else if (!strcmp(argv[1], "dns")) {
77    } else {
78        cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown tether cmd", false);
79        return 0;
80    }
81
82    return 0;
83}
84
85CommandListener::NatCmd::NatCmd() :
86                 NetdCommand("nat") {
87}
88
89int CommandListener::NatCmd::runCommand(SocketClient *cli,
90                                                      int argc, char **argv) {
91
92    return 0;
93}
94
95