+#define _POSIX_C_SOURCE 200112L
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#define __USE_XOPEN_EXTENDED
+#define __USE_MISC
#include <arpa/inet.h>
#include <time.h>
#include <errno.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
-#include <sys/types.h>
#include <linux/ip.h>
#include <linux/udp.h>
#include <unistd.h>
} 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
{
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);
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;
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);
break;
case 'm' :
max_packets = atoi(optarg);
- if (packet_length < 64)
+ if (max_packets < 50)
{
printf("You must send at least 50 packets.\n");
return -1;
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);
// 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)
return -1;
}
printf("Received ");
- r = parsecontrol(packet, l);
+ r = parsecontrol((char *) packet, l);
if (!r->first)
{
printf("Invalid packet.. no first avp\n");
printf("All session create requests sent...\n");/*}}}*/
if ( fork() == 0) {
- reader_thread(udpfd);
+ reader_thread();
exit(0);
}
*(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);
nanosleep(&req, NULL);
}
- if (max_packets && ss->send_count >= max_packets) ss->quitit++;
+ if (max_packets && ss->send_count >= max_packets)
+ ss->quitit++;
}
}
}
}/*}}}*/
-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++)
{
// }}}
-void reader_thread(int updfd)/*{{{*/
+void reader_thread()/*{{{*/
{
unsigned char *packet;
unsigned int seq = 0;
while (!ss->quitit)
{
struct sockaddr_in addr;
- int alen = sizeof(addr);
+ socklen_t alen = sizeof(addr);
control_message *m;
int l;
int s;
{
// Control Packet
printf("Reader Received ");
- m = parsecontrol(packet, l);
+ m = parsecontrol((char *) packet, l);
printf("\n");
s = m->session;
if (protocol != PPPIP)
{
printf("Received ");
- dump_ppp_packet(packet + 6, l - 6);
+ dump_ppp_packet((char *) (packet + 6), l - 6);
}
if (protocol == PPPLCP)
controlfree(r);
break;
case CONFNAK :
- // Ack whatever address we are given - it's ours
- r = ppp_ipcp(s, CONFACK, time(NULL) % 255);
- ppp_lcp_add_option(r, 3, 4, address); // Request 0.0.0.0
+ // Request whatever address we are given - it's ours
+ r = ppp_ipcp(s, CONFREQ, time(NULL) % 255);
+ ppp_lcp_add_option(r, 3, 4, address);
ppp_send(r);
controlfree(r);
printf("Session %d: %s\n", s, inet_toa(address));
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.
}
}
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);