mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
code cleanup
git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@42 8ec27952-4edc-4aab-86aa-e87bb2611832
This commit is contained in:
parent
ab79460f71
commit
facadafb2e
3 changed files with 43 additions and 32 deletions
|
@ -33,14 +33,15 @@ int main(int argc, char *argv[])
|
|||
struct sockaddr_in sa;
|
||||
|
||||
if (argc != 2) {
|
||||
printf("Usage: %s IP:PORT\n", argv[0]);
|
||||
printf(" IP is the destination ip of our packets\n");
|
||||
printf(" PORT is the port to receive from\n\n");
|
||||
printf("Usage: %s LOCAL\n", argv[0]);
|
||||
printf(" LOCAL is a IP:PORT combination of the local host\n\n");
|
||||
printf("s2ss Simulator2Simulator Server v%s\n", VERSION);
|
||||
printf("Copyright 2014, Institute for Automation of Complex Power Systems, EONERC\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
const char *local_str = argv[1];
|
||||
|
||||
/* Setup signals */
|
||||
struct sigaction sa_quit = {
|
||||
.sa_flags = SA_SIGINFO,
|
||||
|
@ -52,8 +53,10 @@ int main(int argc, char *argv[])
|
|||
sigaction(SIGINT, &sa_quit, NULL);
|
||||
|
||||
/* Resolve address */
|
||||
if (resolve(argv[1], &sa, 0))
|
||||
error("Failed to resolve: %s", argv[1]);
|
||||
struct sockaddr_in local;
|
||||
|
||||
if (resolve(local_str, &local, 0))
|
||||
error("Failed to resolve local address: %s", local_str);
|
||||
|
||||
/* Create socket */
|
||||
sd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
@ -61,7 +64,7 @@ int main(int argc, char *argv[])
|
|||
perror("Failed to create socket");
|
||||
|
||||
/* Bind socket */
|
||||
if (bind(sd, (struct sockaddr *) &sa, sizeof(struct sockaddr_in)))
|
||||
if (bind(sd, (struct sockaddr *) &local, sizeof(struct sockaddr_in)))
|
||||
perror("Failed to bind to socket");
|
||||
|
||||
struct msg m;
|
||||
|
|
19
src/send.c
19
src/send.c
|
@ -33,14 +33,15 @@ int main(int argc, char *argv[])
|
|||
struct sockaddr_in sa;
|
||||
|
||||
if (argc != 2) {
|
||||
printf("Usage: %s IP:PORT\n", argv[0]);
|
||||
printf(" IP is the destination ip of our packets\n");
|
||||
printf(" PORT is the port to send to\n\n");
|
||||
printf("Usage: %s REMOTE\n", argv[0]);
|
||||
printf(" REMOTE is a IP:PORT combination of the remote host\n\n");
|
||||
printf("s2ss Simulator2Simulator Server v%s\n", VERSION);
|
||||
printf("Copyright 2014, Institute for Automation of Complex Power Systems, EONERC\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
const char *remote_str = argv[1];
|
||||
|
||||
/* Setup signals */
|
||||
struct sigaction sa_quit = {
|
||||
.sa_flags = SA_SIGINFO,
|
||||
|
@ -51,14 +52,16 @@ int main(int argc, char *argv[])
|
|||
sigaction(SIGTERM, &sa_quit, NULL);
|
||||
sigaction(SIGINT, &sa_quit, NULL);
|
||||
|
||||
/* Resolve address */
|
||||
if (resolve(argv[1], &sa, 0))
|
||||
error("Failed to resolve: %s", argv[1]);
|
||||
/* Resolve addresses */
|
||||
struct sockaddr_in remote;
|
||||
|
||||
if (resolve(remote_str, &remote, 0))
|
||||
error("Failed to resolve remote address: %s", remote_str);
|
||||
|
||||
/* Create socket */
|
||||
sd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (sd < 0)
|
||||
error("Failed to create socket: %s", strerror(errno));
|
||||
perror("Failed to create socket");
|
||||
|
||||
// TODO: remove workaround
|
||||
struct msg msg = {
|
||||
|
@ -66,7 +69,7 @@ int main(int argc, char *argv[])
|
|||
};
|
||||
|
||||
/* Connect socket */
|
||||
if (connect(sd, (struct sockaddr *) &sa, sizeof(struct sockaddr_in)))
|
||||
if (connect(sd, (struct sockaddr *) &remote, sizeof(struct sockaddr_in)))
|
||||
perror("Failed to connect socket");
|
||||
|
||||
while (!feof(stdin)) {
|
||||
|
|
41
src/test.c
41
src/test.c
|
@ -26,18 +26,20 @@ void quit(int sig, siginfo_t *si, void *ptr)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct sockaddr_in sa;
|
||||
|
||||
if (argc != 3) {
|
||||
printf("Usage: %s TEST IP:PORT\n", argv[0]);
|
||||
printf(" TEST has to be 'latency' for now\n");
|
||||
printf(" IP is the destination ip of our packets\n");
|
||||
printf(" PORT is the port to send to\n\n");
|
||||
if (argc != 3 && argc != 4) {
|
||||
printf("Usage: %s TEST REMOTE [LOCAL]\n", argv[0]);
|
||||
printf(" TEST has to be 'latency' for now\n");
|
||||
printf(" REMOTE is a IP:PORT combination of the remote host\n");
|
||||
printf(" LOCAL is a IP:PORT combination of the remote host\n\n");
|
||||
printf("s2ss Simulator2Simulator Server v%s\n", VERSION);
|
||||
printf("Copyright 2014, Institute for Automation of Complex Power Systems, EONERC\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
const char *test = argv[1];
|
||||
const char *remote_str = argv[2];
|
||||
const char *local_str = (argc == 4) ? argv[3] : NULL;
|
||||
|
||||
/* Setup signals */
|
||||
struct sigaction sa_quit = {
|
||||
.sa_flags = SA_SIGINFO,
|
||||
|
@ -48,9 +50,15 @@ int main(int argc, char *argv[])
|
|||
sigaction(SIGTERM, &sa_quit, NULL);
|
||||
sigaction(SIGINT, &sa_quit, NULL);
|
||||
|
||||
/* Resolve address */
|
||||
if (resolve(argv[2], &sa, 0))
|
||||
error("Failed to resolve: %s", argv[2]);
|
||||
/* Resolve addresses */
|
||||
struct sockaddr_in remote;
|
||||
struct sockaddr_in local;
|
||||
|
||||
if (resolve(remote_str, &remote, 0))
|
||||
error("Failed to resolve remote address: %s", remote_str);
|
||||
|
||||
if (resolve(local_str, &local, 0))
|
||||
error("Failed to resolve local address: %s", local_str);
|
||||
|
||||
/* Create socket */
|
||||
sd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
@ -58,17 +66,14 @@ int main(int argc, char *argv[])
|
|||
perror("Failed to create socket");
|
||||
|
||||
/* Bind socket */
|
||||
if (bind(sd, (struct sockaddr *) &sa, sizeof(struct sockaddr_in)))
|
||||
error("Failed to bind socket: %s", strerror(errno));
|
||||
if (bind(sd, (struct sockaddr *) &local, sizeof(struct sockaddr_in)))
|
||||
perror("Failed to bind to socket");
|
||||
|
||||
/* Connect socket */
|
||||
sa.sin_port = htons(ntohs(sa.sin_port) + 1);
|
||||
if (connect(sd, (struct sockaddr *) &sa, sizeof(struct sockaddr_in))) {
|
||||
error("Failed to connect socket: %s", strerror(errno));
|
||||
}
|
||||
if (connect(sd, (struct sockaddr *) &remote, sizeof(struct sockaddr_in)))
|
||||
perror("Failed to connect socket");
|
||||
|
||||
|
||||
if (!strcmp(argv[1], "latency")) {
|
||||
if (!strcmp(test, "latency")) {
|
||||
struct msg m2, m1 = {
|
||||
.device = 99,
|
||||
.sequence = 0
|
||||
|
|
Loading…
Add table
Reference in a new issue