2021-08-10 07:10:33 +00:00
|
|
|
From 0b8d2dfdcca767c833f302b22b36bc09cfb2a74a Mon Sep 17 00:00:00 2001
|
|
|
|
From: Jaroslav Kysela <perex@perex.cz>
|
|
|
|
Date: Fri, 18 Jun 2021 10:11:34 +0200
|
|
|
|
Subject: [PATCH 1/4] alsatplg: fix memory-leak in tplg_construct_object_name()
|
|
|
|
|
|
|
|
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
|
|
|
|
---
|
|
|
|
topology/pre-process-object.c | 2 +-
|
|
|
|
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
|
|
|
|
|
|
diff --git a/topology/pre-process-object.c b/topology/pre-process-object.c
|
|
|
|
index 7565091..ff985e7 100644
|
|
|
|
--- a/topology/pre-process-object.c
|
|
|
|
+++ b/topology/pre-process-object.c
|
|
|
|
@@ -1290,13 +1290,13 @@ static int tplg_construct_object_name(struct tplg_pre_processor *tplg_pp, snd_co
|
|
|
|
|
|
|
|
/* alloc and concat arg value to the name */
|
|
|
|
temp = tplg_snprintf("%s.%s", new_name, arg_value);
|
|
|
|
+ free(arg_value);
|
|
|
|
if (!temp) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
free(new_name);
|
|
|
|
new_name = temp;
|
|
|
|
- free(arg_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = snd_config_set_id(obj, new_name);
|
|
|
|
--
|
|
|
|
2.31.1
|
|
|
|
|
|
|
|
|
|
|
|
From f076518254d08b9329bd50b52264c5b1b2cb5b16 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Jaroslav Kysela <perex@perex.cz>
|
|
|
|
Date: Fri, 18 Jun 2021 10:15:46 +0200
|
|
|
|
Subject: [PATCH 2/4] alsatplg: do not do NULL check for string arrays
|
|
|
|
|
|
|
|
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
|
|
|
|
---
|
|
|
|
topology/pre-process-object.c | 45 ++++++++++++++++-------------------
|
|
|
|
1 file changed, 21 insertions(+), 24 deletions(-)
|
|
|
|
|
|
|
|
diff --git a/topology/pre-process-object.c b/topology/pre-process-object.c
|
|
|
|
index ff985e7..f479aa4 100644
|
|
|
|
--- a/topology/pre-process-object.c
|
|
|
|
+++ b/topology/pre-process-object.c
|
|
|
|
@@ -201,35 +201,32 @@ static int tplg_create_config_template(struct tplg_pre_processor *tplg_pp,
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* add integer configs */
|
|
|
|
- if (items->int_config_ids)
|
|
|
|
- for (i = 0; i < MAX_CONFIGS_IN_TEMPLATE; i++)
|
|
|
|
- if (items->int_config_ids[i]) {
|
|
|
|
- ret = tplg_config_make_add(&child, items->int_config_ids[i],
|
|
|
|
- SND_CONFIG_TYPE_INTEGER, top);
|
|
|
|
- if (ret < 0)
|
|
|
|
- goto err;
|
|
|
|
- }
|
|
|
|
+ for (i = 0; i < MAX_CONFIGS_IN_TEMPLATE; i++)
|
|
|
|
+ if (items->int_config_ids[i]) {
|
|
|
|
+ ret = tplg_config_make_add(&child, items->int_config_ids[i],
|
|
|
|
+ SND_CONFIG_TYPE_INTEGER, top);
|
|
|
|
+ if (ret < 0)
|
|
|
|
+ goto err;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/* add string configs */
|
|
|
|
- if (items->string_config_ids)
|
|
|
|
- for (i = 0; i < MAX_CONFIGS_IN_TEMPLATE; i++)
|
|
|
|
- if (items->string_config_ids[i]) {
|
|
|
|
- ret = tplg_config_make_add(&child, items->string_config_ids[i],
|
|
|
|
- SND_CONFIG_TYPE_STRING, top);
|
|
|
|
- if (ret < 0)
|
|
|
|
- goto err;
|
|
|
|
- }
|
|
|
|
+ for (i = 0; i < MAX_CONFIGS_IN_TEMPLATE; i++)
|
|
|
|
+ if (items->string_config_ids[i]) {
|
|
|
|
+ ret = tplg_config_make_add(&child, items->string_config_ids[i],
|
|
|
|
+ SND_CONFIG_TYPE_STRING, top);
|
|
|
|
+ if (ret < 0)
|
|
|
|
+ goto err;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/* add compound configs */
|
|
|
|
- if (items->compound_config_ids)
|
|
|
|
- for (i = 0; i < MAX_CONFIGS_IN_TEMPLATE; i++) {
|
|
|
|
- if (items->compound_config_ids[i]) {
|
|
|
|
- ret = tplg_config_make_add(&child, items->compound_config_ids[i],
|
|
|
|
- SND_CONFIG_TYPE_COMPOUND, top);
|
|
|
|
- if (ret < 0)
|
|
|
|
- goto err;
|
|
|
|
- }
|
|
|
|
+ for (i = 0; i < MAX_CONFIGS_IN_TEMPLATE; i++) {
|
|
|
|
+ if (items->compound_config_ids[i]) {
|
|
|
|
+ ret = tplg_config_make_add(&child, items->compound_config_ids[i],
|
|
|
|
+ SND_CONFIG_TYPE_COMPOUND, top);
|
|
|
|
+ if (ret < 0)
|
|
|
|
+ goto err;
|
|
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
|
|
err:
|
|
|
|
if (ret < 0) {
|
|
|
|
--
|
|
|
|
2.31.1
|
|
|
|
|
|
|
|
|
|
|
|
From c8e5762750ae47b15d1b7a447529083af2b7fae6 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Jaroslav Kysela <perex@perex.cz>
|
|
|
|
Date: Mon, 9 Aug 2021 18:10:56 +0200
|
|
|
|
Subject: [PATCH 3/4] aseqnet: use getaddrinfo() instead obsolete
|
|
|
|
gethostbyname()
|
|
|
|
|
|
|
|
- modernize code (preparation for IPv6)
|
|
|
|
|
|
|
|
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
|
|
|
|
---
|
|
|
|
seq/aseqnet/aseqnet.c | 133 +++++++++++++++++++++++++++---------------
|
|
|
|
1 file changed, 85 insertions(+), 48 deletions(-)
|
|
|
|
|
|
|
|
diff --git a/seq/aseqnet/aseqnet.c b/seq/aseqnet/aseqnet.c
|
|
|
|
index e756e82..d05f52d 100644
|
|
|
|
--- a/seq/aseqnet/aseqnet.c
|
|
|
|
+++ b/seq/aseqnet/aseqnet.c
|
|
|
|
@@ -21,6 +21,7 @@
|
|
|
|
#include <string.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
+#include <arpa/inet.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <locale.h>
|
|
|
|
#include <alsa/asoundlib.h>
|
|
|
|
@@ -38,10 +39,9 @@ static void init_buf(void);
|
|
|
|
static void init_pollfds(void);
|
|
|
|
static void close_files(void);
|
|
|
|
static void init_seq(char *source, char *dest, char *name);
|
|
|
|
-static int get_port(char *service);
|
|
|
|
static void sigterm_exit(int sig);
|
|
|
|
-static void init_server(int port);
|
|
|
|
-static void init_client(char *server, int port);
|
|
|
|
+static void init_server(const char *port);
|
|
|
|
+static void init_client(const char *server, const char *port);
|
|
|
|
static void do_loop(void);
|
|
|
|
static int copy_local_to_remote(void);
|
|
|
|
static int copy_remote_to_local(int fd);
|
|
|
|
@@ -49,7 +49,7 @@ static int copy_remote_to_local(int fd);
|
|
|
|
/*
|
|
|
|
* default TCP port number
|
|
|
|
*/
|
|
|
|
-#define DEFAULT_PORT 40002
|
|
|
|
+#define DEFAULT_PORT "40002"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* local input buffer
|
|
|
|
@@ -97,7 +97,7 @@ static const struct option long_option[] = {
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
- int port = DEFAULT_PORT;
|
|
|
|
+ char *port = DEFAULT_PORT;
|
|
|
|
char *source = NULL, *dest = NULL;
|
|
|
|
char *name = NULL;
|
|
|
|
|
|
|
|
@@ -109,10 +109,7 @@ int main(int argc, char **argv)
|
|
|
|
while ((c = getopt_long(argc, argv, "p:s:d:n:,vi", long_option, NULL)) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'p':
|
|
|
|
- if (isdigit(*optarg))
|
|
|
|
- port = atoi(optarg);
|
|
|
|
- else
|
|
|
|
- port = get_port(optarg);
|
|
|
|
+ port = optarg;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
source = optarg;
|
|
|
|
@@ -307,19 +304,25 @@ static void init_seq(char *source, char *dest, char* name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
/*
|
|
|
|
- * convert from string to TCP port number
|
|
|
|
+ * translate the binary network address to ASCII
|
|
|
|
*/
|
|
|
|
-static int get_port(char *service)
|
|
|
|
+static void get_net_addr(struct addrinfo *rp, char *buf, size_t buflen)
|
|
|
|
{
|
|
|
|
- struct servent *sp;
|
|
|
|
+ void *ptr;
|
|
|
|
|
|
|
|
- if ((sp = getservbyname(service, "tcp")) == NULL){
|
|
|
|
- fprintf(stderr, _("service '%s' is not found in /etc/services\n"), service);
|
|
|
|
- return -1;
|
|
|
|
+ switch (rp->ai_family) {
|
|
|
|
+ case AF_INET:
|
|
|
|
+ ptr = &((struct sockaddr_in *) rp->ai_addr)->sin_addr;
|
|
|
|
+ break;
|
|
|
|
+ case AF_INET6:
|
|
|
|
+ ptr = &((struct sockaddr_in6 *) rp->ai_addr)->sin6_addr;
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ ptr = NULL;
|
|
|
|
}
|
|
|
|
- return sp->s_port;
|
|
|
|
+ buf[buflen-1] = '\0';
|
|
|
|
+ inet_ntop(rp->ai_family, ptr, buf, buflen-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
@@ -335,30 +338,48 @@ static void sigterm_exit(int sig)
|
|
|
|
/*
|
|
|
|
* initialize network server
|
|
|
|
*/
|
|
|
|
-static void init_server(int port)
|
|
|
|
+static void init_server(const char *port)
|
|
|
|
{
|
|
|
|
+ struct addrinfo hints;
|
|
|
|
+ struct addrinfo *result, *rp;
|
|
|
|
+ char buf[100];
|
|
|
|
int i;
|
|
|
|
int curstate = 1;
|
|
|
|
- struct sockaddr_in addr;
|
|
|
|
+ int save_errno = 0;
|
|
|
|
|
|
|
|
- memset(&addr, 0, sizeof(addr));
|
|
|
|
-
|
|
|
|
- addr.sin_family = AF_INET;
|
|
|
|
- addr.sin_addr.s_addr = INADDR_ANY;
|
|
|
|
- addr.sin_port = htons(port);
|
|
|
|
+ memset(&hints, 0, sizeof(hints));
|
|
|
|
+ hints.ai_family = AF_INET;
|
|
|
|
+ hints.ai_socktype = SOCK_STREAM;
|
|
|
|
+ hints.ai_flags = AI_PASSIVE;
|
|
|
|
|
|
|
|
- sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
|
|
|
- if (sockfd < 0) {
|
|
|
|
- perror("create socket");
|
|
|
|
+ if (getaddrinfo(NULL, port, &hints, &result) < 0) {
|
|
|
|
+ fprintf(stderr, _("can't get address\n"));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
- setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &curstate, sizeof(curstate));
|
|
|
|
- /* the return value is ignored.. */
|
|
|
|
-
|
|
|
|
- if (bind(sockfd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
|
|
|
- perror("can't bind");
|
|
|
|
+ for (rp = result; rp != NULL; rp = rp->ai_next) {
|
|
|
|
+ if ((sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0){
|
|
|
|
+ perror("create socket");
|
|
|
|
+ exit(1);
|
|
|
|
+ }
|
|
|
|
+ if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &curstate, sizeof(curstate)) < 0) {
|
|
|
|
+ perror("setsockopt");
|
|
|
|
+ exit(1);
|
|
|
|
+ }
|
|
|
|
+ if (verbose) {
|
|
|
|
+ get_net_addr(rp, buf, sizeof(buf));
|
|
|
|
+ fprintf(stderr, _("connecting to: %s\n"), buf);
|
|
|
|
+ }
|
|
|
|
+ if (bind(sockfd, rp->ai_addr, rp->ai_addrlen) == 0)
|
|
|
|
+ break;
|
|
|
|
+ save_errno = errno;
|
|
|
|
+ close(sockfd);
|
|
|
|
+ }
|
|
|
|
+ if (rp == NULL) {
|
|
|
|
+ errno = save_errno;
|
|
|
|
+ perror("bind");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
+ freeaddrinfo(result);
|
|
|
|
|
|
|
|
if (listen(sockfd, 5) < 0) {
|
|
|
|
perror("can't listen");
|
|
|
|
@@ -402,32 +423,48 @@ static void start_connection(void)
|
|
|
|
/*
|
|
|
|
* initialize network client
|
|
|
|
*/
|
|
|
|
-static void init_client(char *server, int port)
|
|
|
|
+static void init_client(const char *server, const char *port)
|
|
|
|
{
|
|
|
|
- struct sockaddr_in addr;
|
|
|
|
- struct hostent *host;
|
|
|
|
+ struct addrinfo hints;
|
|
|
|
+ struct addrinfo *result, *rp;
|
|
|
|
+ char buf[100];
|
|
|
|
int curstate = 1;
|
|
|
|
int fd;
|
|
|
|
+ int save_errno = 0;
|
|
|
|
|
|
|
|
- if ((fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0){
|
|
|
|
- perror("create socket");
|
|
|
|
- exit(1);
|
|
|
|
- }
|
|
|
|
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &curstate, sizeof(curstate)) < 0) {
|
|
|
|
- perror("setsockopt");
|
|
|
|
- exit(1);
|
|
|
|
- }
|
|
|
|
- if ((host = gethostbyname(server)) == NULL){
|
|
|
|
+ memset(&hints, 0, sizeof(hints));
|
|
|
|
+ hints.ai_family = AF_INET;
|
|
|
|
+ hints.ai_socktype = SOCK_STREAM;
|
|
|
|
+ hints.ai_flags = AI_PASSIVE;
|
|
|
|
+
|
|
|
|
+ if (getaddrinfo(server, port, &hints, &result) < 0) {
|
|
|
|
fprintf(stderr, _("can't get address %s\n"), server);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
- addr.sin_port = htons(port);
|
|
|
|
- addr.sin_family = AF_INET;
|
|
|
|
- memcpy(&addr.sin_addr, host->h_addr, host->h_length);
|
|
|
|
- if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
|
|
|
+ for (rp = result; rp != NULL; rp = rp->ai_next) {
|
|
|
|
+ if ((fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0){
|
|
|
|
+ perror("create socket");
|
|
|
|
+ exit(1);
|
|
|
|
+ }
|
|
|
|
+ if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &curstate, sizeof(curstate)) < 0) {
|
|
|
|
+ perror("setsockopt");
|
|
|
|
+ exit(1);
|
|
|
|
+ }
|
|
|
|
+ if (verbose) {
|
|
|
|
+ get_net_addr(rp, buf, sizeof(buf));
|
|
|
|
+ fprintf(stderr, _("connecting to: %s\n"), buf);
|
|
|
|
+ }
|
|
|
|
+ if (connect(fd, rp->ai_addr, rp->ai_addrlen) == 0)
|
|
|
|
+ break;
|
|
|
|
+ save_errno = errno;
|
|
|
|
+ close(fd);
|
|
|
|
+ }
|
|
|
|
+ if (rp == NULL) {
|
|
|
|
+ errno = save_errno;
|
|
|
|
perror("connect");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
+ freeaddrinfo(result);
|
|
|
|
if (verbose)
|
|
|
|
fprintf(stderr, _("ok.. connected\n"));
|
|
|
|
netfd[0] = fd;
|
|
|
|
--
|
|
|
|
2.31.1
|
|
|
|
|
|
|
|
|
|
|
|
From 5471a0b285d5918a62219fa454bca127de356507 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Jaroslav Kysela <perex@perex.cz>
|
|
|
|
Date: Mon, 9 Aug 2021 20:24:44 +0200
|
|
|
|
Subject: [PATCH 4/4] aseqnet: add ipv6 support
|
|
|
|
|
|
|
|
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
|
|
|
|
---
|
|
|
|
seq/aseqnet/aseqnet.c | 16 +++++++++++-----
|
|
|
|
1 file changed, 11 insertions(+), 5 deletions(-)
|
|
|
|
|
|
|
|
diff --git a/seq/aseqnet/aseqnet.c b/seq/aseqnet/aseqnet.c
|
|
|
|
index d05f52d..41d7256 100644
|
|
|
|
--- a/seq/aseqnet/aseqnet.c
|
|
|
|
+++ b/seq/aseqnet/aseqnet.c
|
|
|
|
@@ -75,6 +75,7 @@ static int cur_connected;
|
|
|
|
static int seq_port;
|
|
|
|
|
|
|
|
static int server_mode;
|
|
|
|
+static int ipv6 = 0;
|
|
|
|
static int verbose = 0;
|
|
|
|
static int info = 0;
|
|
|
|
|
|
|
|
@@ -84,6 +85,7 @@ static int info = 0;
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const struct option long_option[] = {
|
|
|
|
+ {"ipv6", 0, NULL, '6'},
|
|
|
|
{"port", 1, NULL, 'p'},
|
|
|
|
{"source", 1, NULL, 's'},
|
|
|
|
{"dest", 1, NULL, 'd'},
|
|
|
|
@@ -106,8 +108,11 @@ int main(int argc, char **argv)
|
|
|
|
textdomain(PACKAGE);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
- while ((c = getopt_long(argc, argv, "p:s:d:n:,vi", long_option, NULL)) != -1) {
|
|
|
|
+ while ((c = getopt_long(argc, argv, "p:s:d:n:6hvi", long_option, NULL)) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
+ case '6':
|
|
|
|
+ ipv6 = 1;
|
|
|
|
+ break;
|
|
|
|
case 'p':
|
|
|
|
port = optarg;
|
|
|
|
break;
|
|
|
|
@@ -169,6 +174,7 @@ static void usage(void)
|
|
|
|
printf(_(" server mode: aseqnet [-options]\n"));
|
|
|
|
printf(_(" client mode: aseqnet [-options] server_host\n"));
|
|
|
|
printf(_("options:\n"));
|
|
|
|
+ printf(_(" -6,--ipv6 : use IPv6 TCP protocol\n"));
|
|
|
|
printf(_(" -p,--port # : specify TCP port (digit or service name)\n"));
|
|
|
|
printf(_(" -s,--source addr : read from given addr (client:port)\n"));
|
|
|
|
printf(_(" -d,--dest addr : write to given addr (client:port)\n"));
|
|
|
|
@@ -348,7 +354,7 @@ static void init_server(const char *port)
|
|
|
|
int save_errno = 0;
|
|
|
|
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
- hints.ai_family = AF_INET;
|
|
|
|
+ hints.ai_family = ipv6 ? AF_INET6 : AF_INET;
|
|
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
|
|
hints.ai_flags = AI_PASSIVE;
|
|
|
|
|
|
|
|
@@ -357,7 +363,7 @@ static void init_server(const char *port)
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
for (rp = result; rp != NULL; rp = rp->ai_next) {
|
|
|
|
- if ((sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0){
|
|
|
|
+ if ((sockfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol)) < 0){
|
|
|
|
perror("create socket");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
@@ -433,7 +439,7 @@ static void init_client(const char *server, const char *port)
|
|
|
|
int save_errno = 0;
|
|
|
|
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
- hints.ai_family = AF_INET;
|
|
|
|
+ hints.ai_family = AF_UNSPEC;
|
|
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
|
|
hints.ai_flags = AI_PASSIVE;
|
|
|
|
|
|
|
|
@@ -442,7 +448,7 @@ static void init_client(const char *server, const char *port)
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
for (rp = result; rp != NULL; rp = rp->ai_next) {
|
|
|
|
- if ((fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0){
|
|
|
|
+ if ((fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol)) < 0){
|
|
|
|
perror("create socket");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
--
|
|
|
|
2.31.1
|
|
|
|
|