diff options
author | Volker Lendecke <vl@samba.org> | 2020-12-30 22:43:07 +0100 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2021-01-11 13:19:32 +0000 |
commit | 4aa3ff574f209d0fbd1e725cf06af03887db9fe0 (patch) | |
tree | 6c09aa2fa22bd91d3f0b8ae70ebd6ab26701132b /lib/util | |
parent | 564b62a6f7c0a9b9712946d723118122b9c3785f (diff) | |
download | samba-4aa3ff574f209d0fbd1e725cf06af03887db9fe0.tar.gz |
lib: Move sockaddr_storage_to_samba_sockaddr() to lib/
This can be useful outside of source3/libsmb/namequery.c as Samba
moves towards samba_sockaddr.
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Samuel Cabrero <scabrero@samba.org>
Diffstat (limited to 'lib/util')
-rw-r--r-- | lib/util/util_net.c | 26 | ||||
-rw-r--r-- | lib/util/util_net.h | 3 |
2 files changed, 29 insertions, 0 deletions
diff --git a/lib/util/util_net.c b/lib/util/util_net.c index b9b0621f45f..0460a3ad3a8 100644 --- a/lib/util/util_net.c +++ b/lib/util/util_net.c @@ -1065,3 +1065,29 @@ void set_socket_options(int fd, const char *options) TALLOC_FREE(ctx); print_socket_options(fd); } + +/* + * Utility function that copes only with AF_INET and AF_INET6 + * as that's all we're going to get out of DNS / NetBIOS / WINS + * name resolution functions. + */ + +bool sockaddr_storage_to_samba_sockaddr( + struct samba_sockaddr *sa, const struct sockaddr_storage *ss) +{ + sa->u.ss = *ss; + + switch (ss->ss_family) { + case AF_INET: + sa->sa_socklen = sizeof(struct sockaddr_in); + break; +#ifdef HAVE_IPV6 + case AF_INET6: + sa->sa_socklen = sizeof(struct sockaddr_in6); + break; +#endif + default: + return false; + } + return true; +} diff --git a/lib/util/util_net.h b/lib/util/util_net.h index 80a7e08b7e8..4f60a9c6f7d 100644 --- a/lib/util/util_net.h +++ b/lib/util/util_net.h @@ -123,4 +123,7 @@ char *print_canonical_sockaddr(TALLOC_CTX *ctx, void set_socket_options(int fd, const char *options); +bool sockaddr_storage_to_samba_sockaddr( + struct samba_sockaddr *sa, const struct sockaddr_storage *ss); + #endif /* _SAMBA_UTIL_NET_H_ */ |