예제 #1
0
int main(int argc, char **argv)
{
    char *iname;
    int n;
    
    if(ifc_init()) {
        die("Cannot perform requested operation");
    }

    if(argc == 1) {
        int result = dump_interfaces();
        ifc_close();
        return result;
    }

    if(argc < 3) usage();

    iname = argv[1];
    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;
            }
        }
        fprintf(stderr,"no such action '%s'\n", argv[0]);
        usage();
    done:
        ;
    }
    ifc_close();

    return 0;
}
예제 #2
0
파일: lispd.c 프로젝트: LISPmob/lispdroid
void dump_info_file(void) {
    FILE *fp;
    char addr_buf[128];
    lispd_map_server_list_t *ms = NULL;
    lispd_addr_list_t *mr = NULL;
    int plural = FALSE;

    fp = fopen(LISPD_INFOFILE, "w+");

    if (!fp) {
        log_msg(WARNING, "Could not write lispd info file to %s", LISPD_INFOFILE);
        return;
    }

    fprintf(fp, "Version:         %d.%d.%d\n", MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION);
    fprintf(fp, "Device EID(s):   ");
    if (lispd_config.eid_address_v4.afi) {
        fprintf(fp, "%s\n", inet_ntop(AF_INET,
                                      &lispd_config.eid_address_v4.address,
                                      addr_buf, 128));
    }
    if (lispd_config.eid_address_v6.afi) {
        fprintf(fp, "                 %s\n", inet_ntop(AF_INET6,
                                                       lispd_config.eid_address_v6.address.ipv6.s6_addr,
                                                       addr_buf, 128));
    }

    if (lispd_config.use_instance_id) {
        fprintf(fp, "Instance ID:     %d\n", lispd_config.instance_id);
    }
    fprintf(fp, "Map Server(s):   ");
    ms = lispd_config.map_servers;
    while (ms)
    {
        if (plural) {
            fprintf(fp, ",\n                 ");
        }
        fprintf(fp, "%s", inet_ntop(ms->address->afi,
                                    &ms->address->address,
                                    addr_buf, 128));
        plural = TRUE;
        ms = ms->next;
    }
    fprintf(fp, "\n");

    plural = FALSE;
    fprintf(fp, "Map Resolver(s): ");
    mr = lispd_config.map_resolvers;
    while (mr) {

        if (plural) {
            fprintf(fp, ",\n                 ");
        }
        fprintf(fp, "%s", inet_ntop(mr->address->afi,
                                    &mr->address->address,
                                    addr_buf, 128));
        plural = TRUE;
        mr = mr->next;
    }
    fprintf(fp, "\n");
    fprintf(fp, "Configured Interface(s):\n");
    dump_interfaces(fp);

    fprintf(fp, "Locator(s):\n");
    dump_database(AF4_database, AF_INET, fp);
    dump_database(AF6_database, AF_INET6, fp);

    if (lispd_config.use_dns_override) {
        fprintf(fp, "LISP DNS Resolver: %s", inet_ntop(AF_INET, &lispd_config.dns_override_address1.address,
                                                       addr_buf, 128));

        if (lispd_config.dns_override_address2.address.ip.s_addr != 0) {
            fprintf(fp, "\nLISP Second DNS Resolver: %s", inet_ntop(AF_INET, &lispd_config.dns_override_address2.address,
                                                                    addr_buf, 128));
        }
    }
    fclose(fp);
}