/** Entry point of application. @param argc Number of arguments on command line @param argv Array of strings with arguments from command line @return 0 on success, otherwise >0. */ int main(int argc,char *argv[]) { int mode,operation; char *hostname, *port; char *pname; int port_n; PRFileDesc *fd_socket; int res; pname=basename(argv[0]); atexit(atexit_handler); if (!parse_cli(argc,argv,&operation,&mode,&hostname,&port) || operation==OPERATION_HELP) { show_usage(pname); if (operation!=OPERATION_HELP) return 1; return 0; } if ((port_n=return_port(port))==-1) { fprintf(stderr,"Error. Unknown port number/name %s!\n",port); return 1; } if (!(mode&MODE_NO_SSL)) { if (!init_nss()) return 1; } if (!(fd_socket=create_connected_socket(hostname,port_n,mode))) return 1; res=poll_cycle(fd_socket,mode); if (PR_Close(fd_socket)!=PR_SUCCESS) { print_nspr_error(); return 1; } return (res?0:1); }
int main(int argc, char **argv) { int cfd; SSL_CTX *ctx; SSL *ssl; char buf[4096]; int ret; SSL_library_init(); SSL_load_error_strings(); OPENSSL_no_config(); // cfd = create_connected_socket("localhost", "4242"); cfd = create_connected_socket("::1", "4242"); std::cout << cfd << std::endl; ctx = SSL_CTX_new(SSLv3_client_method()); // if (SSL_CTX_use_certificate_file(ctx, "cert.pem", SSL_FILETYPE_PEM) != 1) { // ERR_print_errors_fp(stderr); // exit(EXIT_FAILURE); // } // if (SSL_CTX_use_PrivateKey_file(ctx, "localhost.key", SSL_FILETYPE_PEM) != 1 ) { // ERR_print_errors_fp(stderr); // exit(EXIT_FAILURE); // } ssl = SSL_new(ctx); if (ssl == NULL) exit(1); ret = SSL_set_fd(ssl, cfd); if (ret != 1) { ERR_print_errors_fp(stderr); std::cout << "SSL_sed_fd : " << SSL_get_error(ssl, ret) << std::endl; } ret = SSL_connect(ssl); if (ret != 1) { ERR_print_errors_fp(stderr); std::cout << "SSL_connect : " << SSL_get_error(ssl, ret) << std::endl; } SSL_write(ssl, "coucou", 6); ret = SSL_read(ssl, buf, 4096); write(1, buf, ret); }
int main(int argc, char ** argv) { mode = program_mode(argv[0]); /* Initialise settings from configuration files. */ dvswitch_read_config(handle_config); /* Parse arguments. */ int opt; while ((opt = getopt_long(argc, argv, "c:h:p:i:t", options, NULL)) != -1) { switch (opt) { case 'c': free(firewire_card); firewire_card = strdup(optarg); break; case 'F': mode = mode_firewire; break; case 'V': mode = mode_v4l2; break; case 'h': free(mixer_host); mixer_host = strdup(optarg); break; case 'p': free(mixer_port); mixer_port = strdup(optarg); break; case 't': do_tally = 1; break; case 'i': { long id = strtoul(optarg, NULL, 10); mixer_id = (id < 255) ? id-1 : 255; } break; case 'H': /* --help */ usage(argv[0]); return 0; default: usage(argv[0]); return 2; } } if (optind != argc) { free(device_name); device_name = strdup(argv[optind++]); } if (!mixer_host || !mixer_port) { fprintf(stderr, "%s: mixer hostname and port not defined\n", argv[0]); return 2; } if (optind != argc) { fprintf(stderr, "%s: excess argument \"%s\"\n", argv[0], argv[optind]); usage(argv[0]); return 2; } if (mode == mode_firewire) { if (device_name) printf("INFO: Reading from Firewire device %s\n", device_name); else if (firewire_card) printf("INFO: Reading from Firewire card %s\n", firewire_card); else printf("INFO: Reading from first Firewire card with camera\n"); } else if (mode == mode_v4l2) { if (!device_name) device_name = "/dev/video"; printf("INFO: Reading from V4L2 device %s\n", device_name); } else { fprintf(stderr, "%s: mode not defined (Firewire or V4L2)\n", argv[0]); return 2; } /* Connect to the mixer, set that as stdout, and run dvgrab. */ printf("INFO: Connecting to %s:%s\n", mixer_host, mixer_port); int sock = create_connected_socket(mixer_host, mixer_port); assert(sock >= 0); /* create_connected_socket() should handle errors */ if (write(sock, do_tally ? GREETING_ACT_SOURCE : GREETING_SOURCE, GREETING_SIZE-1) != GREETING_SIZE-1) { perror("ERROR: write"); exit(1); } if (write(sock, &mixer_id, sizeof(mixer_id)) != sizeof(mixer_id)) { perror("ERROR: write"); exit(1); } if (do_tally) { fflush(NULL); int child_pid = fork(); if (child_pid < 0) { perror("ERROR: fork"); return 1; } if (child_pid == 0) { tally(sock); _exit(0); } } if (dup2(sock, STDOUT_FILENO) < 0) { perror("ERROR: dup2"); return 1; } close(sock); char * dvgrab_argv[7]; char ** argp = dvgrab_argv; *argp++ = "dvgrab"; if (mode == mode_v4l2) *argp++ = "-v4l2"; if (device_name) { *argp++ = "-input"; *argp++ = device_name; } else if (firewire_card) { *argp++ = "-card"; *argp++ = firewire_card; } *argp++ = "-noavc"; *argp++ = "-"; *argp = NULL; assert(argp < dvgrab_argv + sizeof(dvgrab_argv) / sizeof(dvgrab_argv[0])); execvp("dvgrab", dvgrab_argv); perror("ERROR: execvp"); return 1; }