Oppure

Loading
31/07/12 12:15
mberny88
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?
aaa
31/07/12 15:28
pierotofy
Non e' tutto il codice... potresti allegare il codice completo?
Il mio blog: piero.dev
31/07/12 18:37
mberny88
void SunTunnel::send_deviceToport (SunParameter* par) {

		int length_send;
		int length_receive;
		void* buffer;

		buffer=malloc(BUFFER_LENGTH);

	printf("Ho iniziato il tunnel tra interfaccia e sunspot\n \n");
	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;
	}
}


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ù!!!
aaa