[network-manager-sstp/fix-deprecation] Fixing a IPv6 truncation issue for when connected to a IPv6 remote gateway
- From: Eivind Næss <eivnaes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-sstp/fix-deprecation] Fixing a IPv6 truncation issue for when connected to a IPv6 remote gateway
- Date: Sun, 11 Sep 2022 20:56:35 +0000 (UTC)
commit b8598940c14797ea0e583aba163a5e83ea735c99
Author: Eivind Næss <eivnaes yahoo com>
Date: Sun Sep 11 13:54:45 2022 -0700
Fixing a IPv6 truncation issue for when connected to a IPv6 remote gateway
Also fixes issue #48 by using inet_ntop instead of inet_ntoa which is deprecated on some distributions.
Signed-off-by: Eivind Næss <eivnaes yahoo com>
src/nm-sstp-pppd-plugin.c | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
---
diff --git a/src/nm-sstp-pppd-plugin.c b/src/nm-sstp-pppd-plugin.c
index abe4d09..28484cf 100644
--- a/src/nm-sstp-pppd-plugin.c
+++ b/src/nm-sstp-pppd-plugin.c
@@ -225,7 +225,7 @@ done:
* Extract the address SSTPC resolved as the hostname
*/
static int
-nm_sstp_getaddr(struct sockaddr_in *addr)
+nm_sstp_getaddr(struct sockaddr_storage *addr)
{
char *buff = NULL;
int retval = (-1);
@@ -233,6 +233,7 @@ nm_sstp_getaddr(struct sockaddr_in *addr)
int ret = (-1);
int cnt = (SSTP_API_ATTR_MAX+1);
char name[255] = {};
+ char ipstr[INET6_ADDRSTRLEN];
sstp_api_msg_st msg;
sstp_api_msg_t type;
sstp_api_attr_st *attr;
@@ -297,7 +298,18 @@ nm_sstp_getaddr(struct sockaddr_in *addr)
}
/* Copy the result to the output argument */
- memcpy(addr, attr->attr_data, sizeof(struct sockaddr_in));
+ memcpy(addr, attr->attr_data, MIN(attr->attr_len, sizeof(*addr)));
+ switch (addr->ss_family)
+ {
+ case AF_INET:
+ inet_ntop(addr->ss_family, &((struct sockaddr_in*)addr)->sin_addr,
+ ipstr, sizeof(ipstr));
+ break;
+ case AF_INET6:
+ inet_ntop(addr->ss_family, &((struct sockaddr_in6*)addr)->sin6_addr,
+ ipstr, sizeof(ipstr));
+ break;
+ }
/* Get the gateway name */
attr = list[SSTP_API_ATTR_GATEWAY];
@@ -310,7 +322,7 @@ nm_sstp_getaddr(struct sockaddr_in *addr)
memcpy(name, attr->attr_data, attr->attr_len);
_LOGI ("sstp-plugin: sstpc is connected to %s using %s",
- name, inet_ntoa(addr->sin_addr));
+ name, ipstr);
/* Success */
retval = 0;
@@ -565,7 +577,7 @@ nm_send_config (void)
{
GVariantBuilder builder;
GVariant *ip4config = NULL, *ip6config = NULL;
- struct sockaddr_in addr;
+ struct sockaddr_storage addr;
int mtu;
g_return_if_fail (G_IS_DBUS_PROXY (gl.proxy));
@@ -584,12 +596,12 @@ nm_send_config (void)
/* Request the address of the server sstpc connected to */
if (0 == nm_sstp_getaddr(&addr)) {
- if (addr.sin_family == AF_INET) {
+ if (addr.ss_family == AF_INET) {
g_variant_builder_add (&builder, "{sv}",
NM_VPN_PLUGIN_CONFIG_EXT_GATEWAY,
- g_variant_new_uint32 (addr.sin_addr.s_addr));
+ g_variant_new_uint32 (((struct sockaddr_in*)&addr)->sin_addr.s_addr));
}
- if (addr.sin_family == AF_INET6) {
+ if (addr.ss_family == AF_INET6) {
g_variant_builder_add (&builder, "{sv}",
NM_VPN_PLUGIN_CONFIG_EXT_GATEWAY,
g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, &((struct
sockaddr_in6*)&addr)->sin6_addr, 16, 1));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]