DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ T s

⟦678ec9a69⟧ TextFile

    Length: 3018 (0xbca)
    Types: TextFile
    Names: »server.c«

Derivation

└─⟦87ddcff64⟧ Bits:30001253 CPHDIST85 Tape, 1985 Autumn Conference Copenhagen
    └─ ⟦this⟧ »cph85dist/rman/client/server.c« 

TextFile

/*
 *  Copyright (c) 1985  Jonathan C. Broome and The Regents of the 
 *  University of California.
 *
 *  This software may be freely redistributed without licensing
 *  provided that this copyright notice remains intact and no profit
 *  is gained through any redistribution.
 *
 *  Please report any bug fixes or modifications to the author at:
 *
 *        broome@ucb-vax.berkeley.edu
 *   or:
 *        ...!ucbvax!broome
 *
 *  The author and the Regents assume no liability for any damages 
 *  or loss of revenue caused directly or indirectly by the use of 
 *  this software.
 */

#ifndef lint
static char *RCSid = "$Header: server.c,v 1.9 85/08/27 15:20:00 broome Exp $";
#endif

/*
 * $Log:    server.c,v $
 * Revision 1.9  85/08/27  15:20:00  broome
 * Added copyright/distribution comment.
 * 
 * Revision 1.8  85/08/27  15:05:04  broome
 * 
 * 
 * Revision 1.7  85/08/09  16:10:37  broome
 * Added #ifdef'ed code to ask for alternate machine type, define TYPE to
 * compile it in, i.e. "-DTYPE=\"sun\"" to cc.
 * 
 * Revision 1.6  85/08/03  02:38:04  broome
 * 
 * Revision 1.5  85/07/31  09:32:43  broome
 * Changed to set errno to EHOSTDOWN when the connection times out, always
 * returns instead of exiting on errors...
 * 
 * Revision 1.4  85/07/16  11:11:29  broome
 * Rewritten to use the routines to ping all possible servers.
 * 
 * Revision 1.3  85/07/04  19:59:09  broome
 * 
 * Revision 1.2  85/07/02  21:05:25  broome
 * 
 * Revision 1.1  85/06/25  11:22:58  broome
 * Initial revision
 */

#include <stdio.h>
#include <netdb.h>

#ifndef PORT
#define PORT 9535
#endif

/*
 *  Open a socket to the specified host.
 */

open_server ()
{
    extern FILE *sock_rp, *sock_wp;
    extern char *type;
#ifdef SERVICES
    struct servent *serv;
#endif
    char   buf[132];
    int    sock, port;

#ifdef SERVICES   /* listed in /etc/services */
    if ((serv = getservbyname ("man", "tcp")) == NULL) {
        fprintf (stderr, "Unknown service: man/tcp\n");
        exit (1);
    }
    port = serv->s_port;
#else SERVICES
    port = htons (PORT);
#endif SERVICES

    if ((sock = get_host (port)) == -1)
        return (-1);

    /*
    **  Create a pair of buffered descriptors to the socket
    **  so that we can use stdio ``fprintf'' and the like.
    */
    sock_wp = fdopen (sock, "w");
    sock_rp = fdopen (sock, "r"); 

    fgets (buf, 128, sock_rp);       /* get the banner line */
    if (strncmp (buf, "210", 3)) {   /* bad response code */
        close (sock);
        fprintf (stderr, "%s", buf+4);
        return (-1);
    }

#ifdef TYPE
    fprintf (sock_wp, "type %s\r\n", TYPE);   /* ask for alternate cpu type */
    fgets (buf, 128, sock_rp);                /* get (and trash) response */
#endif TYPE

    if (type) {   /* they specified a machine type */
        fprintf (sock_wp, "type %s\r\n", type);
        (void) fflush (sock_wp);
        fgets (buf, 128, sock_rp);
        if (strncmp (buf, "223", 3))
            fprintf (stderr, "%s", buf+4);
    }

    return (sock);
}