Commit 7bd835d9 authored by Joanne Hugé's avatar Joanne Hugé

Clean and rename client and server files

parent 471ae88b
......@@ -25,6 +25,8 @@ typedef struct thread_param {
thread_stat_t stats;
} thread_param_t;
static void process_options(int argc, char *argv[], thread_param_t * param);
// Real-time thread
// Sends packets at a regular intervall
......@@ -60,6 +62,35 @@ static void *packet_sending_thread(void *p) {
return NULL;
}
// Main thread, has non-real time priority
// Handles the IO and creates real time threads
int main(int argc, char *argv[]) {
pthread_t thread;
thread_param_t param;
// Default values
param.interval = 1;
param.max_cycles = -1;
param.priority = 99;
process_options(argc, argv, &param);
if(pthread_create(&thread, NULL, packet_sending_thread, (void *)&param))
error(EXIT_FAILURE, errno, "Couldn't create thread");
for (;;) {
usleep(100000);
printf("Nb cycles: %d\n", param.stats.nb_cycles);
if( param.max_cycles == param.stats.nb_cycles )
break;
}
exit(EXIT_SUCCESS);
}
static void process_options(int argc, char *argv[], thread_param_t * param) {
for(;;) {
......@@ -92,35 +123,3 @@ static void process_options(int argc, char *argv[], thread_param_t * param) {
param->ip_address = argv[optind];
}
// Main thread, has non-real time priority
// Handles the IO and creates real time threads
int main(int argc, char *argv[]) {
pthread_t thread;
thread_param_t param;
// Default values
param.interval = 1;
param.max_cycles = -1;
param.priority = 80;
process_options(argc, argv, &param);
int err =
pthread_create(&thread, NULL, packet_sending_thread, (void *)&param);
if(err)
error(EXIT_FAILURE, errno, "Couldn't create thread");
for (;;) {
usleep(100000);
printf("Nb cycles: %d\n", param.stats.nb_cycles);
if( param.max_cycles == param.stats.nb_cycles )
break;
}
exit(EXIT_SUCCESS);
}
#include "getip.h"
#include <ifaddrs.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
void print_ifs(void) {
struct ifaddrs* ifap;
getifaddrs(&ifap);
printf("Interfaces:\n\n");
for (struct ifaddrs* cur_ifap = ifap; cur_ifap;
cur_ifap = cur_ifap->ifa_next) {
printf("%s, ", cur_ifap->ifa_name);
void * addr;
char * ipver;
char ipstr[INET6_ADDRSTRLEN];
struct sockaddr * sa = cur_ifap->ifa_addr;
if( sa->sa_family == AF_INET ) { // IPV4
struct sockaddr_in * ipv4 = (struct sockaddr_in *) sa;
addr = &(ipv4->sin_addr);
ipver = "IPv4";
} else {
struct sockaddr_in6 * ipv6 = (struct sockaddr_in6 *) sa;
addr = &(ipv6->sin6_addr);
ipver = "IPv6";
}
inet_ntop(sa->sa_family, addr, ipstr, sizeof ipstr);
printf(" %s: %s\n", ipver, ipstr);
}
freeifaddrs(ifap);
}
#ifndef GETIP_H
#define GETIP_H
void print_ifs(void);
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment