From: Brendan O'Dea Date: Mon, 18 Dec 2006 11:58:35 +0000 (+0000) Subject: add Makefile, cleanup for -std=c99 X-Git-Tag: 2.2.1-2fdn3.1~19^2^2~1^2~15 X-Git-Url: http://git.sameswireless.fr/l2tpns.git/commitdiff_plain/36ddde96e1e6a58889663b06c24d78e03afc5c3f?ds=inline;hp=c2152aa3785766ff9623b5de63e6dcd1f934dcac add Makefile, cleanup for -std=c99 --- diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..ae9b79f --- /dev/null +++ b/test/Makefile @@ -0,0 +1,11 @@ +CFLAGS = -g -Wall -W -std=c99 -pedantic +TARGETS = bounce generateload radius + +all: $(TARGETS) +clean: + rm -f $(TARGETS) + +../md5.o: ../md5.c ../md5.h + $(MAKE) -C .. md5.o + +radius: radius.c ../md5.o diff --git a/test/bounce.c b/test/bounce.c index 5443b67..269d6c9 100644 --- a/test/bounce.c +++ b/test/bounce.c @@ -68,7 +68,8 @@ int main(int argc, char *argv[]) while (1) { struct sockaddr_in addr; - int alen = sizeof(addr), l; + socklen_t alen = sizeof(addr); + int l; unsigned int iseq; l = recvfrom(s, packet, 65535, 0, (void *) &addr, &alen); @@ -87,7 +88,7 @@ int main(int argc, char *argv[]) free(packet); } -void sigalarm(int junk) +void sigalarm(int unusedg __attribute__ ((unused))) { printf("Recv: %10llu %0.1fMbits/s (%lu pps) (%5ld dropped)\n", recv_count, (bytes / 1024.0 / 1024.0 * 8), pps, dropped); pps = bytes = 0; diff --git a/test/generateload.c b/test/generateload.c index 0b32199..b671b4f 100644 --- a/test/generateload.c +++ b/test/generateload.c @@ -1,3 +1,9 @@ +#define _POSIX_C_SOURCE 200112L +#include +#include +#include +#define __USE_XOPEN_EXTENDED +#define __USE_MISC #include #include #include @@ -6,11 +12,8 @@ #include #include #include -#include -#include #include #include -#include #include #include #include @@ -179,10 +182,10 @@ typedef struct } control_message; typedef struct { -unsigned long long send_count , recv_count ; -unsigned long long spkt , rpkt ; -unsigned int dropped; -unsigned long sbytes , rbytes ; +long long send_count, recv_count; +long long spkt, rpkt ; +int dropped; +long sbytes, rbytes ; int quitit; struct sessiont { @@ -210,7 +213,7 @@ void dump_control_message(control_message *c); u32 avp_get_32(control_message *c, int id); u16 avp_get_16(control_message *c, int id); char *avp_get_s(control_message *c, int id); -void reader_thread(int udpfd); +void reader_thread(void); void skip_zlb(); void cm_free(control_message *m); controlt *ppp_new(u16 session, int protocol); @@ -234,7 +237,7 @@ void print_report(); int ns = 0, nr = 0; int udpfd; int t = 0; -struct sockaddr_in gatewayaddr = {0}; +struct sockaddr_in gatewayaddr; int numsessions = NUM_SESSIONS; int packet_length = PACKET_LENGTH; int target_pps = TARGET_PPS; @@ -251,7 +254,7 @@ char *suffix = "@optusnet.com.au"; int main(int argc, char *argv[]) { int s; - char *packet; + unsigned char *packet; ss = (sharedt*) mmap(NULL, sizeof(*ss), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); @@ -377,6 +380,7 @@ int main(int argc, char *argv[]) printf("Bound to port %d\n", htons(addr.sin_port)); }/*}}}*/ + memset(&gatewayaddr, 0, sizeof(gatewayaddr)); gatewayaddr.sin_family = AF_INET; gatewayaddr.sin_port = htons(1701); inet_aton(gwaddr, &gatewayaddr.sin_addr); @@ -400,7 +404,8 @@ int main(int argc, char *argv[]) // Receive reply/*{{{*/ { struct sockaddr_in addr; - int alen = sizeof(addr), l; + int l; + socklen_t alen = sizeof(addr); l = recvfrom(udpfd, packet, 4096, 0, (void *) &addr, &alen); if (l < 0) @@ -409,7 +414,7 @@ int main(int argc, char *argv[]) return -1; } printf("Received "); - r = parsecontrol(packet, l); + r = parsecontrol((char *) packet, l); if (!r->first) { printf("Invalid packet.. no first avp\n"); @@ -446,7 +451,7 @@ int main(int argc, char *argv[]) printf("All session create requests sent...\n");/*}}}*/ if ( fork() == 0) { - reader_thread(udpfd); + reader_thread(); exit(0); } @@ -529,7 +534,7 @@ int main(int argc, char *argv[]) *(u16 *)(c->buf + 4) = htons(ss->sessions[i].remote_session); // Session ID iph->saddr = ss->sessions[i].addr; iph->check = 0; - iph->check = ntohs(checksum((char *)iph, sizeof(struct iphdr))); + iph->check = ntohs(checksum((unsigned char *)iph, sizeof(struct iphdr))); *((unsigned int *) data) = seq++; ppp_send(c); @@ -546,7 +551,8 @@ int main(int argc, char *argv[]) nanosleep(&req, NULL); } - if (max_packets && ss->send_count >= max_packets) ss->quitit++; + if (max_packets && ss->send_count >= max_packets) + ss->quitit++; } } @@ -602,22 +608,24 @@ void clean_shutdown()/*{{{*/ } }/*}}}*/ -void sigint(int signal) +void sigint(int unused __attribute__ ((unused))) { ss->quitit++; } -void sigalarm(int junk) +void sigalarm(int unused __attribute__ ((unused))) { static unsigned long long last_rpkts[AVG_SIZE], last_spkts[AVG_SIZE]; static int last = 0, avg_count = 0; - register unsigned int avg_s = 0, avg_r = 0, i; + unsigned int avg_s = 0, avg_r = 0; + int i; float loss; last_rpkts[last] = ss->rpkt; last_spkts[last] = ss->spkt; last = (last + 1) % AVG_SIZE; - if (avg_count < AVG_SIZE) avg_count++; + if (avg_count < AVG_SIZE) + avg_count++; for (i = 0; i < avg_count; i++) { @@ -867,7 +875,7 @@ void cm_free(control_message *m) // }}} -void reader_thread(int updfd)/*{{{*/ +void reader_thread()/*{{{*/ { unsigned char *packet; unsigned int seq = 0; @@ -877,7 +885,7 @@ void reader_thread(int updfd)/*{{{*/ while (!ss->quitit) { struct sockaddr_in addr; - int alen = sizeof(addr); + socklen_t alen = sizeof(addr); control_message *m; int l; int s; @@ -906,7 +914,7 @@ void reader_thread(int updfd)/*{{{*/ { // Control Packet printf("Reader Received "); - m = parsecontrol(packet, l); + m = parsecontrol((char *) packet, l); printf("\n"); s = m->session; @@ -975,7 +983,7 @@ void reader_thread(int updfd)/*{{{*/ if (protocol != PPPIP) { printf("Received "); - dump_ppp_packet(packet + 6, l - 6); + dump_ppp_packet((char *) (packet + 6), l - 6); } if (protocol == PPPLCP) @@ -1073,13 +1081,13 @@ void reader_thread(int updfd)/*{{{*/ if (iph->protocol == 17) { - int iseq; + unsigned int iseq; ss->recv_count++; ss->rpkt++; iseq = *((unsigned int *) data); - if (seq != iseq) { + if (seq != iseq) ss->dropped += (iseq - seq) ; - } + seq = iseq + 1; // Next sequence number to expect. } } @@ -1095,7 +1103,7 @@ void reader_thread(int updfd)/*{{{*/ void skip_zlb() /*{{{*/ { struct sockaddr_in addr; - int alen = sizeof(addr); + socklen_t alen = sizeof(addr); char buf[1024]; int l; l = recvfrom(udpfd, buf, 1024, MSG_PEEK, (void *) &addr, &alen);