Commit c0fbb728 authored by Dafydd Harries's avatar Dafydd Harries

fix fake UDP send, including 0-cleanliness

darcs-hash:20070122182609-c9803-d06c9d6d9c38e40fafced8c766dfe2a16d8d4fce.gz
parent e80dbcde
......@@ -29,7 +29,7 @@ main (void)
/* test recv */
strcpy (buf, "hello");
memcpy (buf, "he\0lo", 5);
len = 5;
sin.sin_addr.s_addr = htonl (0x01020304);
sin.sin_port = htons (2345);
......@@ -40,22 +40,22 @@ main (void)
len = udp_socket_recv (&sock, &sin, sizeof (buf), buf);
g_assert (len == 5);
g_assert (strcmp (buf, "hello") == 0);
g_assert (memcmp (buf, "he\0lo", 5) == 0);
g_assert (ntohl (sin.sin_addr.s_addr) == 0x01020304);
g_assert (ntohs (sin.sin_port) == 2345);
/* test send */
strcpy (buf, "lala");
len = 4;
memcpy (buf, "la\0la", 5);
len = 5;
udp_socket_send (&sock, &sin, len, buf);
memset (buf, '\0', len);
memset (&sin, '\0', sizeof (sin));
len = udp_fake_socket_pop_send (&sock, &sin, sizeof (buf), buf);
g_assert (len == 4);
g_assert (strcmp (buf, "lala"));
g_assert (len == 5);
g_assert (0 == memcmp (buf, "la\0la", 5));
g_assert (ntohl (sin.sin_addr.s_addr) == 0x01020304);
g_assert (ntohs (sin.sin_port) == 2345);
......
......@@ -55,7 +55,7 @@ fake_send (
packet = g_slice_new0 (Packet);
packet->len = len;
packet->sin = *to;
strncpy (packet->buf, buf, len);
memcpy (packet->buf, buf, len);
priv = (UDPFakeSocketPriv *) sock->priv;
priv->send_queue = g_slist_append (priv->send_queue, packet);
......@@ -157,6 +157,7 @@ udp_fake_socket_pop_send (
if (!packet)
return 0;
memcpy (buf, packet->buf, MIN (len, packet->len));
len = packet->len;
*to = packet->sin;
g_slice_free (Packet, packet);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment