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

Terje Mathisen terje at tmsw.no
Sun May 31 16:26:56 UTC 2009


David J Taylor wrote:
> Dave Hart wrote:
>> I'm planning to check in changes to ports/winnt/ntpd/win32_io.c
>> common_serial_open() in the near future to implement this mapping to
>> minimize source changes to reference clock drivers, unless there is an
>> objection.
>>
>> Cheers,
>> Dave Hart
> 
> Dave,
> 
> Presumably this is purely an internal change, and the ntp.conf file syntax 
> for COM4 on Windows, as in:
> 
>   server 127.127.20.4 minpoll 4 prefer  # NMEA serial
> 
> would continue to be accepted?
> 
> If so, no objections.

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.

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

So the full logic becomes:

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

   while (*dev) {
     char c = *dev++;
     if ((c >= '0') && (c <= '9')) {
       com = com*10 + (c - '0');
     }
   }
/* Can never overflow, even with a 64-bit int since the buffer has
    room for 20 digits
  */
   sprintf(comstr+3,"%u:", com+1);

   return comstr;
}

OK?

Terje

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


More information about the hackers mailing list