if (ADDR_IS_MULTICAST(rcvr_addr.s_addr)) { if (prog_type == sender) {
ret = setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)); if (ret < 0) {
fprintf(stderr, "%s: Failed to set TTL for multicast group",
argv[0]);
perror(""); exit(1);
}
}
/* *readkeyfromhexadecimalorbase64oncommandlineintoanoctet *string
*/ if (b64_input) { int pad;
expected_len = (policy.rtp.cipher_key_len * 4) / 3;
len = base64_string_to_octet_string(key, &pad, input_key,
expected_len); if (pad != 0) {
fprintf(stderr, "error: padding in base64 unexpected\n"); exit(1);
}
} else {
expected_len = policy.rtp.cipher_key_len * 2;
len = hex_string_to_octet_string(key, input_key, expected_len);
} /* check that hex string is the right length */ if (len < expected_len) {
fprintf(stderr, "error: too few digits in key/salt " "(should be %d digits, found %d)\n",
expected_len, len); exit(1);
} if ((int)strlen(input_key) > policy.rtp.cipher_key_len * 2) {
fprintf(stderr, "error: too many digits in key/salt " "(should be %d hexadecimal digits, found %u)\n",
policy.rtp.cipher_key_len * 2, (unsigned)strlen(input_key)); exit(1);
}
if (prog_type == sender) { #if BEW /* bind to local socket (to match crypto policy, if need be) */
memset(&local, 0, sizeof(struct sockaddr_in));
local.sin_addr.s_addr = htonl(INADDR_ANY);
local.sin_port = htons(port);
ret = bind(sock, (struct sockaddr *)&local, sizeof(struct sockaddr_in)); if (ret < 0) {
fprintf(stderr, "%s: bind failed\n", argv[0]);
perror(""); exit(1);
} #endif/* BEW */
/* initialize sender's rtp and srtp contexts */
snd = rtp_sender_alloc(); if (snd == NULL) {
fprintf(stderr, "error: malloc() failed\n"); exit(1);
}
rtp_sender_init(snd, sock, name, ssrc);
status = rtp_sender_init_srtp(snd, &policy); if (status) {
fprintf(stderr, "error: srtp_create() failed with code %d\n",
status); exit(1);
}
/* open dictionary */
dict = fopen(dictfile, "r"); if (dict == NULL) {
fprintf(stderr, "%s: couldn't open file %s\n", argv[0], dictfile); if (ADDR_IS_MULTICAST(rcvr_addr.s_addr)) {
leave_group(sock, mreq, argv[0]);
} exit(1);
}
/* read words from dictionary, then send them off */ while (!interrupted && fgets(word, MAX_WORD_LEN, dict) != NULL) {
len = strlen(word) + 1; /* plus one for null */
if (len > MAX_WORD_LEN)
printf("error: word %s too large to send\n", word); else {
rtp_sendto(snd, word, len);
printf("sending word: %s", word);
}
usleep(USEC_RATE);
}
if (ADDR_IS_MULTICAST(rcvr_addr.s_addr)) {
leave_group(sock, mreq, argv[0]);
}
#ifdef RTPW_USE_WINSOCK2
ret = closesocket(sock); #else
ret = close(sock); #endif if (ret < 0) {
fprintf(stderr, "%s: Failed to close socket", argv[0]);
perror("");
}
status = srtp_shutdown(); if (status) {
printf("error: srtp shutdown failed with error code %d\n", status); exit(1);
}
#ifdef RTPW_USE_WINSOCK2
WSACleanup(); #endif
return0;
}
void usage(char *string)
{
printf("usage: %s [-d <debug>]* [-k <key> [-a][-e]] " "[-s | -r] dest_ip dest_port\n" "or %s -l\n" "where -a use message authentication\n" " -e <key size> use encryption (use 128 or 256 for key size)\n" " -g Use AES-GCM mode (must be used with -e)\n" " -t <tag size> Tag size to use in GCM mode (use 8 or 16)\n" " -k <key> sets the srtp master key given in hexadecimal\n" " -b <key> sets the srtp master key given in base64\n" " -s act as rtp sender\n" " -r act as rtp receiver\n" " -l list debug modules\n" " -d <debug> turn on debugging for module <debug>\n" " -w <wordsfile> use <wordsfile> for input, rather than %s\n",
string, string, DICT_FILE); exit(1);
}
ret = setsockopt(sock, IPPROTO_IP, IP_DROP_MEMBERSHIP, (void *)&mreq, sizeof(mreq)); if (ret < 0) {
fprintf(stderr, "%s: Failed to leave multicast group", name);
perror("");
}
}
void handle_signal(int signum)
{
interrupted = 1; /* Reset handler explicitly, in case we don't have sigaction() (and signal()
has BSD semantics), or we don't have SA_RESETHAND */
signal(signum, SIG_DFL);
}
act.sa_handler = handle_signal;
sigemptyset(&act.sa_mask); #ifdefined(SA_RESETHAND)
act.sa_flags = SA_RESETHAND; #else
act.sa_flags = 0; #endif /* Note that we're not setting SA_RESTART; we want recvfrom to return
* EINTR when we signal the receiver. */
if (sigaction(SIGTERM, &act, NULL) != 0) {
fprintf(stderr, "%s: error setting up signal handler", name);
perror(""); return -1;
} #else if (signal(SIGTERM, handle_signal) == SIG_ERR) {
fprintf(stderr, "%s: error setting up signal handler", name);
perror(""); return -1;
} #endif return0;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.