mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
lib: Add samba_sockaddr_[gs]et_port()
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Samuel Cabrero <scabrero@samba.org>
This commit is contained in:
parent
4aa3ff574f
commit
2e5d246b3b
@ -1091,3 +1091,33 @@ bool sockaddr_storage_to_samba_sockaddr(
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool samba_sockaddr_set_port(struct samba_sockaddr *sa, uint16_t port)
|
||||
{
|
||||
if (sa->u.sa.sa_family == AF_INET) {
|
||||
sa->u.in.sin_port = port;
|
||||
return true;
|
||||
}
|
||||
#ifdef HAVE_IPV6
|
||||
if (sa->u.sa.sa_family == AF_INET6) {
|
||||
sa->u.in6.sin6_port = port;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
bool samba_sockaddr_get_port(const struct samba_sockaddr *sa, uint16_t *port)
|
||||
{
|
||||
if (sa->u.sa.sa_family == AF_INET) {
|
||||
*port = sa->u.in.sin_port;
|
||||
return true;
|
||||
}
|
||||
#ifdef HAVE_IPV6
|
||||
if (sa->u.sa.sa_family == AF_INET6) {
|
||||
*port = sa->u.in6.sin6_port;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
@ -125,5 +125,7 @@ void set_socket_options(int fd, const char *options);
|
||||
|
||||
bool sockaddr_storage_to_samba_sockaddr(
|
||||
struct samba_sockaddr *sa, const struct sockaddr_storage *ss);
|
||||
bool samba_sockaddr_set_port(struct samba_sockaddr *sa, uint16_t port);
|
||||
bool samba_sockaddr_get_port(const struct samba_sockaddr *sa, uint16_t *port);
|
||||
|
||||
#endif /* _SAMBA_UTIL_NET_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user