LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-25-2005, 10:20 AM   #1
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Rep: Reputation: 45
buggy c codrPlP


Plz take a look at the following code

Code:
void send_diff(struct configuration *diff,union qdisc *qdisc){

        int                     sock,n,temp,sock2,n2,counter;
        socklen_t               server_len,server_len2;
        struct sockaddr_in      server,client,server2,client2;
        struct hostent          *host,*host2;

        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);

        for (counter=0;counter<5;counter++){
                if (sendto( sock, diff , sizeof(struct configuration), 0,(struct sockaddr *) &server, server_len) <0){
                        perror("Client send to");
                        close(sock);
                }
                sleep(5);
        }

        close(sock);
        sleep(10);
        server2.sin_family= AF_INET;
        memcpy(&server2.sin_addr,host->h_addr,host->h_length);
        server2.sin_port=htons((9990));
        if ((sock2=socket(PF_INET, SOCK_DGRAM, 0)) < 0){
                perror("Client socket ");
        }
                         
 memset(&client2,0,sizeof(client));
        client2.sin_family       = AF_INET;
        client2.sin_addr.s_addr  = htonl(INADDR_ANY);
        client2.sin_port         = htons(9990);

        if ( bind(sock2, (struct sockaddr *) &client2, sizeof(client2)) <0){
                perror("Client bind ");
        }
        server_len2=sizeof(server2);
        for(counter=0;counter<5;counter++){
                printf("Mesa sti loop \n");
                if (sendto( sock2, qdisc_stats, sizeof(qdisc_stats), 0, (struct sockaddr *) &server2, server_len2) <0){
                        perror("Client send to");
                        close(sock2);
                }
                sleep(5);
        }
        for(temp=0;temp<3;temp++){
                printf("Stelno rate %s \n",qdisc_stats[temp].htbstats.rate);
                printf("Stelno ceil %s \n",qdisc_stats[temp].htbstats.ceil);

        }
        printf("Finished sending structs \n");
        close(sock2);

}
As u can see this code has two parts... Each part sends five time a message to a given port... When i restart the pc this code works FINE!!!! which means that i send and receive packets as well... This is only for the first time... When i retry to execute this programme only the first part works fine.... the second one DOESNOT SEND ANYTHING (checked with tcpdump) and not print error with the perror function.... I dont know why..... I have checked this many times (i am bored restarting my pc) Plz check the code... perhaps i reserve a resource that i dont release so i cannot reuse it....(just suggestions)
Do u have anything else i mind?
 
Old 09-25-2005, 06:11 PM   #2
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Original Poster
Rep: Reputation: 45
Hmmm i have spend a few hours with this prob!!! Stil not working
I am still asking why this thing works only for one time and not for a second one ( shit!!!
I have thought to use the gdb to check it out... but i dont think that debugger can execute step by step the sendto(... ) system call .. I think that the problem relies for sth that my programmes use and dont release after it is killed... I dont know if u agree or nor.. but suggest everything u can think and i am here to test it
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Buggy 10.2 with KDE Nichole_knc Slackware 3 10-01-2005 03:46 PM
buggy c code? alaios Programming 2 09-23-2005 06:25 PM
are gdeskletes really buggy? gulo General 2 03-26-2005 12:25 PM
Least buggy distribution? mark_2811 Linux - General 2 11-04-2003 05:30 AM
I know this isn't a buggy bios DarkXtar Slackware 1 04-19-2003 03:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration