473,657 Members | 2,735 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.8 90").

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 1226
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(&ot p->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...@rwaltma n.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.progr ammer.

--
Keith Thompson (The_Other_Keit h) 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.securityfoc us.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
1526
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 calculated as the sum of the transition scores between the characters in that string. The transition scores are stored in a 26 x 26 matrix. I.e. the transition A -> F would have the score soundScoreMatrix.
2
2280
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 mean I can spell check using the php backend and my python port running as cgi-bin). My question is this: moinmoin runs on many python web backends (cgi-bin/mod-python/twisted/standalone). My spell-checker backend runs
0
1901
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 reason suddenly some controls (buttons, toolbars...) will be drawn completely white with a red cross inside it. As I know from other postings this happens if there are exceptions during the painting of the controls. The call stack shown in the...
8
1317
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 message. Thus, I have started to rephrase the statement as "More is less". Now, I obviously don't mean this as an absolute, but it's helpful to remember that, in engineering, it is very often true. Take this story about the microwave at my...
1
9490
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 it, full of data I'm getting from the database. When my background worker completes I take e.Result and cast it back into a UserControl. I create a TabPage, add the returned UserControl to the Controls of the new TabPage and *BAM* there's my...
8
4842
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 I want to raise the ProgressChanged-event to update the DataGridView. It works fine when only one Progresschanged is fired, but at the second, third, fopurth etc it raises everytile a 'Cross-thread operation not valid"-exception on lmy...
4
7777
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 red cross across a certain control (the entire form, labels and so on). I get the following message in MessageBox.
3
5407
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 caught by all my forms that than refresh the lists with emails. But on the moment I do a MyDataGrid.DataSource = nothing, I get this "Cross-thread operation not valid"-exception:
11
4264
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 an HTA file and Internet Explorer. Now I'm tackling a similar issue, but really need to keep the IE menus, navigation buttons, etc. this time around. Assuming a solution exists, I'm guessing it involves using the IE6 SP2 "Mark of the Web"...
17
2410
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: #include <stdlib.h> #include<stdio.h> #define MAX 1000000000
0
8407
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8739
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8612
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7347
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6175
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2739
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 we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.