Re: Problems with sockets

Discussion in 'C Programming' started by Nobody, Aug 27, 2009.

  1. Nobody

    Nobody Guest

    On Thu, 27 Aug 2009 08:41:11 +0200, Hakan wrote:

    > The server code quoted below keeps giving me errors. The bind call
    > returns -1 every time I try it.


    And what does it set errno to?
    Nobody, Aug 27, 2009
    #1
    1. Advertising

  2. Nobody <> writes:

    > On Thu, 27 Aug 2009 08:41:11 +0200, Hakan wrote:
    >
    >> The server code quoted below keeps giving me errors. The bind call
    >> returns -1 every time I try it.

    >
    > And what does it set errno to?


    This question has been re-posted on another group but it turns out the
    problem is, after all, a C one:

    >> if (sockint=socket(hp->h_addrtype,SOCK_STREAM,ptrp->p_proto)>=0)


    There are missing ()s round the assignment.

    C advice to the OP: turn on more warnings from you compiler!

    --
    Ben.
    Ben Bacarisse, Aug 27, 2009
    #2
    1. Advertising

  3. Hakan <> writes:

    > Ben Bacarisse wrote:
    >
    >> Nobody <> writes:

    >
    >>> On Thu, 27 Aug 2009 08:41:11 +0200, Hakan wrote:
    >>>
    >>>> The server code quoted below keeps giving me errors. The bind
    >>>> call returns -1 every time I try it.
    >>>
    >>> And what does it set errno to?

    >
    >> This question has been re-posted on another group but it turns out the
    >> problem is, after all, a C one:

    >
    >>>> if (sockint=socket(hp->h_addrtype,SOCK_STREAM,ptrp->p_proto)>=0)

    >
    >> There are missing ()s round the assignment.

    >
    >> C advice to the OP: turn on more warnings from you compiler!

    >
    > Still get the same problem from this after adding the
    > parenthesis. Perror types out "Socket operation on
    > non-socket". Thanks.


    Can you paste the section of code in case there has been some
    misunderstanding? If you are confident that there has been no
    misunderstanding, then you have a very odd problem indeed (and not a C
    one so, keep posting in whatever other group you think is more
    suitable).

    --
    Ben.
    Ben Bacarisse, Aug 27, 2009
    #3
  4. On Aug 27, 10:29 pm, Hakan <> wrote:
    > Ben Bacarisse wrote:
    > > Nobody <> writes:
    > >> On Thu, 27 Aug 2009 08:41:11 +0200, Hakan wrote:

    >
    > >>>  The server code quoted below keeps giving me errors. The bind call
    > >>> returns -1 every time I try it.

    >
    > >> And what does it set errno to?

    > > This question has been re-posted on another group but it turns out the
    > > problem is, after all, a C one:
    > >>> if (sockint=socket(hp->h_addrtype,SOCK_STREAM,ptrp->p_proto)>=0)

    > > There are missing ()s round the assignment.
    > > C advice to the OP: turn on more warnings from you compiler!

    >
    > Still get the same problem from this after adding the parenthesis.
    > Perror types out "Socket operation on non-socket". Thanks.
    >


    I think you didn't get what Ben Bacarisse meant?
    > >>> if (sockint=socket(hp->h_addrtype,SOCK_STREAM,ptrp->p_proto)>=0)

    change to if ((sockint=socket(hp->h_addrtype,SOCK_STREAM,ptrp-
    >p_proto))>=0)

    From the error message, this must be the problem. What you are
    assigning to sockint in your statement is not the socket descriptor
    returned by the call but rather the truth value on comparison with 0.

    Hence the error message saying socket operation on non-socket.
    Sri Harsha Dandibhotla, Aug 28, 2009
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jeff
    Replies:
    0
    Views:
    1,498
  2. Pep
    Replies:
    5
    Views:
    2,283
    E.J. Pitt
    Sep 12, 2005
  3. GilNajera

    problems with windows sockets

    GilNajera, Jan 14, 2011, in forum: C Programming
    Replies:
    5
    Views:
    355
    Michael Angelo Ravera
    Jan 18, 2011
  4. David Heinemeier Hansson

    Sockets problems on OS X 10.3

    David Heinemeier Hansson, Jan 15, 2004, in forum: Ruby
    Replies:
    1
    Views:
    93
    Richard Kilmer
    Jan 15, 2004
  5. Dexter Deejay

    Problems with sockets and threads

    Dexter Deejay, Apr 11, 2013, in forum: Python
    Replies:
    9
    Views:
    129
    Dexter Deejay
    Apr 11, 2013
Loading...

Share This Page