예제 #1
0
파일: main.cpp 프로젝트: kekyo/PlayPcmWin
int
main(int argc, char *argv[])
{
    WWPcmData *pcmData = NULL;
    int deviceId = -1;
    int latencyInMillisec = LATENCY_MILLISEC_DEFAULT;
    char *filePath = 0;
    WWBitsPerSampleType bitsPerSampleType = WWBpsNone;

    if (argc != 3 && argc != 4 && argc != 6) {
        PrintUsage();
        PrintDeviceList();
        return 0;
    }

    if (0 != strcmp("-d", argv[1])) {
        PrintUsage();
        return 1;
    }
    deviceId = atoi(argv[2]);

    if (argc == 3) {
        Test(deviceId);
        return 0;
    }

    if (argc == 6) {
        if (0 != strcmp("-l", argv[3])) {
            PrintUsage();
            return 1;
        }
        latencyInMillisec = atoi(argv[4]);
    }

    bitsPerSampleType = InspectDeviceBitsPerSample(deviceId);

    filePath = argv[argc-1];
    pcmData = WWReadWavFile(filePath);
    if (NULL == pcmData) {
        pcmData = WWReadDsfFile(filePath, bitsPerSampleType);
        if (NULL == pcmData) {
            pcmData = WWReadDsdiffFile(filePath, bitsPerSampleType);
            if (NULL == pcmData) {
                printf("E: read file failed %s\n", argv[3]);
                return 1;
            }
        }
    }

    HRESULT hr = Run(deviceId, latencyInMillisec, *pcmData);
    if (FAILED(hr)) {
        printf("E: Run failed (%08x)\n", hr);
    }

    if (NULL != pcmData) {
        pcmData->Term();
        delete pcmData;
        pcmData = NULL;
    }

#ifdef _DEBUG
    _CrtDumpMemoryLeaks();
#endif
    return 0;
}
예제 #2
0
파일: nemesis-ip.c 프로젝트: Inphi/nemesis
static void ip_cmdline(int argc, char **argv)
{
    int opt, i;
    u_int32_t addr_tmp[6];
    char *ip_options;
    extern char *optarg;
    extern int optind;

#if defined(ENABLE_PCAPOUTPUT)
  #if defined(WIN32)
    ip_options = "d:D:F:H:I:M:O:p:P:S:t:T:vWZ?";
  #else
    ip_options = "d:D:F:H:I:M:O:p:P:S:t:T:vW?";
  #endif
#else
  #if defined(WIN32)
    ip_options = "d:D:F:H:I:M:O:p:P:S:t:T:vZ?";
  #else
    ip_options = "d:D:F:H:I:M:O:p:P:S:t:T:v?";
  #endif
#endif

    while ((opt = getopt(argc, argv, ip_options)) != -1)
    {
        switch (opt)
        {
            case 'd':    /* Ethernet device */
#if defined(WIN32)
                if (nemesis_getdev(atoi(optarg), &device) < 0)
                {
                    fprintf(stderr, "ERROR: Unable to lookup device: '%d'.\n", 
                            atoi(optarg));
                    ip_exit(1);
                }
#else
                if (strlen(optarg) < 256)
                {
                    device = strdup(optarg);
                    got_link = 1;
                }
                else
                {
                    fprintf(stderr, "ERROR: device %s > 256 characters\n",
                            optarg);
                    ip_exit(1);
                }
#endif
                break;
            case 'D':    /* destination IP address */
                if ((nemesis_name_resolve(optarg, 
                        (u_int32_t *)&iphdr.ip_dst.s_addr )) < 0)
                {
                    fprintf(stderr, "ERROR: Invalid destination IP address: "
                            "\"%s\".\n", optarg);
                    ip_exit(1);
                }
                break;
            case 'F':    /* IP fragmentation options */
                if (parsefragoptions(&iphdr, optarg) < 0)
                    ip_exit(1);
                break;
            case 'H':    /* Ethernet source address */
                memset(addr_tmp, 0, sizeof(addr_tmp));
                sscanf(optarg, "%02X:%02X:%02X:%02X:%02X:%02X", &addr_tmp[0],
                        &addr_tmp[1], &addr_tmp[2], &addr_tmp[3], &addr_tmp[4],
                        &addr_tmp[5]);
                for (i = 0; i < 6; i++)
                    etherhdr.ether_shost[i] = (u_int8_t)addr_tmp[i];
                break;
            case 'I':   /* IP ID */
                iphdr.ip_id = xgetint16(optarg);
                break;
            case 'M':    /* Ethernet destination address */
                memset(addr_tmp, 0, sizeof(addr_tmp));
                sscanf(optarg, "%02X:%02X:%02X:%02X:%02X:%02X", &addr_tmp[0],
                        &addr_tmp[1], &addr_tmp[2], &addr_tmp[3], &addr_tmp[4],
                        &addr_tmp[5]);
                for (i = 0; i < 6; i++)
                    etherhdr.ether_dhost[i] = (u_int8_t)addr_tmp[i];
                break;
            case 'O':   /* IP options file */
                if (strlen(optarg) < 256)
                {
                    ipoptionsfile = strdup(optarg);
                    got_ipoptions = 1;
                }
                else
                {
                    fprintf(stderr, "ERROR: IP options file %s > 256 "
                            "characters.\n", optarg);
                    ip_exit(1);
                }
                break;
            case 'p':   /* IP protocol */
                iphdr.ip_p = xgetint8(optarg);
                break;
            case 'P':   /* payload file */
                if (strlen(optarg) < 256)
                {
                    payloadfile = strdup(optarg);
                    got_payload = 1;
                }
                else
                {
                    fprintf(stderr, "ERROR: payload file %s > 256 characters\n",
                            optarg);
                    ip_exit(1);
                }
                break;
            case 'S':    /* source IP address */
                if ((nemesis_name_resolve(optarg, 
                        (u_int32_t *)&iphdr.ip_src.s_addr )) < 0)
                {
                    fprintf(stderr, "ERROR: Invalid source IP address: \"%s\"."
                            "\n", optarg);
                    ip_exit(1);
                }
                break;
            case 't':   /* IP type of service */
                iphdr.ip_tos = xgetint8(optarg);
                break;
            case 'T':   /* IP time to live */
                iphdr.ip_ttl = xgetint8(optarg);
                break;
            case 'v':
                verbose++;
                if (verbose == 1)
                    nemesis_printtitle((const char *)title);
                break;
#if defined(WIN32)
            case 'Z':
                if ((ifacetmp = pcap_lookupdev(errbuf)) == NULL)
                    perror(errbuf);

                PrintDeviceList(ifacetmp);
                ip_exit(1);
#endif
            case '?':    /* FALLTHROUGH */
            default:
                ip_usage(argv[0]);
                break;
        }    
    }
    argc -= optind;
    argv += optind;
    return;
}