This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Problems when moving Ubuntu -> Cygwin

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
    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 <tab> timestamp <tab> sample)
       // timestamp is NTP format e.g. seconds since 1 Jan 1900
       sprintf(buf, "%d\t%u%010llu\t%d\n", i, secs, nsecs,
       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:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]