|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T g
Length: 5016 (0x1398) Types: TextFile Names: »general.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0 └─⟦e83f91978⟧ »EurOpenD22/isode/osimis-2.0.tar.Z« └─⟦d846658bd⟧ └─⟦this⟧ »osimis/smap/general.c«
/* * Copyright (c) 1988 University College London * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that the above copyright notice and this paragraph are * duplicated in all such forms and that any documentation, * advertising materials, and other materials related to such * distribution and use acknowledge that the software was developed * by the Department of Computer Science, University College London. * The name of the University may not be used to * endorse or promote products derived from this software without * specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* various peripheral routines */ /* * By George Pavlou, October 1988 */ #include <stdio.h> #include <ctype.h> #include <sys/types.h> #include <sys/socket.h> #include <netdb.h> #include "isode/psap.h" #include "objectS.h" char *tprot2str (tProtocol) int tProtocol; { static char buf[6]; switch (tProtocol) { case 0: strcpy(buf, "undef"); break; case 1: strcpy(buf, "tp0"); break; case 2: strcpy(buf, "tp1"); break; case 3: strcpy(buf, "tp2"); break; case 4: strcpy(buf, "tp3"); break; case 5: strcpy(buf, "tp4"); break; default: advise (NULLCP, "tprot2str: unknown tProtocol %d", tProtocol); return (NULLCP); } return (buf); } int host2indx (host, hosts, nofhosts) char host[], *hosts[]; int nofhosts; { int i; for (i = 0; i < nofhosts; i++) if (strcmp(host, hosts[i]) == 0) break; if (i >= nofhosts) return (-1); return (i); } char *utct2disptime (utct) UTCtime *utct; { static char buf[TIMELEN+1]; static char *month[] = { "illegal month", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; register char *cp; cp = utct2str(utct); strncpy(buf, cp+2, 2); /* month */ buf[2] = '\0'; strncpy(buf, month[atoi(buf)], 3); strncpy(buf+4, cp+4, 2); /* day */ strncpy(buf+7, cp+6, 2); /* hour */ strncpy(buf+10, cp+8, 2); /* min */ strncpy(buf+13, cp+10, 2); /* sec */ strncpy(buf+16, "19", 2); strncpy(buf+18, cp, 2); /* year */ buf[3] = buf[6] = buf[15] = ' '; buf[9] = buf[12] = ':'; buf[20] = '\0'; return (buf); } /* converts time in secs to time in * "month day hours:minutes:seconds year" */ char *secs2disptime (secs) long *secs; { register char *cp; int i; char *ctime(); cp = ctime(secs); for (i = 0; i < 4; i++) *(cp+20+i) = *(cp+24+i); *(cp+24) = '\0'; return (cp+4); } static NAddrHostMap naddrhostmap [] = { "X.25 23421920030035", "London", "X.25 23421920030028", "London", "X.25 23426020017299", "Nottingham", "X.25 31344152401010", "Palo Alto", "X.25 242211000163", "Oslo", "X.25 5052334300013", "Melbourne" }; #define NADDRS 6 char *naddr2host (naddr) char *naddr; { static char buf[HOSTLEN+1]; register char *cp; int len = 0, i; if (strncmp(naddr, "TCP", 3) == 0 || strncmp(naddr, "NSAP", 4) == 0) { cp = naddr+5; if (isalpha(*cp)) { while (*cp != '.' && *cp++ != ' ') if (++len >= 12) break; strncpy(buf, naddr+5, len); buf[len] = '\0'; } else { struct hostent *h; u_long ip_addr; while (*cp != ' ' && *cp++ != '\0'); if (*--cp == ' ') cp = '\0'; ip_addr = inet_addr(naddr+5); if ((h = gethostbyaddr((char *) &ip_addr, 4, AF_INET)) != NULL) { cp = h->h_name; while (*cp != '.' && *cp++ != '\0') if (++len >= 12) break; strncpy(buf, h->h_name, len); buf[len] = '\0'; } else { strncpy(buf, naddr+5, 12); buf[12] = '\0'; } } } else if (strncmp(naddr, "X.25", 4) == 0) { for (i = 0; i < NADDRS; i++) if (strcmp(naddr, naddrhostmap[i].naddr) == 0) break; if (i < NADDRS) { strncpy(buf, naddrhostmap[i].host, 12); buf[10] = '\0'; } else strncpy(buf, "unknown X.25", 12); } else strncpy(buf, "unknown", 12); /* unknown address type */ return (buf); } char *cept2rhost (Cept, l_host) T_ConnectionEndpointS *Cept; char *l_host; { char *cp, *getmyname(), *naddr2host(); if (strcmp(cp = naddr2host(Cept->destTAddr.naddr), l_host) != 0 && strcmp(cp, "localhost") != 0) return (cp); if (strlen(cp = naddr2host(Cept->sourceTAddr.naddr, l_host)) != 0) return (cp); strncpy(cp, l_host, 12); return (cp); } /* gets hostname in short form */ char *getmyname () { char *gethostname(); static char buf[32]; register char *cp = buf; gethostname(buf, 32); while (*cp++ != '.'); *--cp = '\0'; return (buf); }