CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2008
    Posts
    1

    Explain This Code

    can any tell me what this code does...i am a university student and baffled about what this code does, lol

    --------------------------------------------------------------------------------------------------------------------------------

    /* make_contact.c */

    #include "cnaiapi.h"

    /*-----------------------------------------------------------------------
    * make_contact - open a new TCP connection to the specified IP address
    * (c) and port e(a).
    *-----------------------------------------------------------------------
    */
    connection
    make_contact(computer c, appnum a)
    {
    struct sockaddr_in sockaddr;
    int sock;

    cnaiapi_init();

    sock = socket(PF_INET, SOCK_STREAM, 0);
    if (sock < 0)
    return -1;

    (void) memset(&sockaddr, 0, sizeof(struct sockaddr_in));

    sockaddr.sin_family = AF_INET;
    sockaddr.sin_port = htons(a);
    sockaddr.sin_addr.s_addr = c;

    if (connect(sock, (struct sockaddr *) &sockaddr, sizeof(struct sockaddr_in)) < 0) {
    #if defined(LINUX) || defined(SOLARIS)
    close(sock);
    #elif defined(WINDOWS)
    closesocket(sock);
    #endif
    return -1;
    }
    return sock;
    }

    -----------------------------------------------------------------------------------------------------------------------


    thanks

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Lightbulb Re: I need helpppppppppppppppppppp

    * make_contact - open a new TCP connection to the specified IP address
    * (c) and port e(a).
    It opens a new TCP connection to a specific IP address and port.

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Explain This Code

    HAve a look here on how to post properly :
    http://www.codeguru.com/forum/misc.php?do=bbcode

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured