/* depend: */
/* cflags: */
-/* linker: mtime.o test.o stat.o -lm -lpthread -lrt */
+/* linker: msg.o mtime.o test.o stat.o -lm -lpthread -lrt */
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
+#include "msg.h"
#include "mtime.h"
#include "test.h"
void (*usage_ext) (FILE *) = NULL;
int (*parse_arg_ext) (char *) = NULL;
+#define MSGLEN 128
#define MAXBUF 1024
#define TIMER 1000
pthread_mutex_unlock (&mutex);
sys_timestamp (&ts1);
- char *buffer = "ping";
- if (mq_send (mq, buffer, strlen (buffer) + 1, 0) == -1) {
+ char *msg = get_msg (MSGLEN);
+ if (mq_send (mq, msg, MSGLEN, 0) == -1) {
fprintf (stderr, "ping error: mq_send (%d)\n", try);
rc = 1;
pthread_exit (NULL);
/* depend: */
/* cflags: */
-/* linker: mtime.o test.o stat.o -lm -lrt */
+/* linker: msg.o mtime.o test.o stat.o -lm -lrt */
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
+#include "msg.h"
#include "mtime.h"
#include "test.h"
void (*usage_ext) (FILE *) = NULL;
int (*parse_arg_ext) (char *) = NULL;
+#define MSGLEN 128
#define MAXBUF 1024
int ping (mqd_t mq)
printf ("Sending ping...\n");
for (int i = 0; i < nb_measurements; i++) {
+ char *msg = get_msg (MSGLEN);
char buffer[MAXBUF] = { 0 };
- sprintf (buffer, "ping %d", i);
ts_t ts1;
sys_timestamp (&ts1);
- if (mq_send (mq, buffer, strlen (buffer) + 1, 0) == -1) {
+ if (mq_send (mq, msg, MSGLEN, 0) == -1) {
fprintf (stderr, "ping error: mq_send (%d)\n", i);
return 1;
}
//printf ("send '%s'\n", buffer);
- if (mq_receive (mq, buffer, sizeof(buffer), NULL) == -1) {
+ if (mq_receive (mq, buffer, sizeof(buffer) - 1, NULL) == -1) {
fprintf (stderr, "ping error: mq_receive (%d)\n", i);
return 1;
}
printf ("Responding pong...\n");
for (int i = 0; i < nb_measurements; i++) {
+ char *msg = get_msg (MSGLEN);
char buffer[MAXBUF] = { 0 };
- if (mq_receive (mq, buffer, sizeof(buffer), NULL) == -1) {
+ if (mq_receive (mq, buffer, sizeof(buffer) - 1, NULL) == -1) {
fprintf (stderr, "pong error: mq_receive (%d)\n", i);
return 1;
}
//printf ("receive '%s'\n", buffer);
- if (mq_send (mq, buffer, strlen (buffer) + 1, 0) == -1) {
+ if (mq_send (mq, msg, MSGLEN, 0) == -1) {
fprintf (stderr, "pong error: mq_send (%d)\n", i);
return 1;
}
/* depend: */
/* cflags: */
-/* linker: mtime.o test.o stat.o -lm -lpthread -lrt */
+/* linker: msg.o mtime.o test.o stat.o -lm -lpthread -lrt */
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
+#include "msg.h"
#include "mtime.h"
#include "test.h"
void (*usage_ext) (FILE *) = NULL;
int (*parse_arg_ext) (char *) = NULL;
+#define MSGLEN 128
#define MAXBUF 1024
#define TIMER 100
for (int i = 0; i < nb_measurements; i++) {
- char buffer[MAXBUF] = { 0 };
- sprintf (buffer, "ping %d", i);
+ char *msg = get_msg (MSGLEN);
pthread_mutex_lock (&mutex);
pthread_mutex_unlock (&mutex);
sys_timestamp (&ts1);
- if (write (fdout, buffer, strlen (buffer) + 1) == -1) {
+ if (write (fdout, msg, MSGLEN) == -1) {
fprintf (stderr, "ping error: write (%d)\n", i);
rc = 1;
pthread_exit (NULL);
/* depend: */
/* cflags: */
-/* linker: mtime.o test.o stat.o -lm -lrt */
+/* linker: msg.o mtime.o test.o stat.o -lm -lrt */
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
+#include "msg.h"
#include "mtime.h"
#include "test.h"
void (*usage_ext) (FILE *) = NULL;
int (*parse_arg_ext) (char *) = NULL;
+#define MSGLEN 128
#define MAXBUF 1024
int ping (int fdin, int fdout)
printf ("Sending ping...\n");
for (int i = 0; i < nb_measurements; i++) {
+ char *msg = get_msg (MSGLEN);
char buffer[MAXBUF] = { 0 };
- sprintf (buffer, "ping %d", i);
ts_t ts1;
sys_timestamp (&ts1);
- if (write (fdout, buffer, strlen (buffer) + 1) == -1) {
+ if (write (fdout, msg, MSGLEN) == -1) {
fprintf (stderr, "ping error: write (%d)\n", i);
return 1;
}
//printf ("write '%s'\n", buffer);
- if (read (fdin, buffer, sizeof(buffer)) == -1) {
+ if (read (fdin, buffer, sizeof(buffer) - 1) == -1) {
fprintf (stderr, "ping error: read (%d)\n", i);
return 1;
}
printf ("Responding pong...\n");
for (int i = 0; i < nb_measurements; i++) {
+ char *msg = get_msg (MSGLEN);
char buffer[MAXBUF] = { 0 };
- if (read (fdin, buffer, sizeof(buffer)) == -1) {
+ if (read (fdin, buffer, sizeof(buffer) - 1) == -1) {
fprintf (stderr, "ping error: read (%d)\n", i);
return 1;
}
//printf ("read '%s'\n", buffer);
- if (write (fdout, buffer, strlen (buffer) + 1) == -1) {
+ if (write (fdout, msg, MSGLEN) == -1) {
fprintf (stderr, "ping error: write (%d)\n", i);
return 1;
}
/* depend: */
/* cflags: */
-/* linker: mtime.o test.o stat.o -lm -lpthread -lrt */
+/* linker: msg.o mtime.o test.o stat.o -lm -lpthread -lrt */
#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <sys/socket.h>
+#include "msg.h"
#include "mtime.h"
#include "test.h"
}
int (*parse_arg_ext) (char *) = _parse_arg_ext;
+#define MSGLEN 128
#define MAXBUF 1024
#define TIMER 1000
for (int i = 0; i < nb_measurements; i++) {
- char buffer[MAXBUF] = { 0 };
- sprintf (buffer, "ping %d", i);
+ char *msg = get_msg (MSGLEN);
pthread_mutex_lock (&mutex);
pthread_mutex_unlock (&mutex);
sys_timestamp (&ts1);
- if (sendto (sock, buffer, strlen (buffer) + 1, 0, (struct sockaddr *)&remote, sizeof (remote)) == -1) {
+ if (sendto (sock, msg, MSGLEN, 0, (struct sockaddr *)&remote, sizeof (remote)) == -1) {
fprintf (stderr, "ping error: sendto (%d)\n", i);
rc = 1;
pthread_exit (NULL);
/* depend: */
/* cflags: */
-/* linker: mtime.o test.o stat.o -lm -lrt */
+/* linker: msg.o mtime.o test.o stat.o -lm -lrt */
#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <sys/socket.h>
+#include "msg.h"
#include "mtime.h"
#include "test.h"
}
int (*parse_arg_ext) (char *) = _parse_arg_ext;
+#define MSGLEN 128
#define MAXBUF 1024
int ping (int local_port, int remote_addr, int remote_port)
printf ("Sending ping...\n");
for (int i = 0; i < nb_measurements; i++) {
+ char *msg = get_msg (MSGLEN);
char buffer[MAXBUF] = { 0 };
- sprintf (buffer, "ping %d", i);
ts_t ts1;
sys_timestamp (&ts1);
- if (sendto (sock, buffer, strlen (buffer) + 1, 0, (struct sockaddr *)&remote, sizeof (remote)) == -1) {
+ if (sendto (sock, msg, MSGLEN, 0, (struct sockaddr *)&remote, sizeof (remote)) == -1) {
fprintf (stderr, "ping error: sendto (%d)\n", i);
return 1;
}
//printf ("sendto '%s'\n", buffer);
- int len = recv (sock, buffer, MAXBUF, 0);
+ int len = recv (sock, buffer, sizeof (buffer) - 1, 0);
if (len == -1) {
fprintf (stderr, "ping error: recv_from (%d)\n", i);
return 1;
printf ("Sending pong...\n");
for (int i = 0; i < nb_measurements; i++) {
+ char *msg = get_msg (MSGLEN);
char buffer[MAXBUF] = { 0 };
- int len = recv (sock, buffer, MAXBUF, 0);
+ int len = recv (sock, buffer, sizeof (buffer) - 1, 0);
if (len == -1) {
fprintf (stderr, "pong error: recv_from (%d)\n", i);
return 1;
}
//printf ("recv_from '%s'\n", buffer);
- if (sendto (sock, buffer, len, 0, (struct sockaddr *)&remote, sizeof (remote)) == -1) {
+ if (sendto (sock, msg, MSGLEN, 0, (struct sockaddr *)&remote, sizeof (remote)) == -1) {
fprintf (stderr, "pong error: sendto (%d)\n", i);
return 1;
}