X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=BAYES_00,J_CHICKENPOX_73,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org MIME-Version: 1.0 Date: Thu, 26 Mar 2009 08:06:09 +0100 Message-ID: Subject: Problems when moving Ubuntu -> Cygwin From: Mikael Normark To: cygwin AT cygwin DOT com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Hi, I have an application which reads data from TCP/IP packets and writes it to a file. The program works fine on Ubuntu but now I need it to run on my laptop (Vista) so I built it in Cygwin (without problems). The packet data is read into a struct: -------------------------------------------------------------------------------- // Holdning the raw sample data and timestamp when // the sample was fetched. struct sample_t{ int sample; long long timestamp; }; // A package that will hold samples data over // the TCP transfer. struct sample_pkg_t{ unsigned int type; // Should always be PKG_SAMPLES unsigned int pkg_nr; // Counter increased for each package unsigned int nr_samples; // Should be same as ADC_SAMPLES_IN_PKG struct sample_t sample[SAMPLES_IN_PKG]; // The samples data }; -------------------------------------------------------------------------------- And the code where the data is written looks like this: for(si = 0; si < sample_pkg->nr_samples; si++){ timestamp = sample_pkg->sample[si].timestamp; unsigned int secs = (timestamp>>32); long long nsecs = ((timestamp>>17 & 0x7FFF) * 1000000000)/3277; //32768 // Save as a line with format (channel timestamp sample) // timestamp is NTP format e.g. seconds since 1 Jan 1900 sprintf(buf, "%d\t%u%010llu\t%d\n", i, secs, nsecs, sample_pkg->sample[si].sample); fwrite (buf , 1 , strlen(buf) , pFile ); } The program works fine on Ubuntu but when I run it in Cygwin (yes, built in Cygwin from source ;) the secs and nsecs values make no sense whatsoever. Typical Ubuntu output: 0 34451499217497700000 24215 0 34451499217689300000 23418 0 34451499217908100000 23022 0 34451499218099400000 22887 0 34451499218291100000 23083 0 34451499218482400000 23956 0 34451499218701200000 22929 0 34451499218892500000 23706 Typical Cygwin output: 0 20601241600000000000 1883963392 0 14987793713 1 0 256220000000000 25221 0 24007802880000000000 -1976369152 0 15780897162 1 0 257650000000000 23954 0 27414364160000000000 -1635713024 0 16574000610 1 0 250970000000000 24616 First thing that came to my mind was endianness, after doing a simple test I determined that both computers are little endian as expected. As the data in the IP packet is big endian (right?) I wonder if there is any difference between Ubuntu/Cygwin in how (or IF) they handle the transition before the data reaches the application? Any input on what the problem could be, or on how to determine what the problem is, is greatly appreciated. Best Regards, Mikael Normark -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/