November 19th, 2008 06:59 AM
#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
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
Forum Rules
Click Here to Expand Forum to Full Width
Bookmarks