dish/src/dish.cxx
//----------------------------------------------------------------
// This static function will try to connect to the HTTP server on the
// given host using given port. Will return server socket or -1 if
// failed to connect.
// ----------------------------------------------------------------
This static function will try to connect to the HTTP server on the
given host using given port. Will return server socket or -1 if
failed to connect.
This static function will try to connect to the HTTP server on the given host using given port . Will return server socket or - 1 if failed to connect .
static int connectToHttpServer(char* host, int port) {
    struct sockaddr_in serv_addr;
    if(IsIp(host)==0) {
        struct hostent *ent;
        ent = gethostbyname(host);
        if(ent == NULL) return -1;
        serv_addr.sin_addr   = *(in_addr *)*ent->h_addr_list;
    } else {
#if 0 
        serv_addr.sin_addr.S_un.S_addr = IpFromDecDelim(host);
#else
        serv_addr.sin_addr.s_addr = IpFromDecDelim(host);
#endif
    }
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_port   = htons (port);
    int sock = socket (PF_INET, SOCK_STREAM, 0);
    if (sock < 0) return sock;
    if(connect(sock,  (struct sockaddr *)&serv_addr, sizeof (sockaddr_in)) < 0) {
        closesocket(sock);
        return -1;
    }
    return sock;
}
static int connectToHttpServer ( char * host , int port ) { struct sockaddr_in serv_addr ; if ( IsIp ( host ) == 0 ) { struct hostent * ent ; ent = gethostbyname ( host ) ; if ( ent == NULL ) return -1 ; serv_addr . sin_addr = * ( in_addr * ) * ent -> h_addr_list ; } else { #if 0 serv_addr . sin_addr . S_un . S_addr = IpFromDecDelim ( host ) ; #else serv_addr . sin_addr . s_addr = IpFromDecDelim ( host ) ; #endif } serv_addr . sin_family = AF_INET ; serv_addr . sin_port = htons ( port ) ; int sock = socket ( PF_INET , SOCK_STREAM , 0 ) ; if ( sock < 0 ) return sock ; if ( connect ( sock , ( struct sockaddr * ) & serv_addr , sizeof ( sockaddr_in ) ) < 0 ) { closesocket ( sock ) ; return -1 ; } return sock ; }
This static function will try to connect to the HTTP server on the
given host using given port.
This static function will try to connect to the HTTP server on the given host using given port .
//XXX porting? /* Create the socket. */ /* Give the socket a name. */