UDP client port question - TCP-IP

This is a discussion on UDP client port question - TCP-IP ; This is Solaris 10. I am trying to write a simple UDP client that sends a SIP request to a server and wait for the response. I have essentially copied the simple UDP client out of Stevens book, but while ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: UDP client port question

  1. UDP client port question

    This is Solaris 10.

    I am trying to write a simple UDP client that sends a SIP request to
    a server and wait for the response.

    I have essentially copied the simple UDP client out of Stevens book,
    but while I can see the request sent on Wireshark, I do not receive
    anything back (i.e., my recvfrom blocks without returning with data)
    even though I can see the server is sending a response.

    In my program, I bind with port 0, then call getsockname to find out
    what port I actually got (e.g. 56493). The problem is, according to
    the trace, that
    is NOT the port that the packet is going out on (port 44508). Once I
    realized that,
    I was able to find that there is a UDP entry for this port in the
    netstat output.

    While looking at the Wireshark trace, I can see that the server is
    sending
    the reply to 56493, which is what I told it in the "Via" message.
    Since it appears
    that my program is *really* listening on port 44508, I never receive
    the message.

    This seems very basic to me, and doesn't correspond to my knowledge of
    how
    sockets work at all.

    Does this make any sense to anyone? How can I be on a different
    socket that
    what I bind to (and get back from getsockname)?

    Thanks,

    Mitch

  2. Re: UDP client port question

    In article ,
    "mitchmcc@yahoo.com" writes:
    > This is Solaris 10.
    >
    > I am trying to write a simple UDP client that sends a SIP request to
    > a server and wait for the response.
    >
    > I have essentially copied the simple UDP client out of Stevens book,
    > but while I can see the request sent on Wireshark, I do not receive
    > anything back (i.e., my recvfrom blocks without returning with data)
    > even though I can see the server is sending a response.
    >
    > In my program, I bind with port 0, then call getsockname to find out
    > what port I actually got (e.g. 56493). The problem is, according to
    > the trace, that
    > is NOT the port that the packet is going out on (port 44508).


    Use ntohs() when printing port numbers from getsockname.

  3. Re: UDP client port question

    In comp.unix.solaris mitchmcc@yahoo.com wrote:
    > In my program, I bind with port 0, then call getsockname to find out
    > what port I actually got (e.g. 56493). The problem is, according to
    > the trace, that
    > is NOT the port that the packet is going out on (port 44508). Once I


    56493 == 0xdcad.
    44508 == 0xaddc.

    Thus, 56493 is a byte-swapped 44508.

    Thus, at some point you're byte-swapping the port, or NOT byte-swapping,
    depending on how your code works. Check up on the ntohs and htons functions.

    --
    Brandon Hume - hume -> BOFH.Ca, http://WWW.BOFH.Ca/

  4. Re: UDP client port question

    On 02 Jul 2008, "mitchmcc@yahoo.com" wrote:

    > This is Solaris 10.
    >
    > I am trying to write a simple UDP client that sends a SIP request
    > to a server and wait for the response.


    Others have cleared up the port number confusion. But there's also a
    source of sometimes silent packet loss on UDP sockets. If the size of
    the buffer you are giving to recvfrom() is not big enough to contain
    the entire payload of the UDP packet, the entire packet may be silently
    discarded. I'm not sure how this works on Solaris 10, but you might
    want to check what you're passing to recvfrom() against what Wireshark
    shows as the size of the data in the datagram.

    Dave

    --
    D.a.v.i.d T.i.k.t.i.n
    t.i.k.t.i.n [at] a.d.v.a.n.c.e.d.r.e.l.a.y [dot] c.o.m

+ Reply to Thread