IP_PUBLIC int
ipcom_cmd_smptest(int argc, char **argv)
{
    Ipcom_getopt         opt;
    int                  c;
    struct Ip_addrinfo   hints;
    struct Ip_addrinfo  *res;
    char                *hostname = "0.0.0.0";
    char                *servname = "8484";
    int                  socktype = IP_SOCK_STREAM;
    int                  domain = IP_AF_INET;
    Ipcom_cmd_smptest_t  smp_opt;

    return_client           = 0;
    return_server           = 0;
    verbose                 = 0;
    ipcom_memset(&smp_opt, 0, sizeof(smp_opt));
    smp_opt.server          = 1;
    smp_opt.ip4             = 1;
    smp_opt.tcp             = 1;
    smp_opt.num_bytes       = 1024;
    smp_opt.num_sock        = 1;
    smp_opt.port            = 8484;

    ipcom_getopt_clear_r(&opt);
    while ((c = ipcom_getopt_r(argc, argv, "l:p:s:c6uhv", &opt)) != -1)
    {
        switch(c)
        {
        case 'c':
            smp_opt.server = 0;
            if ( verbose )
                ipcom_printf( "client"IP_LF );
            break;
        case '6':
            smp_opt.ip4 = 0;
            domain = IP_AF_INET6;
            hostname = "::";
            if ( verbose )
                ipcom_printf( "IPv6"IP_LF );
            break;
        case 'u':
            smp_opt.tcp = 0;
            socktype = IP_SOCK_DGRAM;
            if ( verbose )
                ipcom_printf( "UDP"IP_LF );
            break;
        case 'l':
            smp_opt.num_bytes = ipcom_atoi(opt.optarg);
            if ( verbose )
                ipcom_printf( "num bytes: %d"IP_LF, smp_opt.num_bytes );
            break;
        case 'p':
            servname = opt.optarg;
            smp_opt.port = ipcom_atoi(opt.optarg);
            if ( verbose )
                ipcom_printf( "port: %s"IP_LF, servname );
            break;
        case 's':
            smp_opt.num_sock = ipcom_atoi(opt.optarg);
            if ( smp_opt.num_sock > MAX_TASKS )
                smp_opt.num_sock = MAX_TASKS;
            if ( verbose )
                ipcom_printf( "sockets: %d"IP_LF, smp_opt.num_sock );
            break;
        case 'v':
            verbose = 1;
            break;
        case 'h':
            ipcom_cmd_smptest_print_usage();
            return -1;
        default:
            ipcom_printf("smptest: unknown option %c"IP_LF, (char)c);
            ipcom_cmd_smptest_print_usage();
            return -1;
        }
    }

   if (opt.optind < argc)
        hostname = argv[opt.optind];
    else
    {
        if ( 0 == smp_opt.server )
        {
            if ( smp_opt.ip4 )
                hostname = "127.0.0.1";
            else
                hostname = "::1";
           }
    }

    if ( verbose )
        ipcom_printf( "%s : %s"IP_LF, hostname, servname );

    ipcom_memset(&hints, 0, sizeof(hints));
    hints.ai_socktype = socktype;
    hints.ai_flags    = IP_AI_CANONNAME;
    hints.ai_family   = domain;
    if (ipcom_getaddrinfo(hostname, servname, &hints, &res) != 0)
    {
        ipcom_printf("sockperf: getaddrinfo() failed"IP_LF);
        goto cleanup;
    }

    smp_opt.res = res;

    if ( smp_opt.server )
        smp_opt_server = smp_opt;
    else
        smp_opt_client = smp_opt;

    if ( smp_opt.server == 1 )
    {
        if ( 0 != ipcom_cmd_smptest_server() || 0 != return_server )
        {
            ipcom_printf( "Failure."IP_LF );
            goto cleanup;
        }
    }
    else
    {
        if ( 0 != ipcom_cmd_smptest_client() || 0 != return_client )
        {
            ipcom_printf( "Failure"IP_LF );
            goto cleanup;
        }
    }

    ipcom_printf( "Success." );    /* Success */

cleanup:
    ipcom_freeaddrinfo( res );
    return 0;
}
Exemplo n.º 2
0
/*
 *===========================================================================
 *                    ipcom_cmd_ipd
 *===========================================================================
 * Description:
 * Parameters:
 * Returns:
 */
IP_PUBLIC int
ipcom_cmd_ipd(int argc, char **argv)
{
    Ipcom_getopt   opt;
    int            i, c, msgtype;
    Ip_err         err = IPCOM_SUCCESS;
#if IPCOM_VR_MAX > 1
    int            vr = ipcom_proc_vr_get();
    int            vr_new = vr;
#endif

    if (argc < 2)
    {
usage:
        ipcom_fprintf(ip_stderr,
                      "Interpeak daemon (IPD) command, version 1.2"IP_LF
                      "usage:  "IP_LF
                      "   ipd [-V <vr>] list"IP_LF
                      "   ipd [-V <vr>] start <service>"IP_LF
                      "   ipd [-V <vr>] kill <service>"IP_LF
                      "   ipd [-V <vr>] reconfigure <service>"IP_LF
                      "   ipd [-V <vr>] <#> <service>"IP_LF
                      IP_LF);
        return 0;
    }

    ipcom_getopt_clear_r(&opt);
    while ((c = ipcom_getopt_r(argc, argv, "V:", &opt)) != -1)
    {
        switch(c)
        {
        case 'V':
#if IPCOM_VR_MAX > 1
            vr_new = ipcom_atoi(opt.optarg);
#endif
            break;
        default:
            ipcom_printf("ipd: unknown option %c"IP_LF, (char)c);
            return -1;
        }
    }

    if (opt.optind >= argc)
    {
        ipcom_printf("ipd: missing <command> argument"IP_LF);
        goto usage;
    }


    if(ipcom_strcmp(argv[opt.optind], "list") == 0)
    {
#if IPCOM_VR_MAX > 1
        if (vr != vr_new)
            ipcom_proc_vr_set(vr_new);
#endif
        ipcom_printf("Services:"IP_LF);
        for (i = 0; ipcom_ipd_products[i].name != IP_NULL; i++)
        {
            if ((argc - (opt.optind + 1)) > 0)
            {
                int p;
                for (p = opt.optind + 1; p < argc; p++)
                {
                    if (ipcom_strcasecmp(ipcom_ipd_products[i].name, argv[p]) == 0)
                        goto print_service;
                }
                continue;
            }

print_service:
            if (IP_BIT_ISSET(ipcom_ipd_products[i].flags, IPCOM_IPD_FLAG_IPD_START))
            {
#ifdef IP_PORT_OSE5
                if (ipcom_ipd_products[i].start == IP_NULL
                    && ipcom_ipd_isinstalled_ose5(ipcom_ipd_products[i].name) != IPCOM_SUCCESS)
                    continue;
#endif
                err = ipcom_ipd_send(ipcom_ipd_products[i].name, IPCOM_IPD_MSGTYPE_PING);
                ipcom_printf("%-20s %-s"IP_LF,
                             ipcom_ipd_products[i].name,
                             err == IPCOM_SUCCESS ? "started" : "killed");
            }
            else if (ipcom_ipd_products[i].start)
                ipcom_printf("%-20s %-s"IP_LF,
                             ipcom_ipd_products[i].name, "started");

        }
        ipcom_printf(IP_LF);
#if IPCOM_VR_MAX > 1
        if (vr != vr_new)
            ipcom_proc_vr_set(vr);
#endif
        return 0;
    }

    if ((argc - opt.optind) < 2)
    {
        ipcom_printf("ipd: missing <service> argument"IP_LF);
        return -1;
    }

    for (i = 0; ipcom_cmd_ipd_messages[i].name; i++)
        if (ipcom_strcmp(argv[opt.optind], ipcom_cmd_ipd_messages[i].name) == 0)
        {
            msgtype = ipcom_cmd_ipd_messages[i].msgtype;
            goto sendmsg;
        }

    if (*argv[opt.optind] == '-' && ipcom_isdigit(argv[opt.optind][1]))
    {
        /* "UNIX" signal support (using negative numbers) */
        msgtype = -ipcom_atoi(argv[opt.optind] + 1);
        goto sendmsg;
    }

    if (ipcom_isdigit(argv[opt.optind][0]))
    {
        /* positive numbers */
        msgtype = ipcom_atoi(argv[1]);
        goto sendmsg;
    }

    /* unknown command. */
    ipcom_printf ("ipd: unknown command '%s'"IP_LF, argv[opt.optind]);
    return -1;

    /* send msg */
 sendmsg:
#if IPCOM_VR_MAX > 1
    if (vr != vr_new)
        ipcom_proc_vr_set(vr_new);
#endif


    if ((argc - opt.optind) < 3)
        err = ipcom_ipd_send(argv[opt.optind+1], msgtype);
    else
    {
        Ipcom_ipd_msg   *msg;
        int             sz  = ipcom_strlen(argv[opt.optind + 2]) + 1;

        msg = ipcom_calloc(1, sz + sizeof(*msg));
        if (msg != IP_NULL)
        {
            msg->msgtype = msgtype;
            ipcom_memcpy(msg + 1, argv[opt.optind + 2], sz);
            err = ipcom_ipd_sendmsg(argv[opt.optind+1], msg, sz + sizeof(*msg));
            ipcom_free(msg);
        }
    }

    if(err == IPCOM_SUCCESS)
        ipcom_printf("ipd: %s %s ok"IP_LF, argv[opt.optind], argv[opt.optind+1]);
    else
        ipcom_printf("ipd: %s %s failed: %s"IP_LF, argv[opt.optind], argv[opt.optind+1], ipcom_err_string(err));

#if IPCOM_VR_MAX > 1
    if (vr != vr_new)
        ipcom_proc_vr_set(vr);
#endif
    return 0;
}
Exemplo n.º 3
0
/*
 *===========================================================================
 *                    ipcom_cmd_sockperf
 *===========================================================================
 * Description:
 * Parameters:
 * Returns:
 *
 */
IP_PUBLIC int
ipcom_cmd_sockperf(int argc, char **argv)
{
    Ipcom_getopt         opt;
    Ipcom_cmd_sockperf_t cmd;
    int                  c;
    struct Ip_addrinfo   hints;
    char                *hostname = "0.0.0.0";
    char                *servname = "7373";
    int                  socktype = IP_SOCK_STREAM;
    int                  domain = IP_AF_INET;

    if (argc < 2)
    {
        ipcom_cmd_sockperf_print_usage();
        return 0;
    }

    ipcom_memset(&cmd, 0, sizeof(cmd));
    cmd.buf_len         = 8192;
    cmd.num_buf         = 2048;
    cmd.num_sock        = 1;
    cmd.linger.l_onoff  = 1;
    cmd.linger.l_linger = 3;
    cmd.sendbuf_size    = 32767;
    cmd.recvbuf_size    = 16384;

    ipcom_getopt_clear_r(&opt);
    while ((c = ipcom_getopt_r(argc, argv, "6aeL:l:n:Pp:R:rs:T:tu", &opt)) != -1)
    {
        switch(c)
        {
        case '6':
            domain = IP_AF_INET6;
            hostname = "::";
            break;
        case 'a':
            cmd.accept = IP_TRUE;
            break;
        case 'e':
            cmd.echo = IP_TRUE;
            break;
        case 'L':
            cmd.linger.l_linger = ipcom_atoi(opt.optarg);
            break;
        case 'l':
            cmd.buf_len = ipcom_atoi(opt.optarg);
            break;
        case 'n':
            cmd.num_buf = ipcom_atoi(opt.optarg);
            break;
        case 'P':
            cmd.testpattern = IP_TRUE;
            break;
        case 'p':
            servname = opt.optarg;
            break;
        case 'R':
            cmd.recvbuf_size = ipcom_atoi(opt.optarg);
            break;
        case 'r':
            cmd.receive = IP_TRUE;
            break;
        case 's':
            cmd.num_sock = ipcom_atoi(opt.optarg);
            break;
        case 'T':
            cmd.sendbuf_size = ipcom_atoi(opt.optarg);
            break;
        case 't':
            cmd.transmit = IP_TRUE;
            break;
        case 'u':
            socktype = IP_SOCK_DGRAM;
            break;
        default:
            ipcom_printf("sockperf: unknown option %c"IP_LF, (char)c);
            return -1;
        }
    }

    if (cmd.testpattern)
    {
        if (cmd.buf_len & 0x7)
        {
            ipcom_printf("sockperf: the buffert (set with -l) must be a multiple of 8 when "
                         "using a test pattern"IP_LF);
            goto cleanup;
        }

        if (cmd.transmit)
        {
            cmd.send_pattern = ipcom_calloc(cmd.num_sock, sizeof(Ip_u32));
            if (cmd.send_pattern == IP_NULL)
            {
                ipcom_printf("sockperf: out of memory when allocating send pattern"IP_LF);
                goto cleanup;
            }
        }
        if (cmd.receive)
        {
            cmd.recv_pattern = ipcom_calloc(cmd.num_sock, sizeof(Ip_u32));
            if (cmd.recv_pattern == IP_NULL)
            {
                ipcom_printf("sockperf: out of memory when allocating receive pattern"IP_LF);
                goto cleanup;
            }
        }
    }

    if (opt.optind < argc)
        hostname = argv[opt.optind];

    ipcom_memset(&hints, 0, sizeof(hints));
    hints.ai_socktype = socktype;
    hints.ai_flags    = IP_AI_CANONNAME;
    hints.ai_family   = domain;
    if (ipcom_getaddrinfo(hostname, servname, &hints, &cmd.res) != 0)
    {
        ipcom_printf("sockperf: getaddrinfo() failed"IP_LF);
        goto cleanup;
    }

    cmd.buf = ipcom_malloc(cmd.buf_len + 1);
    if (cmd.buf == IP_NULL)
    {
        ipcom_printf("sockperf: Failed to allocate %lu bytes" IP_LF, cmd.buf_len);
        goto cleanup;
    }

    cmd.sock_array = ipcom_malloc(cmd.num_sock * sizeof(int));
    if (cmd.sock_array == IP_NULL)
    {
        ipcom_printf("sockperf: Failed to allocate %lu bytes for sockets" IP_LF,
                     cmd.num_sock * sizeof(int));
        goto cleanup;
    }

    if (cmd.accept)
        ipcom_cmd_sockperf_accept(&cmd);
    else
        ipcom_cmd_sockperf_connect(&cmd);

 cleanup:
    ipcom_free(cmd.send_pattern);
    ipcom_free(cmd.recv_pattern);
    ipcom_free(cmd.sock_array);
    ipcom_free(cmd.buf);
    ipcom_freeaddrinfo(cmd.res);
    return 0;
}