Esempio n. 1
0
int main(int argc, char **argv)
{
    MSocket *sock;
    Abstract *dnslookup;
    char google[] = "www.google.com";

    quitting = 0;
    signal(SIGINT, cntrlc_hdlr);

    fprintf(stdout, "libmsocket example code: libmsocket version %s\n", lms_version());

    if (lms_init(1) < 0) {
        return(1);
    }

    sock = lms_socket_create(LMSTYPE_STREAM4);
    if (!sock) {
        fprintf(stdout, "lms_socket_create(): %s\n", strerror(errno));
        return(1);
    }
    if (!sock->remotedns)
    {
        /* remotedns begins life as a null pointer - no sense allocating the memory if it isn't necessary, but since we're doing a DNS callback, it will be necessary. */
        sock->remotedns = (char *)malloc(256);
        if (!sock->remotedns) {
            fprintf(stdout, "malloc(sock->remotedns): %s\n", strerror(errno));
            return(1);
        }
        memset(sock->remotedns, 0, 256);
    }
    strncpy(sock->remotedns, google, LMS_LEN_V4ADDR);
    sock->remoteport = 80;
    sock->opts |= LMSOPTION_CWAIT;

    dnslookup = (Abstract *)malloc(sizeof(Abstract));
    if (!dnslookup) {
        fprintf(stdout, "malloc(dnslookup): %s\n", strerror(errno));
        return(1);
    }
    memset(dnslookup, 0, sizeof(Abstract));
    dnslookup->what = ABSTRACT_CALLBACK;
    dnslookup->where = sock;
    dnslookup->how = dnscallback;

    lms_dns_lookup(google, dnslookup);

    while (!quitting)
    {
        lms_loop();
    }

    fputc('\n', stdout);
    fflush(stdout);
    return(0);
}
Esempio n. 2
0
int main()
{
  lms_init();
  lms_main();
  return ( lms_return() );
}
Esempio n. 3
0
int main(int argc, char **argv) 
{
	FILE *noisyfp, *coeffp, *resultfp;
	int i; int skip = 0x2C;
	unsigned int filesize = 0;
	lms_t *target;

	if (argc < 2) {
		fprintf(stderr, "Usage: %s <noisy file> <coeff filename> <result file>\n", 
				 argv[0]);
		exit(1);
	}

	if ((noisyfp = fopen(argv[1], "r")) == NULL) {
		fprintf(stderr, "Can't open %s", argv[1]);
		exit(1);
	}

	if ((coeffp = fopen(argv[2], "r")) == NULL) {
		fprintf(stderr, "Can't open %s", argv[2]);
		exit(1);
	}

	if ((resultfp = fopen(argv[3], "wb+")) == NULL) {
		fprintf(stderr, "Can't open %s", argv[3]);
		exit(1);
	}

	if (identify_wav(noisyfp)) {
		skip = 0x50;
		float_init_wav(resultfp);
		printf("Is float\n");
	} else {
		int_init_wav(resultfp, 0);
		printf("Is int\n");
	}

	/* cut to the cheese */
	fseek(noisyfp, skip, SEEK_SET);

	target = lms_init(TAPSIZE, BUFSIZE, MU);

	target->ready = true;
	lms_complete(target);

	i = 0;
	double x;
	while(!feof(coeffp) && i < TAPSIZE) {
		fscanf(coeffp, "%lf\n", &x);
	//	printf("%.20g\n", x);
		target->h[i] = x;
		i++;
	}

	double d, b;
	while(!feof(noisyfp)) {
		fread(&d, sizeof(double), 1, noisyfp);	
		b = lms_run(target, d);
		filesize += fwrite(&b, 1, sizeof(double), resultfp);
	}

	if (skip == 0x50) {
		printf("Finalize float\n");
		float_finalize_wav(resultfp, filesize);
	} else {
		printf("Finalize int\n");
		int_finalize_wav(resultfp, filesize);
	}

	fclose(noisyfp); 
	fclose(coeffp); 
	fclose(resultfp);
}