diff --git a/common/gdm-address.h b/common/gdm-address.h
index 5a01f8f..6cb26b1 100644
--- a/common/gdm-address.h
+++ b/common/gdm-address.h
@@ -35,6 +35,7 @@
 G_BEGIN_DECLS
 
 #define GDM_TYPE_ADDRESS (gdm_address_get_type ())
+#define	gdm_sockaddr_len(sa) (((struct sockaddr *)sa)->sa_family == AF_INET6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in))
 
 typedef struct _GdmAddress GdmAddress;
 
diff --git a/daemon/gdm-xdmcp-display-factory.c b/daemon/gdm-xdmcp-display-factory.c
index 2207cef..838854a 100644
--- a/daemon/gdm-xdmcp-display-factory.c
+++ b/daemon/gdm-xdmcp-display-factory.c
@@ -835,7 +835,7 @@ gdm_xdmcp_send_willing (GdmXdmcpDisplayFactory *factory,
         XdmcpFlush (factory->priv->socket_fd,
                     &factory->priv->buf,
                     (XdmcpNetaddr)gdm_address_peek_sockaddr_storage (address),
-                    (int)sizeof (struct sockaddr_storage));
+                    (int)gdm_sockaddr_len (gdm_address_peek_sockaddr_storage (address)));
 
         g_free (status.data);
 }
@@ -879,7 +879,7 @@ gdm_xdmcp_send_unwilling (GdmXdmcpDisplayFactory *factory,
         XdmcpFlush (factory->priv->socket_fd,
                     &factory->priv->buf,
                     (XdmcpNetaddr)gdm_address_peek_sockaddr_storage (address),
-                    (int)sizeof (struct sockaddr_storage));
+                    (int)gdm_sockaddr_len (gdm_address_peek_sockaddr_storage (address)));
 
         last_time = time (NULL);
 }
@@ -988,7 +988,7 @@ gdm_xdmcp_send_forward_query (GdmXdmcpDisplayFactory  *factory,
         XdmcpFlush (factory->priv->socket_fd,
                     &factory->priv->buf,
                     (XdmcpNetaddr)gdm_address_peek_sockaddr_storage (ic->chosen_address),
-                    (int)sizeof (struct sockaddr_storage));
+                    (int)gdm_sockaddr_len (gdm_address_peek_sockaddr_storage (ic->chosen_address)));
 
         g_free (port.data);
         g_free (addr.data);
@@ -1691,7 +1691,7 @@ gdm_xdmcp_really_send_managed_forward (GdmXdmcpDisplayFactory *factory,
         XdmcpFlush (factory->priv->socket_fd,
                     &factory->priv->buf,
                     (XdmcpNetaddr)gdm_address_peek_sockaddr_storage (address),
-                    (int)sizeof (struct sockaddr_storage));
+                    (int)gdm_sockaddr_len (gdm_address_peek_sockaddr_storage (address)));
 
         g_free (addr.data);
 }
@@ -1772,7 +1772,7 @@ gdm_xdmcp_send_got_managed_forward (GdmXdmcpDisplayFactory *factory,
         XdmcpFlush (factory->priv->socket_fd,
                     &factory->priv->buf,
                     (XdmcpNetaddr)gdm_address_peek_sockaddr_storage (address),
-                    (int)sizeof (struct sockaddr_storage));
+                    (int)gdm_sockaddr_len (gdm_address_peek_sockaddr_storage (address)));
 }
 
 static gboolean
@@ -1945,7 +1945,7 @@ gdm_xdmcp_send_decline (GdmXdmcpDisplayFactory *factory,
         XdmcpFlush (factory->priv->socket_fd,
                     &factory->priv->buf,
                     (XdmcpNetaddr)gdm_address_peek_sockaddr_storage (address),
-                    (int)sizeof (struct sockaddr_storage));
+                    (int)gdm_sockaddr_len (gdm_address_peek_sockaddr_storage (address)));
 
         /* Send MANAGED_FORWARD to indicate that the connection
          * reached some sort of resolution */
@@ -2093,7 +2093,7 @@ gdm_xdmcp_send_accept (GdmXdmcpDisplayFactory *factory,
         XdmcpFlush (factory->priv->socket_fd,
                     &factory->priv->buf,
                     (XdmcpNetaddr)gdm_address_peek_sockaddr_storage (address),
-                    (int)sizeof (struct sockaddr_storage));
+                    (int)gdm_sockaddr_len (gdm_address_peek_sockaddr_storage (address)));
 
         host = NULL;
         gdm_address_get_numeric_info (address, &host, NULL);
@@ -2424,7 +2424,7 @@ gdm_xdmcp_send_failed (GdmXdmcpDisplayFactory *factory,
         XdmcpFlush (factory->priv->socket_fd,
                     &factory->priv->buf,
                     (XdmcpNetaddr)gdm_address_peek_sockaddr_storage (address),
-                    (int)sizeof (struct sockaddr_storage));
+                    (int)gdm_sockaddr_len (gdm_address_peek_sockaddr_storage (address)));
 }
 
 static void
@@ -2448,7 +2448,7 @@ gdm_xdmcp_send_refuse (GdmXdmcpDisplayFactory *factory,
         XdmcpFlush (factory->priv->socket_fd,
                     &factory->priv->buf,
                     (XdmcpNetaddr)gdm_address_peek_sockaddr_storage (address),
-                    (int)sizeof (struct sockaddr_storage));
+                    (int)gdm_sockaddr_len (gdm_address_peek_sockaddr_storage (address)));
 
         /*
          * This was from a forwarded query quite apparently so
@@ -2719,7 +2719,7 @@ gdm_xdmcp_send_alive (GdmXdmcpDisplayFactory *factory,
         XdmcpFlush (factory->priv->socket_fd,
                     &factory->priv->buf,
                     (XdmcpNetaddr)gdm_address_peek_sockaddr_storage (address),
-                    (int)sizeof (struct sockaddr_storage));
+                    (int)gdm_sockaddr_len (gdm_address_peek_sockaddr_storage (address)));
 }
 
 static void
diff --git a/gui/simple-chooser/gdm-host-chooser-widget.c b/gui/simple-chooser/gdm-host-chooser-widget.c
index 6ea9196..085cf5d 100644
--- a/gui/simple-chooser/gdm-host-chooser-widget.c
+++ b/gui/simple-chooser/gdm-host-chooser-widget.c
@@ -311,7 +311,8 @@ do_ping (GdmHostChooserWidget *widget,
                 res = XdmcpFlush (widget->priv->socket_fd,
                                   &widget->priv->broadcast_buf,
                                   (XdmcpNetaddr)gdm_address_peek_sockaddr_storage (address),
-                                  (int)sizeof (struct sockaddr_storage));
+                                  (int)gdm_sockaddr_len (gdm_address_peek_sockaddr_storage (address)));
+
                 if (! res) {
                         g_warning ("Unable to flush the XDMCP broadcast packet: %s", g_strerror (errno));
                 }
@@ -328,7 +329,7 @@ do_ping (GdmHostChooserWidget *widget,
                         res = XdmcpFlush (widget->priv->socket_fd,
                                           &widget->priv->query_buf,
                                           (XdmcpNetaddr)gdm_address_peek_sockaddr_storage (address),
-                                          (int)sizeof (struct sockaddr_storage));
+                                          (int)gdm_sockaddr_len (gdm_address_peek_sockaddr_storage (address)));
                         if (! res) {
                                 g_warning ("Unable to flush the XDMCP query packet");
                         }
