Merge "Remove netcfg's unused options."
This commit is contained in:
commit
67900498cf
|
@ -1348,7 +1348,7 @@ int adb_main(int is_daemon, int server_port)
|
|||
** AID_ADB to access the USB driver
|
||||
** AID_LOG to read system logs (adb logcat)
|
||||
** AID_INPUT to diagnose input issues (getevent)
|
||||
** AID_INET to diagnose network issues (netcfg, ping)
|
||||
** AID_INET to diagnose network issues (ping)
|
||||
** AID_NET_BT and AID_NET_BT_ADMIN to diagnose bluetooth (hcidump)
|
||||
** AID_SDCARD_R to allow reading from the SD card
|
||||
** AID_SDCARD_RW to allow writing to the SD card
|
||||
|
|
|
@ -51,7 +51,6 @@ extern int ifc_set_hwaddr(const char *name, const void *ptr);
|
|||
extern int ifc_clear_addresses(const char *name);
|
||||
|
||||
extern int ifc_create_default_route(const char *name, in_addr_t addr);
|
||||
extern int ifc_remove_default_route(const char *ifname);
|
||||
extern int ifc_get_info(const char *name, in_addr_t *addr, int *prefixLength,
|
||||
unsigned *flags);
|
||||
|
||||
|
|
|
@ -353,28 +353,28 @@ static int send_message(int sock, int if_index, dhcp_msg *msg, int size)
|
|||
static int is_valid_reply(dhcp_msg *msg, dhcp_msg *reply, int sz)
|
||||
{
|
||||
if (sz < DHCP_MSG_FIXED_SIZE) {
|
||||
if (verbose) ALOGD("netcfg: Wrong size %d != %d\n", sz, DHCP_MSG_FIXED_SIZE);
|
||||
if (verbose) ALOGD("dhcp: Wrong size %d != %d\n", sz, DHCP_MSG_FIXED_SIZE);
|
||||
return 0;
|
||||
}
|
||||
if (reply->op != OP_BOOTREPLY) {
|
||||
if (verbose) ALOGD("netcfg: Wrong Op %d != %d\n", reply->op, OP_BOOTREPLY);
|
||||
if (verbose) ALOGD("dhcp: Wrong Op %d != %d\n", reply->op, OP_BOOTREPLY);
|
||||
return 0;
|
||||
}
|
||||
if (reply->xid != msg->xid) {
|
||||
if (verbose) ALOGD("netcfg: Wrong Xid 0x%x != 0x%x\n", ntohl(reply->xid),
|
||||
ntohl(msg->xid));
|
||||
if (verbose) ALOGD("dhcp: Wrong Xid 0x%x != 0x%x\n", ntohl(reply->xid),
|
||||
ntohl(msg->xid));
|
||||
return 0;
|
||||
}
|
||||
if (reply->htype != msg->htype) {
|
||||
if (verbose) ALOGD("netcfg: Wrong Htype %d != %d\n", reply->htype, msg->htype);
|
||||
if (verbose) ALOGD("dhcp: Wrong Htype %d != %d\n", reply->htype, msg->htype);
|
||||
return 0;
|
||||
}
|
||||
if (reply->hlen != msg->hlen) {
|
||||
if (verbose) ALOGD("netcfg: Wrong Hlen %d != %d\n", reply->hlen, msg->hlen);
|
||||
if (verbose) ALOGD("dhcp: Wrong Hlen %d != %d\n", reply->hlen, msg->hlen);
|
||||
return 0;
|
||||
}
|
||||
if (memcmp(msg->chaddr, reply->chaddr, msg->hlen)) {
|
||||
if (verbose) ALOGD("netcfg: Wrong chaddr %x != %x\n", *(reply->chaddr),*(msg->chaddr));
|
||||
if (verbose) ALOGD("dhcp: Wrong chaddr %x != %x\n", *(reply->chaddr),*(msg->chaddr));
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
|
|
|
@ -639,26 +639,6 @@ int ifc_reset_connections(const char *ifname, const int reset_mask)
|
|||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Removes the default route for the named interface.
|
||||
*/
|
||||
int ifc_remove_default_route(const char *ifname)
|
||||
{
|
||||
struct rtentry rt;
|
||||
int result;
|
||||
|
||||
ifc_init();
|
||||
memset(&rt, 0, sizeof(rt));
|
||||
rt.rt_dev = (void *)ifname;
|
||||
rt.rt_flags = RTF_UP|RTF_GATEWAY;
|
||||
init_sockaddr_in(&rt.rt_dst, 0);
|
||||
if ((result = ioctl(ifc_ctl_sock, SIOCDELRT, &rt)) < 0) {
|
||||
ALOGD("failed to remove default route for %s: %s", ifname, strerror(errno));
|
||||
}
|
||||
ifc_close();
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
ifc_configure(const char *ifname,
|
||||
in_addr_t address,
|
||||
|
|
105
netcfg/netcfg.c
105
netcfg/netcfg.c
|
@ -24,13 +24,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void die(const char *reason)
|
||||
{
|
||||
perror(reason);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
const char *ipaddr(in_addr_t addr)
|
||||
static const char *ipaddr(in_addr_t addr)
|
||||
{
|
||||
struct in_addr in_addr;
|
||||
|
||||
|
@ -38,13 +32,13 @@ const char *ipaddr(in_addr_t addr)
|
|||
return inet_ntoa(in_addr);
|
||||
}
|
||||
|
||||
void usage(void)
|
||||
static void usage(void)
|
||||
{
|
||||
fprintf(stderr,"usage: netcfg [<interface> {dhcp|up|down}]\n");
|
||||
fprintf(stderr,"usage: netcfg [<interface> dhcp]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int dump_interface(const char *name)
|
||||
static int dump_interface(const char *name)
|
||||
{
|
||||
unsigned addr, flags;
|
||||
unsigned char hwbuf[ETH_ALEN];
|
||||
|
@ -69,7 +63,7 @@ int dump_interface(const char *name)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int dump_interfaces(void)
|
||||
static int dump_interfaces(void)
|
||||
{
|
||||
DIR *d;
|
||||
struct dirent *de;
|
||||
|
@ -85,56 +79,11 @@ int dump_interfaces(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int set_hwaddr(const char *name, const char *asc) {
|
||||
struct ether_addr *addr = ether_aton(asc);
|
||||
if (!addr) {
|
||||
printf("Failed to parse '%s'\n", asc);
|
||||
return -1;
|
||||
}
|
||||
return ifc_set_hwaddr(name, addr->ether_addr_octet);
|
||||
}
|
||||
|
||||
struct
|
||||
{
|
||||
const char *name;
|
||||
int nargs;
|
||||
void *func;
|
||||
} CMDS[] = {
|
||||
{ "dhcp", 1, do_dhcp },
|
||||
{ "up", 1, ifc_up },
|
||||
{ "down", 1, ifc_down },
|
||||
{ "deldefault", 1, ifc_remove_default_route },
|
||||
{ "hwaddr", 2, set_hwaddr },
|
||||
{ 0, 0, 0 },
|
||||
};
|
||||
|
||||
static int call_func(void *_func, unsigned nargs, char **args)
|
||||
{
|
||||
switch(nargs){
|
||||
case 1: {
|
||||
int (*func)(char *a0) = _func;
|
||||
return func(args[0]);
|
||||
}
|
||||
case 2: {
|
||||
int (*func)(char *a0, char *a1) = _func;
|
||||
return func(args[0], args[1]);
|
||||
}
|
||||
case 3: {
|
||||
int (*func)(char *a0, char *a1, char *a2) = _func;
|
||||
return func(args[0], args[1], args[2]);
|
||||
}
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *iname;
|
||||
int n;
|
||||
|
||||
if(ifc_init()) {
|
||||
die("Cannot perform requested operation");
|
||||
perror("Cannot perform requested operation");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if(argc == 1) {
|
||||
|
@ -143,41 +92,23 @@ int main(int argc, char **argv)
|
|||
return result;
|
||||
}
|
||||
|
||||
if(argc < 3) usage();
|
||||
if(argc != 3) usage();
|
||||
|
||||
iname = argv[1];
|
||||
char* iname = argv[1];
|
||||
char* action = argv[2];
|
||||
if(strlen(iname) > 16) usage();
|
||||
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
while(argc > 0) {
|
||||
for(n = 0; CMDS[n].name; n++){
|
||||
if(!strcmp(argv[0], CMDS[n].name)) {
|
||||
char *cmdname = argv[0];
|
||||
int nargs = CMDS[n].nargs;
|
||||
|
||||
argv[0] = iname;
|
||||
if(argc < nargs) {
|
||||
fprintf(stderr, "not enough arguments for '%s'\n", cmdname);
|
||||
ifc_close();
|
||||
exit(1);
|
||||
}
|
||||
if(call_func(CMDS[n].func, nargs, argv)) {
|
||||
fprintf(stderr, "action '%s' failed (%s)\n", cmdname, strerror(errno));
|
||||
ifc_close();
|
||||
exit(1);
|
||||
}
|
||||
argc -= nargs;
|
||||
argv += nargs;
|
||||
goto done;
|
||||
}
|
||||
if (!strcmp(action, "dhcp")) {
|
||||
if (do_dhcp(iname)) {
|
||||
fprintf(stderr, "dhcp failed: %s\n", strerror(errno));
|
||||
ifc_close();
|
||||
exit(1);
|
||||
}
|
||||
fprintf(stderr,"no such action '%s'\n", argv[0]);
|
||||
} else {
|
||||
fprintf(stderr,"no such action '%s'\n", action);
|
||||
usage();
|
||||
done:
|
||||
;
|
||||
}
|
||||
ifc_close();
|
||||
|
||||
ifc_close();
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue