2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 22:35:15 +00:00

socket-util: Change ss_format_address() to take a dynamic string.

It's occasionally convenient to format into a fixed-size buffer, but
as the use cases, and the text to be formatted, get more sophisticated,
it becomes easier to deal with "struct ds *" than a buffer pointer and
length pair.  An upcoming commit will make ss_format_address() do more
work, and I think that this is the point at which it becomes easier to
take a dynamic string.  This commit makes the parameter type change
without yet changing what is formatted.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Tested-by: Numan Siddique <nusiddiq@redhat.com>
Acked-by: Numan Siddique <nusiddiq@redhat.com>
This commit is contained in:
Ben Pfaff
2017-07-14 14:33:45 -07:00
parent b7636967a8
commit fd245f1da9
4 changed files with 45 additions and 52 deletions

View File

@@ -825,8 +825,6 @@ static int
pssl_open(const char *name OVS_UNUSED, char *suffix, struct pstream **pstreamp,
uint8_t dscp)
{
char bound_name[SS_NTOP_BUFSIZE + 16];
char addrbuf[SS_NTOP_BUFSIZE];
struct sockaddr_storage ss;
struct pssl_pstream *pssl;
uint16_t port;
@@ -844,14 +842,18 @@ pssl_open(const char *name OVS_UNUSED, char *suffix, struct pstream **pstreamp,
}
port = ss_get_port(&ss);
snprintf(bound_name, sizeof bound_name, "pssl:%"PRIu16":%s",
port, ss_format_address(&ss, addrbuf, sizeof addrbuf));
struct ds bound_name = DS_EMPTY_INITIALIZER;
ds_put_format(&bound_name, "pssl:%"PRIu16":", port);
ss_format_address(&ss, &bound_name);
pssl = xmalloc(sizeof *pssl);
pstream_init(&pssl->pstream, &pssl_pstream_class, xstrdup(bound_name));
pstream_init(&pssl->pstream, &pssl_pstream_class,
ds_steal_cstr(&bound_name));
pstream_set_bound_port(&pssl->pstream, htons(port));
pssl->fd = fd;
*pstreamp = &pssl->pstream;
return 0;
}
@@ -867,8 +869,6 @@ static int
pssl_accept(struct pstream *pstream, struct stream **new_streamp)
{
struct pssl_pstream *pssl = pssl_pstream_cast(pstream);
char name[SS_NTOP_BUFSIZE + 16];
char addrbuf[SS_NTOP_BUFSIZE];
struct sockaddr_storage ss;
socklen_t ss_len = sizeof ss;
int new_fd;
@@ -894,11 +894,12 @@ pssl_accept(struct pstream *pstream, struct stream **new_streamp)
return error;
}
snprintf(name, sizeof name, "ssl:%s:%"PRIu16,
ss_format_address(&ss, addrbuf, sizeof addrbuf),
ss_get_port(&ss));
return new_ssl_stream(xstrdup(name), new_fd, SERVER, STATE_SSL_CONNECTING,
new_streamp);
struct ds name = DS_EMPTY_INITIALIZER;
ds_put_cstr(&name, "ssl:");
ss_format_address(&ss, &name);
ds_put_format(&name, ":%"PRIu16, ss_get_port(&ss));
return new_ssl_stream(ds_steal_cstr(&name), new_fd, SERVER,
STATE_SSL_CONNECTING, new_streamp);
}
static void