Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

connect.C

Go to the documentation of this file.
00001 #include "connect.h"
00002 int connect(hostent * he, int port) {
00003         int sockfd;
00004         struct sockaddr_in their_addr;
00005         if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
00006                 cerr << "Could not connect to " << he->h_name;
00007                 return -1;
00008         }
00009 
00010         their_addr.sin_family = AF_INET;    /* host char order  */
00011         their_addr.sin_port = htons(port);  /* short, network char order */
00012         their_addr.sin_addr = *((struct in_addr *)he->h_addr);
00013         memset(&(their_addr.sin_zero), 0,8);  /* zero the rest of the struct */
00014         int sd = connect(sockfd, (struct sockaddr *)&their_addr, sizeof(struct sockaddr));
00015         if (sd == -1) { 
00016                 cerr << "Could not connect to " << he->h_name;
00017                 return -1;
00018         }
00019         return sockfd;
00020 }

Generated on Tue Dec 17 21:14:13 2002 for AUSS_Connector by doxygen1.2.18