[ntp:hackers] /dev/ntpsymlink1 -> COM1: for ntpd on Windows

Terje Mathisen terje at tmsw.no
Sun May 31 18:04:56 UTC 2009


Dave Hart wrote:
> On Sun, May 31, 2009 at 4:26 PM, Terje Mathisen <terje at tmsw.no> wrote:
>> Dave's approach is obviously "The Right Thing" to do, with one tiny caveat:
>>
>> ntpd device numbers start at 0, while Windows start at 1, and in the
>> current code this is correctly mapped.
Oops, wrong.
>>
>> I.e. 127.127.20.4 maps an NMEA gps receiver connected to COM5, while my
>> 18LVC on COM1 would use 127.127.20.0
> 
> I do not see the benefit of changing the unit number to COMx: mapping
> on Windows at this point.  127.127.x.0 has always mapped to the (never
> present) COM0:, changing that now would break existing configurations
> (and documentation) for no apparent gain, as we can now use unit
> numbers larger than 3.

I didn't realize this, mea culpa.

Anyway, that should make the conversion code even more trivial:

char *device_to_win_com(char *dev)
{
    int com = 0;
    static char comstr[24] = "COM";
    char *comp = comstr+3;

    while (*dev) {
      char c = *dev++;
      if ((c >= '0') && (c <= '9') &&
          (comp < (comstr+sizeof(comstr)-2))) { /* : + \0 */
        *comp++ = c;
      }
    }
    *comp++ = ':';
    *comp = '\0';
    return comstr;
}

Better?

Terje

-- 
- <Terje at tmsw.no>
"almost all programming can be viewed as an exercise in caching"


More information about the hackers mailing list