Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!asuvax!ncar!elroy.jpl.nasa.gov!usc!sdd.hp.com!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!wuarchive!udel!rochester!cornell!uw-beaver!mit-eddie!bbn.com!papaya.bbn.com!rsalz From: rsalz@bbn.com (Rich Salz) Newsgroups: news.software.b Subject: Re: Ideas for Message-ID's Message-ID: <3434@litchi.bbn.com> Date: 22 Mar 91 13:35:43 GMT References: <3427@litchi.bbn.com> Organization: BBN Systems and Technology, Inc. Lines: 129 I got email pointing out that if the PID wraps around in less than 24 hours, and the new process posts within the same second, there will be a conflict. Hmm... I don't think this is likely unless the machine crashes a lot. (Maybe it *IS* that likely. :-) At any rate, here's what I'm going to do now: where ddd The day of the year, in radix 64 (not fixed width) sss The second within the day, in radix 64 (not fixed width) ppp The process ID, in radix 64 (not fixed width) fqdn The fully-qualified domain name Here's some sample code: /* ** Test program to generate Message-ID's. ** The ID includes the day number, the second within the day, and the current ** process ID. To conserver space, they are decoded into radix-64 strings, ** using [0-9a-zA-Z.+] to represent 0..63. Assumes 32-bit longs. ** ** Rich $alz , 22-March-1991. */ #include #include #include static char ALPHABET[] = "+.ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba9876543210"; extern char *strchr(); /* ** Turn a number into a Radix-64 string. */ void Radix64(l, buff) register unsigned long l; register char *buff; { register char *p; register int i; char temp[20]; /* Simple sanity checks. */ l &= 0xFFFFFFFF; if (l == 0) { *buff++ = '0'; *buff = '\0'; return; } /* Format the string, in reverse. */ for (p = temp; l; l >>= 6) *p++ = ALPHABET[(int)(l & 077)]; /* Reverse it. */ for (i = p - temp; --i >= 0; ) *buff++ = *--p; *buff = '\0'; } /* ** Decode and print a radix-64 string as a number. */ Decode64(what, l, p) char *what; long l; char *p; { long l2; char *cp; printf("%s: %ld = %s = ", what, l, p); for (l2 = 0; *p; p++) { if ((cp = strchr(ALPHABET, *p)) == NULL) { printf("-->Invalid char %c\n", *p); return; } l2 = (l2 << 6) + cp - ALPHABET; } printf("%ld\n", l2); } /* ** Stub routine to get the fully-qualified domain name of this host. */ char * GetFQDN() { static char buff[256]; gethostname(buff, sizeof buff); return buff; } main() { struct tm *gmt; time_t now; char day64[20]; char pid64[20]; char sec64[20]; unsigned long day; unsigned long sec; unsigned long pid; (void)time(&now); gmt = gmtime(&now); day = gmt->tm_year * 1000L + gmt->tm_yday; sec = gmt->tm_hour * 3600L + gmt->tm_min * 60L + gmt->tm_sec; pid = getpid(); Radix64(day, day64); Radix64(sec, sec64); Radix64(pid, pid64); printf("<%s.%s.%s@%s>\n", day64, sec64, pid64, GetFQDN()); Decode64("day", day, day64); Decode64("sec", sec, sec64); Decode64("pid", pid, pid64); } -- Please send comp.sources.unix-related mail to rsalz@uunet.uu.net. Use a domain-based address or give alternate paths, or you may lose out.