Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C/C++ - Socket da 64bit a 32bit problema
Forum - C/C++ - Socket da 64bit a 32bit problema

Avatar
mberny88 (Normal User)
Newbie


Messaggi: 6
Iscritto: 30/07/2012

Segnala al moderatore
Postato alle 14:15
Martedì, 31/07/2012
Ho scritto un'applicazione in c++ che permette di inviare pacchetti da una porta (dove è attaccato un device rfid) e l'ethernet.
L'applicazione scritta su 64bit mi funziona ma per motivi di tesi devo portarla su un pc a 32 bit. La parte di codice che mi dà fastidio è la seguente:


while(1) {

    try {
        
            length_receive=recvfrom(par->sock2.fd, buffer,BUFFER_LENGTH,0,
                                (struct sockaddr*)par->address2.address,
                                &par->address2.address_length);

            if(length_receive==-1) {throw RecvfromException ();}
        
        } catch (RecvfromException e) {e.getDescription ();}
        std::cout <<"Ricevuto il pacchetto dall'interfaccia'\n"<<std::endl;

        IPv6Packet packet=IPv6Packet (buffer,length_receive);
        packet.printInEx (' ');
        std::cout <<"Lunghezza:"<< length_receive << std::endl;


        try {
            
            length_send=sendto(par->sock1.fd, buffer,length_receive,0,
                               (const struct sockaddr*)par->address1.address,
                              par->address1.address_length);
    
            if(length_send==-1) {throw SendToException ();}

        } catch(SendToException e) {e.getDescription ();}
        std::cout << "Rispedito al sunspot\n"<<std::endl;
[\code]

una volta che parte la prima recvfrom, il while gira e incomincia a inviare pacchetti che non sono inviati. È come se il buffer invia i pacchetti precedenti insieme a quello nuovo. Questo solo nella 32bit. È un problema di compilatore? Come posso risovlvere?

PM Quote
Avatar
pierotofy (Admin)
Guru^2


Messaggi: 6230
Iscritto: 04/12/2003

Segnala al moderatore
Postato alle 17:28
Martedì, 31/07/2012
Non e' tutto il codice... potresti allegare il codice completo?


Il mio blog: https://piero.dev
PM Quote
Avatar
mberny88 (Normal User)
Newbie


Messaggi: 6
Iscritto: 30/07/2012

Segnala al moderatore
Postato alle 20:37
Martedì, 31/07/2012
Codice sorgente - presumibilmente C++

  1. void SunTunnel::send_deviceToport (SunParameter* par) {
  2.  
  3.                 int length_send;
  4.                 int length_receive;
  5.                 void* buffer;
  6.  
  7.                 buffer=malloc(BUFFER_LENGTH);
  8.  
  9.         printf("Ho iniziato il tunnel tra interfaccia e sunspot\n \n");
  10.         while(1) {
  11.  
  12.                 try {
  13.                
  14.                         length_receive=recvfrom(par->sock2.fd, buffer,BUFFER_LENGTH,0,
  15.                                             (struct sockaddr*)par->address2.address,
  16.                                         &par->address2.address_length);
  17.  
  18.                         if(length_receive==-1) {throw RecvfromException ();}
  19.                
  20.                 } catch (RecvfromException e) {e.getDescription ();}
  21.                 std::cout <<"Ricevuto il pacchetto dall'interfaccia'\n"<<std::endl;
  22.  
  23.                 IPv6Packet packet=IPv6Packet (buffer,length_receive);
  24.                 packet.printInEx (' ');
  25.                 std::cout <<"Lunghezza:"<< length_receive << std::endl;
  26.  
  27.  
  28.                 try {
  29.                        
  30.                         length_send=sendto(par->sock1.fd, buffer,length_receive,0,
  31.                                            (const struct sockaddr*)par->address1.address,
  32.                                       par->address1.address_length);
  33.        
  34.                         if(length_send==-1) {throw SendToException ();}
  35.  
  36.                 } catch(SendToException e) {e.getDescription ();}
  37.                 std::cout << "Rispedito al sunspot\n"<<std::endl;
  38.         }
  39. }



Questo è tutto il codice del metodo che mi dà problemi!!! Sul 64 bit funziona a dovere sul 32 bit una volta ricevuto il primo pacchetto incomincia a stamparne tanti altri senza che vengano inviati. Se servono altre classi dite ma ho cercato di debuggare tutto e ho scoperto che il problema è nella sendto se la commento (nel 32 bit) la recvfrom riceve solamente i pacchetti che effettivamente devono essere ricevuto e non stampa nulla di più!!!

PM Quote