Thread: udp: sizeof() and recvfrom()

  1. #1
    Registered User
    Join Date
    Oct 2009

    udp: sizeof() and recvfrom()

    I'm having problems with these two lines of code and incompatible types. The code worked, but compiles with this warning:
    "warning: pointer targets in passing argument 6 of ârecvfromâ differ in signedness"
    I looked up the meening of "signedness" and it is what I guessed--> (+/-)

    server_addr_size = sizeof(server_addr);
    rec_size = recvfrom(skt, &buffer, sizeof(buffer), 0, (struct sockaddr*) &client_addr, &server_addr_size);
    I looked up the parameter types for recvfrom() but don't understand the last (6th) parameter type in question.
    ssize_t recvfrom (int s, void * restrict buf, size_t len, int flags, 
                      struct sockaddr * restrict from, socklen_t * restrict fromlen);
    The parameter types came for this page:
    Open C Sockets: recv, recvfrom, recvmsg methods - Forum Nokia Wiki
    Last edited by Roger; 11-15-2009 at 11:08 AM.

  2. #2
    Registered User
    Join Date
    Sep 2007
    Is server_addr_size a socklen_t? If not, you're passing the wrong type. The last argument of the function is supposed to be a socklen_t*. If you're passing any other pointer type, that's incorrect.

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    In the example on the page you refer to, the 6th param ("size") is an unsigned int type.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Generic heapsort
    By Sephiroth1109 in forum C Programming
    Replies: 15
    Last Post: 12-07-2007, 06:14 PM
  2. Invalid conversion from 'void*' to 'BYTE' help
    By bikr692002 in forum C++ Programming
    Replies: 9
    Last Post: 02-22-2006, 11:27 AM
  3. An exercise in optimization
    By Prelude in forum Contests Board
    Replies: 10
    Last Post: 04-29-2005, 03:06 PM
  4. Monitoring tcp and udp traffic on FreeBSD 4.8-realease
    By Longie in forum Networking/Device Communication
    Replies: 1
    Last Post: 01-19-2004, 01:56 AM