const char *
link_get_local_hostname (void)
{
	static char local_host[NI_MAXHOST] = { 0 };

	if (local_host[0])
		return local_host;

	get_netid(use_local_host, local_host, NI_MAXHOST);

	return local_host;
}
Esempio n. 2
0
int argt_func(int argc, char **argv)
{
    int opt, ret = 1;

    struct option longopts[] = {
        { "help",           0, NULL, 'h' }, //1
        { "version",        0, NULL, 'v' }, //2
        { "save",           0, NULL, 's' }, //3
        { "read",           0, NULL, 'r' }, //4
        { "show",           0, NULL, 'c' }, //5
        { "selist",         0, NULL, 'l' }, //6
        { "loglevel",       1, NULL, 'L' }, //7
        { "id",             1, NULL, 'N' }, //8
        { "addr",           1, NULL, 'A' }, //9
        { "rip",            1, NULL, 'I' }, //10
        { "rport",          1, NULL, 'P' }, //11
        { 0, 0, 0, 0 },
    };

    cfg.rf433.net_id        = RF433_CFG_NET_ID;
    cfg.rf433.local_addr    = RF433_CFG_LOCAL_ADDR;
    cfg.rf433.m_mask        = 0;

    cfg.socket.server_ip.s_addr = inet_addr(RF433_CFG_SRV_IP);
    cfg.socket.server_port  = RF433_CFG_UDP_PORT;
    cfg.socket.m_mask       = 0;

    se433_set.se433_addr    = 0;
    se433_set.op            = 0;

    if (argc <= 1) {
        printf(USAGE);
        ret = 0;
        goto err;
    }

    while ((opt = getopt_long(argc, argv, "hvsrclL:N:A:I:P:", longopts, NULL)) != -1) {
        switch (opt) {
            case 's':                   // save
                opt_id = MSG_REQ_SAVE_CFG;
                break;

            case 'r':                   // read
                opt_id = MSG_REQ_READ_CFG;
                break;

            case 'c':                   // show
                opt_id = MSG_REQ_GET_CFG;
                break;

            case 'l':                   // se433 list
                opt_id = MSG_REQ_GET_SE433L;
                break;

            case 'L':                   // loglevel
                if ((get_log_level(optarg, &log_level)) == -1) {
                    fprintf(stderr, "\n invalid value (%s)\n\n", optarg);
                    ret = -1;
                    goto err;
                }
                opt_id = MSG_REQ_SET_LOG;
                break;

            case 'N':                   // netid
                if ((get_netid(optarg, &cfg.rf433.net_id)) == -1) {
                    fprintf(stderr, "\n invalid value (%s)\n\n", optarg);
                    ret = -1;
                    goto err;
                }
                cfg.rf433.m_mask |= RF433_MASK_NET_ID;
                opt_id = MSG_REQ_SET_CFG;
                break;

            case 'A':                   // addr
                if ((get_local_addr(optarg, &cfg.rf433.local_addr)) == -1) {
                    fprintf(stderr, "\n invalid value (%s)\n\n", optarg);
                    ret = -1;
                    goto err;
                }
                cfg.rf433.m_mask |= RF433_MASK_RCV_ADDR;
                opt_id = MSG_REQ_SET_CFG;
                break;
#if 0
            case 'E':                   // seadd
                if ((get_se433_addr(optarg, &se433_set.se433_addr)) == -1) {
                    fprintf(stderr, "\n invalid value (%s)\n\n", optarg);
                    ret = -1;
                    goto err;
                }
                se433_set.op = SE433_OP_ADD;
                break;

            case 'D':                   // sedel
                if ((get_se433_addr(optarg, &se433_set.se433_addr)) == -1) {
                    fprintf(stderr, "\n invalid value (%s)\n\n", optarg);
                    ret = -1;
                    goto err;
                }
                se433_set.op = SE433_OP_DEL;
                break;
#endif
            case 'I':                   // rip
                if ((get_ip(optarg, &cfg.socket.server_ip)) == -1) {
                    fprintf(stderr, "\n invalid value (%s)\n\n", optarg);
                    ret = -1;
                    goto err;
                }
                cfg.socket.m_mask |= SOCK_MASK_SER_IP;
                opt_id = MSG_REQ_SET_CFG;
                break;

            case 'P':                   // rport
                if ((get_port(optarg, &cfg.socket.server_port)) == -1) {
                    fprintf(stderr, "\n invalid value (%s)\n\n", optarg);
                    ret = -1;
                    goto err;
                }
                cfg.socket.m_mask |= SOCK_MASK_UDP_PORT;
                opt_id = MSG_REQ_SET_CFG;
                break;

            case 'h':
            case 'v':
                printf(USAGE);
                ret = 0;
                goto err;
                break;

            default:
                fprintf(stderr, "%s: invalid opt (%c)\n\n", argv[0], opt);
                printf(USAGE);
                ret = 0;
                goto err;
                break;
        }
    }

err:
    return ret;
}