From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (qmail 25797 invoked from network); 19 May 1999 10:02:21 -0000 Received: from mail.redhat.com (199.183.24.239) by lists.redhat.com with SMTP; 19 May 1999 10:02:21 -0000 Received: from gatekeeper.px.uk.com ([62.232.19.200]) by mail.redhat.com (8.8.7/8.8.7) with ESMTP id FAA20346 for ; Wed, 19 May 1999 05:23:31 -0400 Received: from ashton (ashton.px.uk.com [172.16.17.14]) by gatekeeper.px.uk.com (8.9.3/8.9.3) with SMTP id KAA08759 for ; Wed, 19 May 1999 10:23:29 +0100 Message-Id: <3.0.6.32.19990519102329.00d4d970@proxy.px.uk.com> X-Sender: treblig#pop3.demon.co.uk@proxy.px.uk.com X-Mailer: QUALCOMM Windows Eudora Light Version 3.0.6 (32) Date: Wed, 19 May 1999 10:23:29 +0100 To: axp-list@redhat.com From: "Dr . David Alan Gilbert" Subject: Re: Converting time (since 01-01-1970) to Epoch In-Reply-To: <9905190951.ZM11753@dns.rgn.it> References: <199905181613.KAA20322@ellpspace.math.ualberta.ca> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" At 09:51 19/05/99 +0000, Franco Tassone wrote: >I have a binary file with record fixed lenght, it has been written on an SGI >box (Irix 6.2) using the following structure: > >(/usr/include/rpcsvc/rusers.h) > >struct rusers_utmp { > char ut_line[8]; /* tty name */ > char ut_name[8]; /* user id */ > char ut_host[16]; /* host name, if remote */ > long ut_time; /* time on */ >}; > >For the SGI box, sizeof(long) = 4. > > >So I've converted the file, rewriting all the records on an Alpha-Linux box >(kernel 2.2.7) using the following structure: > >(/usr/include/rpcsvc/rusers.h) > >struct ru_utmp { > char ut_line[8]; /* tty name */ > char ut_name[8]; /* user id */ > char ut_host[16]; /* host name, if remote */ > long ut_time; /* time on */ >}; > >For Alpha-Linux box, sizeof(long) = 8. >My conversion program does only a field's level assignments, and rewrites the >new file, due to different sizeof(long). >The resulting dates (ut_time in ru_utmp) are all garbled. >Any ideas ? I suggest the problem is not length; but is actually an endian problem. SGI's are big endian (i.e. the first byte is the most significant), where as Linux/Alpha runs as little endian (i.e. the first byte is the least significant). I'd have something like: struct fromsgi_rusers { char ut_line[8]; char ut_name[8]; char ut_host[16]; char ut_time_hack[4]; } use that to read it in and then make: myru_utmp.ut_time=fromsg.ut_time_hack[3] | (fromsg.ut_time_hack[2]<<8) ..... Dave