mirror of
https://github.com/openvswitch/ovs
synced 2025-10-27 15:18:06 +00:00
socket-util: New function inet_parse_address().
This will acquire its first user in an upcoming commit. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Mark Michelson <mmichels@redhat.com>
This commit is contained in:
@@ -698,6 +698,32 @@ error:
|
|||||||
return -error;
|
return -error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Parses 'target', which may be an IPv4 address or an IPv6 address
|
||||||
|
* enclosed in square brackets.
|
||||||
|
*
|
||||||
|
* On success, returns true and stores the parsed remote address into '*ss'.
|
||||||
|
* On failure, logs an error, stores zeros into '*ss', and returns false. */
|
||||||
|
bool
|
||||||
|
inet_parse_address(const char *target_, struct sockaddr_storage *ss)
|
||||||
|
{
|
||||||
|
char *target = xstrdup(target_);
|
||||||
|
char *p = target;
|
||||||
|
char *host = inet_parse_token(&p);
|
||||||
|
bool ok = false;
|
||||||
|
if (!host) {
|
||||||
|
VLOG_ERR("%s: host must be specified", target_);
|
||||||
|
} else if (p && p[strspn(p, " \t\r\n")] != '\0') {
|
||||||
|
VLOG_ERR("%s: unexpected characters follow host", target_);
|
||||||
|
} else {
|
||||||
|
ok = parse_sockaddr_components(ss, host, NULL, 0, target_);
|
||||||
|
}
|
||||||
|
if (!ok) {
|
||||||
|
memset(ss, 0, sizeof *ss);
|
||||||
|
}
|
||||||
|
free(target);
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
read_fully(int fd, void *p_, size_t size, size_t *bytes_read)
|
read_fully(int fd, void *p_, size_t size, size_t *bytes_read)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ int inet_open_passive(int style, const char *target, int default_port,
|
|||||||
struct sockaddr_storage *ssp, uint8_t dscp,
|
struct sockaddr_storage *ssp, uint8_t dscp,
|
||||||
bool kernel_print_port);
|
bool kernel_print_port);
|
||||||
|
|
||||||
|
bool inet_parse_address(const char *target, struct sockaddr_storage *);
|
||||||
|
|
||||||
int read_fully(int fd, void *, size_t, size_t *bytes_read);
|
int read_fully(int fd, void *, size_t, size_t *bytes_read);
|
||||||
int write_fully(int fd, const void *, size_t, size_t *bytes_written);
|
int write_fully(int fd, const void *, size_t, size_t *bytes_written);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user