Plz take a look at the code in my main function:
Code:
init_parameters(¶meters);
parse_config(¶meters);
send_diff(¶meters,qdisc_stats);
reset_server((void *)NULL);
configure((void *)NULL,"add"); /*Configure initially the diffserv */
// configure((void *)NULL,"change"); /*Configure initially the diffserv */
sleep(3);
if (pthread_create(&thread_id[0],NULL,init_diffserv,NULL)>0)
printf("Error creating thread \n");
if (pthread_create(&thread_id[1],NULL,reconfigure,NULL)>0)
printf("Error creating thread \n");
if (pthread_join(thread_id[0],(void **) p_status) >0)
perror("Error joining diffserv thread");
if (pthread_join(thread_id[1],(void **) p_status) >0)
perror("Error joining reconfigure thread");
printf("Lalalala");
return 0;
}
The function send_diff(¶meters,qdisc_stats)is implemented like that
Code:
void send_diff(struct configuration *diff,union qdisc *qdisc){
int sock,n;
socklen_t server_len;
struct sockaddr_in server,client;
struct hostent *host;
if (!(host=gethostbyname(DIFFSERV))){ //?? Huge problem how to read value from file
perror("Client gethostname");
}
memset(&server,0,sizeof(server));
server.sin_family= AF_INET;
memcpy(&server.sin_addr,host->h_addr,host->h_length);
server.sin_port=htons((9997));
if ((sock=socket(PF_INET, SOCK_DGRAM, 0)) < 0){
perror("Client socket ");
}
memset(&client,0,sizeof(client));
client.sin_family = AF_INET;
client.sin_addr.s_addr = htonl(INADDR_ANY);
client.sin_port = htons(9997);
if ( bind(sock, (struct sockaddr *) &client, sizeof(client)) <0){
perror("Client bind ");
}
server_len=sizeof(server);
printf("To i exei timi %d \n",i);
if (sendto( sock, diff , sizeof(struct configuration), 0,(struct sockaddr *) &server, server_len) <0){
perror("Client send to");
close(sock);
}
if (sendto( sock, qdisc, sizeof(qdisc_stats[10]), 0, (struct sockaddr *) &server, server_len) <0){
perror("Client send to");
close(sock);
}
printf("Finished sending structs \n");
close(sock);
}
As u can easily see use two times the sendto system call. Using tcpdump -i eth0 -vvv -n port 9997 (filter for the specific post)
I have noticed that my programme NOT always send packets to the network.. The packets are not created... Firewall is shut down... Sometimes the packets are created and some others not...
What should i do?