Solved

EAFNOSUPPORT porting from freebsd to linux

Posted on 2003-10-23
10
452 Views
Last Modified: 2008-02-26
Alright so i have this application that I have just finished porting to linux.. mainly little things like using namespace std and such to make it happy.. anyway whenthe program runs.. it returns this..


EAFNOSUPPORT

the code of this program is huge. but anywhere here is the jistof things..

 struct sockaddr_in * addr;
*somewhere up here it gets a ip and puts everything together in addr*
i was looking through the code and i see alot of

cli_addr.sin_family      = AF_INET;
or srv_addr.sin_family = AF_INET;

struct sockaddr_in * mserv_addr;
mserv_addr=addr;
 sock = socket(AF_INET,SOCK_STREAM,0); // set the socket
if (connect(sock,(struct sockaddr *) mserv_addr,sizeof(struct sockaddr_in)) == 0) {
                        ndelay_off(sock);
                        free(t_str);
                        t_str = NULL;
                        return true;
}

^^^^ after that statement there is a case statement which checks errno and spits out the error..

there anything i need to change or you guys can think of?

0
Comment
Question by:sizak
  • 5
  • 4
10 Comments
 
LVL 22

Expert Comment

by:cookre
ID: 9611732
I'd first look at the return from socket to make sure that took:
sock = socket(AF_INET,SOCK_STREAM,0); // set the socket
if (sock==-1) oopsie...
0
 

Author Comment

by:sizak
ID: 9611746
shortly after it does it does check..

 sock = socket(AF_INET,SOCK_STREAM,0); // set the socket

if (sock == -1) {
     tracer->print(T_SMTP,TR_ERROR,3,"Create socket failure.");
     other stuff is here too...

so it does create the socket.
0
 
LVL 22

Expert Comment

by:cookre
ID: 9611939
The only thing I can think of right now is to double check sin_family pointed to by mserv_addr right before the call to connect to make sure it really is AF_INET
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9612679
>mserv_addr=addr;
what are the values in addr ?
1. try printing all members of the struct before the connect call
2. run your program through a debugger to be double sure
0
 

Author Comment

by:sizak
ID: 9614294
last night i added.

mserv_addr->sin_family=AF_INET;

compiled.. error went away.. but not when it runs I believe it does make its connection.. but doesn't know wat to do from there.  I'm assuming the way they talk together didn't port over  :-/
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Expert Comment

by:cookre
ID: 9614359
Given that  connect() is now returning a 0, is your read giving a bad return or just not getting any data?
0
 

Author Comment

by:sizak
ID: 9614987
connect() isn't connecting.


                if (connect(sock,(struct sockaddr *) mserv_addr,sizeof(struct sockaddr_in)) == 0) {
                        ndelay_off(sock);
                        sprintf(t_str,"COnnection Made!");
                        tracer->print(T_SENDER,TR_NOTIFY,1,t_str);

                        free(t_str);
                        t_str = NULL;
                        return true;
                } else {
                        sprintf(t_str,"Not connected");
                        tracer->print(T_SENDER,TR_NOTIFY,1,t_str);
                }


I get the not connected in my logs.
0
 

Author Comment

by:sizak
ID: 9616324
I added a


sprintf(t_str,"Errorno: %d",errno);
 tracer->print(T_SENDER,TR_NOTIFY,1,t_str);

after the not connect so i saw the error in the logs.

and it came back with 115..

perror 115 says..

Error code 115:  Operation now in progress

? i'm confused how can it be inprogress if it fails on connect?
0
 
LVL 22

Accepted Solution

by:
cookre earned 250 total points
ID: 9616426
Well, now it's come down to just slogging through:

1) verify socket() gives a good return

2) verify ALL fields of mserv_addr are set and correct (I didn't see a port selection)

3) capture errno on connect() failure - there are lots of things it could be.  Shoot, it may just require a retry.


errno for connect() failures from its' man pages:

[EBADF]                   S is not a valid descriptor.
[ENOTSOCK]            S is a descriptor for a file, not a socket.
[EADDRNOTAVAIL]   The specified address is not available on this machine.
[EAFNOSUPPORT]    Addresses in the specified address family cannot be used with this socket.
[EISCONN]              The socket is already connected.
[ETIMEDOUT]          Connection establishment timed out without establishing a connection.
[ECONNREFUSED]    The attempt to connect      was forcefully rejected.
[ENETUNREACH]      The network isn't reachable from this host.
[EADDRINUSE]         The address is already      in use.
0
 
LVL 22

Expert Comment

by:cookre
ID: 9617253
Sorry about the cross-post (and not listing all the errors at that).

A return of EINPROGRESS says that the socket is non-blocking (i.e., asynchronous) and that the connection hasn't.

All the man pages say:
=====
The socket is non-blocking and the connection cannot be completed immediately. It is possible to select (2) or poll (2) for completion by selecting the socket for writing. After select indicates writability, use getsockopt (2) to read the SO_ERROR option at level SOL_SOCKET to determine whether connect completed successfully ( SO_ERROR is zero) or unsuccessfully ( SO_ERROR is one of the usual error codes listed above, explaining the reason for the failure).
=====
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
allswap challenge 6 75
move one pixel 4 58
Path to Python 9 104
How to remove numeric and alpha from an alphanumeric field? 5 70
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This is about my first experience with programming Arduino.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

932 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now