473,506 Members | 17,000 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

expanding c code to be "more cross-platform"

I'm responsible for supporting some C code which implements one time
passwords.

The author of the code is no longer available for help.

The code has been used for years on a sparc solaris platform.

However...

Now I need it to work on Linux Intel.

The behavior I am seeing is this.

I compiled this C code on Linux, using gcc, and it compiled without
complaint. I know that part of the code converts things into a hex
string from a long (and converts from the hex string into a long).

When I run a "build key" option of software using this code, it is
passed an IP address (for illustration, lets say"123.45.67.890").

A otp is generated.

Then, the command is issued with a flag that says "list the
information".
What it prints is
890.67.45.123

Now, what I am looking for are hints and tips on how to go about
generating things so that a command on either of the platforms will be
able to read and interpret correctly the information.

In other words, the data generated has to be readable across
platforms.

Are there some tutorials or guidelines for doing this sort of thing?

Jul 27 '07 #1
6 1217
lvirden <lv*****@gmail.comwrites:
I'm responsible for supporting some C code which implements one time
passwords.

The code has been used for years on a sparc solaris platform.

However...

Now I need it to work on Linux Intel.
If at all possible, convert the code to portable C. You will then get
the same results on all machines. Where you can't, localise the
non-portable part into as few functions as possible and then re-write
these as required to get the desired behaviour.

It seems obvious, and I am sorry if I am telling you stuff you know,
but it is surprising how many people think that C is inherently
non-portable (especially if it is "doing stuff with bits").

If you can't post your code, can you say more about how the data is
manipulated? There is nothing in what you have said so far that
indicates any portability issues. With more information, we may be
able to suggest portable solutions, or at least point to the danger
areas.

--
Ben.
Jul 27 '07 #2
On Jul 27, 12:33 pm, Ben Bacarisse <ben.use...@bsb.me.ukwrote:
If you can't post your code,
I don't think I had better - can't violate certain contractual
agreements, etc.
can you say more about how the data is
manipulated? There is nothing in what you have said so far that
indicates any portability issues.
Well, there's a whole library of code here. But what I see is a setup
command which is passed several arguments, one of which is an unsigned
long IP address.
The ip address is passed, along with a variety of other arguments,
into an encoding routine. In the encoding routine, the ip address is
passed like this:

otp_uln2hex(&otp->ip, OTP_IP_BYTES, ptr);
ptr += OTP_IP_LEN;
*ptr++ = ' ';
*ptr++ = '0' + otp->sequence / 10000;
*ptr++ = '0' + (otp->sequence / 1000) % 10;
*ptr++ = '0' + (otp->sequence / 100) % 10;
*ptr++ = '0' + (otp->sequence / 10) % 10;
*ptr++ = '0' + otp->sequence % 10;
*ptr++ = ' ';

Where ptr is a pointer into a line. when all the processing is done,
there's one ascii line which is output to a file, which then other
processes read.

Inside the uln2hex routine, the pointer to an unsigned long, along
with a count and an output area is taken, and while the count is
greater than 0, the routine loops around a switch statement. The cases
are the bytes remaining.
For each byte, a line like this is executed:

case 1:
*ptr++ = hex[(*in >4) & 0xf];
*ptr++ = hex[*in & 0xf];

where hex[] is an array of hex ascii characters.

Does that help?
Jul 27 '07 #3
On Jul 27, 12:58 pm, Roberto Waltman <use...@rwaltman.netwrote:
If fixing your problem requires knowledge of the Solaris & Linux
platforms, (as opposed to generic C questions,) you may be better of
in a group dedicated to Solaris/Linux/networking.
I certainly wouldn't want to cause any problems, having read this
newsgroup off and on for many, many years.

Is there a group/mailing list/web forum dedicated to solaris/linux
networking issues where problems such as mine is more appropriate?

As for showing code. I wish I could. However, non-disclosure contracts
really keep me from showing the code.

