Socket Programming (connect() returns errorno = 38)

  • Thread starter Michael McGarry
  • Start date
M

Michael McGarry

Hi,

I am using connect() to connect a socket. connect() returns -1 and
sets errno to 38. How can I find the error type associated with this
value (i.e., 38) in errno?

Thanks for any help,

Michael
 
S

Seebs

I am using connect() to connect a socket. connect() returns -1 and
sets errno to 38. How can I find the error type associated with this
value (i.e., 38) in errno?

strerror(errno)

Note that connect() isn't topical here (it's a system-specific feature),
but conveniently your question is about errno, which is portable (although
the specific value probably isn't).

My guess would be:

ENOTSOCK [38]: Socket operation on non-socket

which suggests that you've got a file descriptor wrong. One of the most
common mistakes causing that is to write something like:
x = syscall() != -1

after which x is set to either 0 or 1, because != is a boolean operator.

-s
 
I

Ian Collins

Michael said:
Hi,

I am using connect() to connect a socket. connect() returns -1 and
sets errno to 38. How can I find the error type associated with this
value (i.e., 38) in errno?

Search for it where it is defined, in errno.h.
 
B

Ben Pfaff

Michael McGarry said:
I am using connect() to connect a socket. connect() returns -1 and
sets errno to 38. How can I find the error type associated with this
value (i.e., 38) in errno?

strerror(38)
 
M

Michael McGarry

Thanks, perfect guess!!

I am using connect() to connect a socket. connect() returns -1 and
sets errno to 38. How can I find the error type associated with this
value (i.e., 38) in errno?

strerror(errno)

Note that connect() isn't topical here (it's a system-specific feature),
but conveniently your question is about errno, which is portable (although
the specific value probably isn't).

My guess would be:

ENOTSOCK [38]:         Socket operation on non-socket

which suggests that you've got a file descriptor wrong.  One of the most
common mistakes causing that is to write something like:
        x = syscall() != -1

after which x is set to either 0 or 1, because != is a boolean operator..

-s
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,476
Latest member
blackwatermelon

Latest Threads

Top