fl0pped1t / mnc

Automatically exported from code.google.com/p/mnc
0 stars 0 forks source link

mnc may re-frame multicast packets #11

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Protocols exist where each packet contains data at fixed offsets within the 
packet. 
2. I would expect two mnc processes connected via. a pipe to accurately 
rebroadcast such a stream between multicast groups, for example:
$ mnc -l -p 61000 224.4.4.32 | mnc -p 61000 225.0.3.171

3. mnc does not guarantee packets are transmitted atomically - multiple input 
packets may be packaged into a single output packet, or more likely a partial 
packet may be broadcast, with the remainder in the next.

What is the expected output? What do you see instead?
Each input packet should product exactly one, identically sized packet

What version of the product are you using? On what operating system?
Any, specifically tested on Solaris and Linux

Please provide any additional information below.
The following patch transmits the size of each packet received *with* the data, 
such that the receiving mnc can splice packets at appropriate points.

Since this patch changes the stdout stream, it needs to be an optional mode, 
perhaps enabled with a flag --respect-frames or --with-packet-sizes to not 
upset existing users.

[14:20:34] $ svn diff
Index: mnc_main.c
===================================================================
--- mnc_main.c  (revision 13)
+++ mnc_main.c  (working copy)
@@ -66,7 +66,7 @@
        /* Utility variables */
        int                             sock,
                                        len;
-       char                            buffer[1024];
+       char                            buffer[2024];

        /* Our main configuration */
        struct mnc_configuration *      config;
@@ -89,7 +89,9 @@
        {
                mnc_error("Could not create socket\n");
        }
+        char sz_buf[]="    ";

+
        /* Are we supposed to listen? */
        if (config->mode == LISTENER)
        {
@@ -104,7 +106,12 @@
                while ((len = recvfrom(sock, buffer, sizeof(buffer), 
                                       0, NULL, NULL)) >= 0)
                {       
+                        sz_buf[0] = len & 0xFF; 
+                        sz_buf[1] = (len >> 8) & 0xFF;
+                       write(STDOUT_FILENO, sz_buf, 2);
                        write(STDOUT_FILENO, buffer, len);
+                       fflush(stdout);
+
                }
        }
        else /* Assume MODE == SENDER */
@@ -115,10 +122,18 @@
                {
                        mnc_error("Can not send multicast packets\n");
                }

+               int r = 0;
                /* Send the packets */
-               while((len = read(STDIN_FILENO, buffer, sizeof(buffer))) > 0)
+               while((len = read(STDIN_FILENO, sz_buf, 2)) > 0)
                {
+                       len = sz_buf[0] | (sz_buf[1] << 8);
+                       r = 0; 
+                       while (r < len) { 
+                          // printf("len=%d, r=%d\n", len, r); 
+                          r += read(STDIN_FILENO, buffer+r, len-r);    
+                       }
                        sendto(sock, buffer, len, 0, config->group->ai_addr, 
                               config->group->ai_addrlen);
                }

Original issue reported on code.google.com by ch...@shucksmith.co.uk on 11 Nov 2010 at 2:24

Attachments:

GoogleCodeExporter commented 8 years ago
I should add that sizeof(buffer) should be at least the MTU.

Original comment by ch...@shucksmith.co.uk on 11 Nov 2010 at 2:26