Jul 27 '07 #4
lvirden <lv*****@gmail.comwrites:
[...]
Is there a group/mailing list/web forum dedicated to solaris/linux
networking issues where problems such as mine is more appropriate?
Probably comp.unix.programmer.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 27 '07 #5
On Jul 27, 6:59 pm, Ben Bacarisse <ben.use...@bsb.me.ukwrote:
>
>
The only truly suspicious thing here is treating an IP address as an
unsigned long. That is not necessarily wrong, but it might be. I'd
be tempted to do a quick test: if you enter 1.2.3.4 as the address (on
Solaris) do you get the same encoding as you get when you enter
4.3.2.1 on the Linux implementation?
Okay, here's the weird thing. I put in 1.2.3.4 as an address to be
encoded, on Linux. I then, on Solaris, indicated that I wanted to
decode the value. It got the right information with no coding
problem. So it looks like my library is doing the right thing! Now I
have to back track to figure out where the information is being used -
because something definitely isn't using the encoded address
correctly.

Thanks for the ideas!

Jul 30 '07 #6
lvirden wrote:
>
I'm responsible for supporting some C code which implements one time
passwords. The author of the code is no longer available for help.
The code has been used for years on a sparc solaris platform.

Now I need it to work on Linux Intel.

The behavior I am seeing is this.

I compiled this C code on Linux, using gcc, and it compiled without
complaint. I know that part of the code converts things into a hex
string from a long (and converts from the hex string into a long).

When I run a "build key" option of software using this code, it is
passed an IP address (for illustration, lets say "123.45.67.890").

A otp is generated.
Whatever that is. It has nothing to do with the problem.
>
Then, the command is issued with a flag that says "list the
information". What it prints is

890.67.45.123
Quite obviously you have run into something to do with endianism.
Somewhere you are treating the data as a sequence of bytes, rather
than as a long. In other words, invalid code, and it is biting. I
suspect you are also assuming 8 bit bytes, which may also bite in
the future.

You want to use an unsigned long to hold the value. Install things
with modulo 256 arithmetic and shifts, and extract things with
divisions by 256.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Aug 1 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
1507
by: Nickolay Kolev | last post by:
Hi all, I would like to find a more pythonic way of solving the following: Having a string consisting of letters only, find out the total sound score of the string. The sound score is...
2
2273
by: matt | last post by:
Hi all- I'm trying to port an ajax spell-checker (http://www.broken-notebook.com/spell_checker/index.php) to use with the moin moin wiki and have been somewhat successful. (By successful I...
0
1886
by: Walter Quirtmair | last post by:
Hello, I have a C# WinForms Application that contains various "old" ActiveX-Controls. Due to some unknown reasons recently the "red cross" - problems appears quite often. Without any know...
8
1312
by: Steve Jorgensen | last post by:
It's a common saying, "Less is more". Mostly, people think it refers only to purely artistic creation, and when it -is- applied to other endevors, I think the words fail to communicate the full...
1
9473
by: Mesan | last post by:
I'm getting a "Cross-thread operation not valid" Exception and I can't figure out why. I've got a BackgroundWorker that creates a UserControl with a whole lot of other user controls inside of...
8
4829
by: Pieter | last post by:
Hi, I'm having some weird problem using the BackGroundWorker in an Outlook (2003) Add-In, with VB.NET 2005: I'm using the BackGroundWorker to get the info of some mailitems, and after each item...
4
7771
by: Mau Kae Horng | last post by:
Hello, I have a C# Windows Forms application for machine. Due to some unknown reasons, the application face problems with unexpected exceptions happening, resulting in two red lines forming a...
3
5390
by: Pieter Coucke | last post by:
Hi, In my VB.NET 2005 application I'm generating and sending emails using the outlook-object model (2003). When a mail is Send (MailObject_Send), I raise an event in a global class, that is...
11
4245
by: taoberly | last post by:
A few months ago I posted a question about using a file on my hard drive to perform cross-frame scripting and pull data from a server on my company's intranet. I eventually got this working using...
17
2390
by: Chen Shusheng | last post by:
Hi all, In fact, I want to let my memory run out. And see what will happen. My system is windowsXp. Memory is 256M.I think my cdes will apply more memory than I have. Codes are below: ...
0
7103
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7307
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4701
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.