Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

udpsender to take payload size as parameter #4

Open
vigneswaran opened this issue Sep 21, 2015 · 0 comments
Open

udpsender to take payload size as parameter #4

vigneswaran opened this issue Sep 21, 2015 · 0 comments

Comments

@vigneswaran
Copy link

Hello,

The following patch enables user to specify payload size to the 'udpsender' program (part of 'how-to-receive-a-million-packets' project). This may be useful, if someone wants to generate packets of different sizes.

--- a/udpsender.c   2015-09-21 12:35:30.341486515 +0530
+++ b/udpsender.c   2015-09-21 17:07:00.730645321 +0530
@@ -8,6 +8,10 @@

 #include "common.h"

+/* Minimum payload: 64 - 42 (frame overhead)
+ * Maximum payload: 1518 - 42 (frame overhead) */
+#define MIN_PAYLOAD 22
+#define MAX_PAYLOAD 1476

 struct state {
    struct net_addr *target_addr;
@@ -64,13 +68,18 @@
 int main(int argc, const char *argv[])
 {
    int packets_in_buf = 1024;
-   const char *payload = (const char[32]){0};
-   int payload_sz = 32;
+   const char *payload = (const char[MAX_PAYLOAD]){0};
+   int payload_sz = MIN_PAYLOAD;

-   if (argc == 1) {
-       FATAL("Usage: %s [target ip:port] [target ...]", argv[0]);
+   if (argc <= 2) {
+       FATAL("Usage: %s [payload size] [target ip:port] [target ...]", argv[0]);
    }

+    payload_sz = atoi(argv[1]);
+    payload_sz = (payload_sz >= MIN_PAYLOAD && payload_sz <= MAX_PAYLOAD) ? payload_sz : MIN_PAYLOAD;
+    argv++;
+    argc--;
+
    struct net_addr *target_addrs = calloc(argc-1, sizeof(struct net_addr));
    int thread_num = argc - 1;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant