recvfrom - fromlen parameter

This is a discussion on recvfrom - fromlen parameter within the Networking/Device Communication forums, part of the General Programming Boards category; i have been fidgeting winsock's udp. the function recvfrom mainly: Code: int recvfrom ( SOCKET s , char FAR* buf ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    28

    recvfrom - fromlen parameter

    i have been fidgeting winsock's udp.

    the function recvfrom mainly:

    Code:
    int recvfrom( SOCKET s, char FAR* buf, int len, int flags, struct sockaddr FAR* from, int FAR* fromlen );
    it has been acting strange

    when i call:

    Code:
    char data[6];
    int fromlen = sizeof(sockaddr);
    
    int recvfrom( s,  data, sizeof(data), 0, NULL, &fromlen );
    i get a WSAEFAULT error.
    when i provide NULL instead of &fromlen i get no error.

    is this normal? my question is why is it checking from when it is NULL? ( assuming that's the problem )

    i would like to hear your thoughts.
    Last edited by symbiote; 04-21-2009 at 03:55 AM.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Probably because you are passing NULL to the from field. You are basically saying that the from structure you are passing is sizeof(sockaddr). Then you pass NULL for that parameter. You are lying to the function.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    28
    in tcp with accept

    Code:
    SOCKET accept( SOCKET s, struct sockaddr FAR* addr,	int FAR* addrlen );
    when i call:

    Code:
    SOCKET s;
    int addrlen = sizeof(sockaddr);
    
    int accept( s, sizeof(data), NULL, &addrlen );
    i get a no error.
    when i provide NULL instead of &addrlen i get no error.

    now i also filled addrlen with sizeof(sockaddr). and the situation looks the same as with the udp recvfrom function where i filled fromlen with sizeof(sockaddr).
    that's why i think it's so strange
    Last edited by symbiote; 04-21-2009 at 03:55 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. my error is storage class specified for parameter
    By meli in forum C Programming
    Replies: 5
    Last Post: 03-27-2009, 01:06 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. cannot start a parameter declaration
    By Dark Nemesis in forum C++ Programming
    Replies: 6
    Last Post: 09-23-2005, 03:09 PM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21