Solved

"Accept" - works on some stations, not others

Posted on 2002-06-21
8
293 Views
Last Modified: 2010-04-21
Hi
  I have written a little c++ client/server in linux and everything worked fine. But when I moved the source to another machine and compiled it there, the accept call returns a invalid argument error, when I run and try to connect to the server with a connect call from the client.  If I only move the executable to this machine, it works fine.  So it seems there is something going wrong a compile-time.  I use g++ to compile.

I hope someone can help.  Thanks in advance.

Dadi
0
Comment
Question by:huxun
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 5

Expert Comment

by:garboua
ID: 7100974
another linux machine?
g++ -v to see what versions are you running of both machines.

"the accept call returns a invalid argument error,"
I don't understand, if the accept returns an error that would mean it compiles OK and then compiler is NOT an issue, If the error is compilation or link time? then tell us more, line 1--> other machine and versions of compiler. it would really help if you post the actuall error
0
 

Author Comment

by:huxun
ID: 7103311
Hi ... I figured out how to solve this stupid error.  But I don't understand why it occured.  I have the same version of the compiler on all the machines.  The thing was that when I send the socklen_t argument into 'accept' it ran ok if I compiled at the machine I originally wrote the program, but not if I compiled at some other machine.  Still, I could copy the executable file to this other machine from the original and it would run fine.  So I started commenting alot af stuff out and adding it piece by piece, and on the end I found the cause of the error. This:

char c;
socklen_t fromlen;
.
.
.
accept( s, (struct sockaddr *) &fsain, &fromlen);

had to be changed to this:

socklen_t fromlen;
char c;
.
.
.
accept( s, (struct sockaddr *) &fsain, &fromlen);


I do not understand why this is the case and if someone has a clue, please tell me.
0
 
LVL 4

Expert Comment

by:newmang
ID: 7105910
huxun

Without seeing the remainder of your code its hard to offer an opinion. However based on bitter experience I find that in cases where swapping the order of variable declarations "fixes" problems then the real problem lies with the variable being partially over-written by another variable. I think you will find that the second piece of code works because the variable c is not used prior to fromlen being used and the value being loaded into fromlen is longer than socklen_t for some reason. In the first case part or all of fromlen is being over-written by another variable.

I would need to see more of your code to go any further, perhaps you could post the include statements, the variable declarations (if any) after the two you have posted, the code that initialises fromlen (and the declaration of any variables used in this process).

Perhaps you could revert to the original code, compile it on the offending system (with debug) then run it through the debugger watching fromlen at each step to detect the location where this variable gets corrupted.

Cheers - Gavin
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:garboua
ID: 7119122
sound like a logical explanation newmang.
0
 

Author Comment

by:huxun
ID: 7121455
I wrote out the size and location of the variables and they didn't overlap.  Still, do not understand what was going wrong. Guess the compiler is kaput.  It is version 2.96 so ...
0
 
LVL 3

Accepted Solution

by:
pjb1008 earned 100 total points
ID: 7249077
The fromlen parameter is input and output.
On entry to accept(), it is the size of the address buffer;
on exit it is the size of the address.

Typical usage is:

struct sockaddr_in addr;
sockaddr_t len=sizeof(addr);

retval=accept(fd, (struct sockaddr *)&addr, &len);

Chances are that len wasn't initialised, and you picked up whatever value happened to be on the stack. This will yield different results with different compilers.
0
 
LVL 20

Expert Comment

by:jmcg
ID: 9925511
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: pjb1008 {http:#7249077}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
idM Identity Management in Red Hat 6 - setting up 9 269
Chinese translation in RedHat 10 57
Prestashop 1.5 Redirect Problem 1 125
Cron jobs 12 140
Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question