summaryrefslogtreecommitdiff
path: root/schulung_tools/ipc_tcp/send.c
diff options
context:
space:
mode:
authorJohn Ogness <john.ogness@linutronix.de>2019-02-01 17:02:02 +0106
committerJohn Ogness <john.ogness@linutronix.de>2019-02-01 17:02:02 +0106
commita7453e30ca4c9f42d27d42f96bc223533c330900 (patch)
tree9dcf79c2844c6512af9487e9f0cf2663d0bd01f3 /schulung_tools/ipc_tcp/send.c
parent80aaf4928e7594f5fdf454de3fa5c43c9eb858c2 (diff)
ipc_tcp: add new ipc example using loopback sockets
This demo should (hopefully serve) as a basis for overlaying pcap and ftrace data within trace compass. Signed-off-by: John Ogness <john.ogness@linutronix.de>
Diffstat (limited to 'schulung_tools/ipc_tcp/send.c')
-rw-r--r--schulung_tools/ipc_tcp/send.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/schulung_tools/ipc_tcp/send.c b/schulung_tools/ipc_tcp/send.c
new file mode 100644
index 0000000..60d2f1f
--- /dev/null
+++ b/schulung_tools/ipc_tcp/send.c
@@ -0,0 +1,52 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+static char buffer[1024 * 1024];
+
+int main(void)
+{
+ struct sockaddr_in sa;
+ size_t count = 0;
+ size_t size;
+ int rv;
+ int s;
+
+ s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if (s < 0)
+ return 1;
+ memset(&sa, 0, sizeof(sa));
+ sa.sin_family = AF_INET;
+ sa.sin_addr.s_addr = inet_addr("127.0.0.1");
+ sa.sin_port = htons(8806);
+
+ if (connect(s, (struct sockaddr *)&sa, sizeof(struct sockaddr)) != 0)
+ return 1;
+
+ printf("send (%d): type message and hit RETURN to send signal\n",
+ getpid());
+ fgets(buffer, sizeof(buffer), stdin);
+
+ /* set "sending" uprobe here */
+
+ size = strlen(buffer);
+
+ if (write(s, &size, sizeof(size)) != sizeof(size))
+ return 1;
+
+ while (count < size) {
+ rv = write(s, buffer + count, size - count);
+ if (rv <= 0)
+ return 1;
+ count += rv;
+ }
+
+ sleep(1);
+
+ return 0;
+}