summaryrefslogtreecommitdiff
path: root/schulung_tools/ipc_tcp/send.c
diff options
context:
space:
mode:
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;
+}