59 lines
1.7 KiB
Diff
59 lines
1.7 KiB
Diff
From 35bb69bc47fecdf54de887a0c29a0889b79663a1 Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Cristian=20Rodr=C3=ADguez?= <crrodriguez@opensuse.org>
|
|
Date: Wed, 29 Jul 2020 12:10:08 -0400
|
|
Subject: [PATCH 0985/1095] gsocketclient: set IP_BIND_ADDRESS_NO_PORT if
|
|
binding to local address
|
|
|
|
The linux kernel does not know that the socket will be used
|
|
for connect or listen and if you bind() to a local address it must
|
|
reserve a random port (if port == 0) at bind() time, making very easy
|
|
to exhaust the ~32k port range, setting IP_BIND_ADDRESS_NO_PORT tells
|
|
the kernel to choose random port at connect() time instead, when the
|
|
full 4-tuple is known.
|
|
|
|
reason:gsocketclient: set IP_BIND_ADDRESS_NO_PORT if binding to local address
|
|
|
|
Conflict:NA
|
|
Reference:https://github.com/GNOME/glib/commit/35bb69bc47fecdf54de887a0c29a0889b79663a1
|
|
---
|
|
gio/gsocketclient.c | 9 +++++++++
|
|
1 file changed, 9 insertions(+)
|
|
|
|
diff --git a/gio/gsocketclient.c b/gio/gsocketclient.c
|
|
index c994330..ca01b68 100644
|
|
--- a/gio/gsocketclient.c
|
|
+++ b/gio/gsocketclient.c
|
|
@@ -24,6 +24,10 @@
|
|
#include "config.h"
|
|
#include "gsocketclient.h"
|
|
|
|
+#ifndef G_OS_WIN32
|
|
+#include <netinet/in.h>
|
|
+#endif
|
|
+
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
@@ -39,6 +43,7 @@
|
|
#include <gio/gioerror.h>
|
|
#include <gio/gsocket.h>
|
|
#include <gio/gnetworkaddress.h>
|
|
+#include <gio/gnetworking.h>
|
|
#include <gio/gnetworkservice.h>
|
|
#include <gio/gproxy.h>
|
|
#include <gio/gproxyresolver.h>
|
|
@@ -142,6 +147,10 @@ create_socket (GSocketClient *client,
|
|
|
|
if (client->priv->local_address)
|
|
{
|
|
+#ifdef IP_BIND_ADDRESS_NO_PORT
|
|
+ g_socket_set_option (socket, IPPROTO_IP, IP_BIND_ADDRESS_NO_PORT, 1, NULL);
|
|
+#endif
|
|
+
|
|
if (!g_socket_bind (socket,
|
|
client->priv->local_address,
|
|
FALSE,
|
|
--
|
|
1.8.3.1
|
|
|