#include #include #include #include /* ** Name: CVlisten - turns a tcp port name into a tcp port number ** ** Description: ** This routine provides mapping from II_INSTALLATION into a ** unique tcp port number for the installation. ** ** If pin is of the form: ** XY ** or XY# ** where ** X is [a-zA-Z] ** Y is [a-zA-Z0-9] ** and # is [0-7] ** ** then portid is the string representation of the decimal number: ** ** 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 ** +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ ** ! 0 ! 1 ! low 5 bits of X ! low 6 bits of Y ! # ! ** +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ ** ** If pin is not of that form an error is returned... ** ** Inputs: ** pin - remote listen address, as entered in netu ** ** Outputs: ** portid - TCP/IP listen port for GCC connection request ** */ main(argc,argv) int argc; char *argv[]; { char pin[3]; int addr_len; if (argc != 2) { printf("\n CVlisten usage: cvlisten remote_listen_address (as in II0)\n\n "); exit(1); } addr_len = strlen(argv[1]); if (addr_len < 2 || addr_len > 3) { printf("\nCVlisten remote_listen_address must be of the form II or II0\n \n"); exit(1); } strcpy(pin,argv[1]); if (isalpha(pin[0]) && isalnum(pin[1])) { long portid; int p0, p1; int p2 = 0; p0 = islower(pin[0]) ? toupper(pin[0]) : pin[0]; p1 = islower(pin[1]) ? toupper(pin[1]) : pin[1]; if (addr_len == 3) { if (isdigit(pin[2])) p2 = pin[2]; else { printf("\nValue in position 3 must be a digit\n\n"); exit(1); } } portid = 1 << 14 | (p0 & 0x1f) << 9 | (p1 & 0x3f) << 3 | (p2 & 0x07); printf("\n\tGCC Remote listen address resolves to port # %d\n\n", portid ); exit(0); } else { printf("\nGCC Remote listen address is not in correct format\n"); printf(" position #1 alpha, position #2 alphanumeric\n\n"); exit(0); } }