Exemplo n.º 1
0
int ping6_main(int argc, char **argv)
{
	char *opt_c, *opt_s, *opt_I;

	datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */

	/* exactly one argument needed, -v and -q don't mix */
	opt_complementary = "=1:q--v:v--q";
	getopt32(argc, argv, OPT_STRING, &opt_c, &opt_s, &opt_I);
	if (option_mask32 & 4) pingcount = xatoul(opt_c); // -c
	if (option_mask32 & 8) datalen = xatou16(opt_s); // -s
	if (option_mask32 & 0x10) { // -I
		if_index = if_nametoindex(opt_I);
		if (!if_index)
			bb_error_msg_and_die(
				"%s: invalid interface name", opt_I);
	}

	myid = (int16_t)getpid();
	ping(argv[optind]);
	return EXIT_SUCCESS;
}
Exemplo n.º 2
0
static void parse_map_file(const char *filename)
{
	parser_t *parser;
	char *tokens[6];

	parser = config_open2(filename, fopen_for_read);

	if (parser) {
		while (config_read(parser, tokens, 6, 6, "# \t", PARSE_NORMAL)) {
			evt_tab = xrealloc_vector(evt_tab, 1, n_evt);
			evt_tab[n_evt].s_type = xstrdup(tokens[0]);
			evt_tab[n_evt].n_type = xstrtou(tokens[1], 16);
			evt_tab[n_evt].s_code = xstrdup(tokens[2]);
			evt_tab[n_evt].n_code = xatou16(tokens[3]);
			evt_tab[n_evt].value = xatoi_positive(tokens[4]);
			evt_tab[n_evt].desc = xstrdup(tokens[5]);
			n_evt++;
		}
		config_close(parser);
	} else {
		evt_tab = (void*)f_evt_tab;
		n_evt = ARRAY_SIZE(f_evt_tab);
	}
}
Exemplo n.º 3
0
static len_and_sockaddr *str2sockaddr(const char *host, int port, int ai_flags)
{
    int rc;
    len_and_sockaddr *r = NULL;
    struct addrinfo *result = NULL;
    const char *org_host = host; /* only for error msg */
    const char *cp;
    struct addrinfo hint;
    
    
    /* Ugly parsing of host:addr */
    if (ENABLE_FEATURE_IPV6 && host[0] == '[') {
        host++;
        cp = strchr(host, ']');
        if (!cp || cp[1] != ':') { /* Malformed: must have [xx]:nn */
            //bb_error_msg_and_die("bad address '%s'", org_host);
            printf("bad address '%s'", org_host);
            exit (-1);
        }
        //return r; /* return NULL */
    } else {
        cp = strrchr(host, ':');
        if (ENABLE_FEATURE_IPV6 && cp && strchr(host, ':') != cp) {
            /* There is more than one ':' (e.g. "::1") */
            cp = NULL; /* it's not a port spec */
        }
    }

    if (cp) {
        int sz = cp - host + 1;
        host = safe_strncpy(alloca(sz), host, sz);
        if (ENABLE_FEATURE_IPV6 && *cp != ':')
            cp++; /* skip ']' */
        cp++; /* skip ':' */
        port = xatou16(cp);
    }
    memset(&hint, 0 , sizeof(hint));
    
    
#if !ENABLE_FEATURE_IPV6
    hint.ai_family = AF_INET; /* do not try to find IPv6 */
#else
    hint.ai_family = af;
#endif
    /* Needed. Or else we will get each address thrice (or more) for each possible socket type (tcp,udp,raw...): */
    hint.ai_socktype = SOCK_STREAM;
    hint.ai_flags = ai_flags & ~DIE_ON_ERROR;
    rc = getaddrinfo(host, NULL, &hint, &result);
    if (rc || !result) {
        //bb_error_msg("bad address '%s'", org_host);
        printf("bad address '%s'", org_host);
        if (ai_flags & DIE_ON_ERROR)
            exit(-1);
        goto ret;
    }
    
    
    r = xmalloc(offsetof(len_and_sockaddr, sa) + result->ai_addrlen);
    r->len = result->ai_addrlen;
    memcpy(&r->sa, result->ai_addr, result->ai_addrlen);
    set_nport(r, htons(port));
    
    
ret:
    freeaddrinfo(result);
    return r;
}