diff options
author | roberto <roberto@FreeBSD.org> | 2008-08-22 15:58:00 +0000 |
---|---|---|
committer | roberto <roberto@FreeBSD.org> | 2008-08-22 15:58:00 +0000 |
commit | b85c7169a740b2edf0106ad59fdaa1b0160f823c (patch) | |
tree | 2b9fb7f64eacb322e95695e412c923e97ba33e88 /contrib/ntp/ntpd/refclock_nmea.c | |
parent | 1d197cfe9feac6bc29537d8e53c30b6435937b95 (diff) | |
parent | 7a6072eb585696f8856cd498c3fd194cf49f14c6 (diff) | |
download | FreeBSD-src-b85c7169a740b2edf0106ad59fdaa1b0160f823c.zip FreeBSD-src-b85c7169a740b2edf0106ad59fdaa1b0160f823c.tar.gz |
Merge ntpd & friends 4.2.4p5 from vendor/ntp/dist into head. Next commit
will update usr.sbin/ntp to match this.
MFC after: 2 weeks
Diffstat (limited to 'contrib/ntp/ntpd/refclock_nmea.c')
-rw-r--r-- | contrib/ntp/ntpd/refclock_nmea.c | 63 |
1 files changed, 51 insertions, 12 deletions
diff --git a/contrib/ntp/ntpd/refclock_nmea.c b/contrib/ntp/ntpd/refclock_nmea.c index 28d6263..5b124cb 100644 --- a/contrib/ntp/ntpd/refclock_nmea.c +++ b/contrib/ntp/ntpd/refclock_nmea.c @@ -14,23 +14,17 @@ #if defined(REFCLOCK) && defined(CLOCK_NMEA) +#include <stdio.h> +#include <ctype.h> + #include "ntpd.h" #include "ntp_io.h" #include "ntp_unixtime.h" #include "ntp_refclock.h" #include "ntp_stdlib.h" -#include <stdio.h> -#include <ctype.h> - #ifdef HAVE_PPSAPI -# ifdef HAVE_TIMEPPS_H -# include <timepps.h> -# else -# ifdef HAVE_SYS_TIMEPPS_H -# include <sys/timepps.h> -# endif -# endif +# include "ppsapi_timepps.h" #endif /* HAVE_PPSAPI */ /* @@ -153,8 +147,53 @@ nmea_start( (void)sprintf(device, DEVICE, unit); fd = refclock_open(device, SPEED232, LDISC_CLK); - if (fd < 0) - return (0); + if (fd <= 0) { +#ifdef HAVE_READLINK + /* nmead support added by Jon Miner (cp_n18@yahoo.com) + * + * See http://home.hiwaay.net/~taylorc/gps/nmea-server/ + * for information about nmead + * + * To use this, you need to create a link from /dev/gpsX to + * the server:port where nmead is running. Something like this: + * + * ln -s server:port /dev/gps1 + */ + char buffer[80]; + char *nmea_host; + int nmea_port; + int len; + struct hostent *he; + struct protoent *p; + struct sockaddr_in so_addr; + + if ((len = readlink(device,buffer,sizeof(buffer))) == -1) + return(0); + buffer[len] = 0; + + if ((nmea_host = strtok(buffer,":")) == NULL) + return(0); + + nmea_port = atoi(strtok(NULL,":")); + + if ((he = gethostbyname(nmea_host)) == NULL) + return(0); + if ((p = getprotobyname("ip")) == NULL) + return(0); + so_addr.sin_family = AF_INET; + so_addr.sin_port = htons(nmea_port); + so_addr.sin_addr = *((struct in_addr *) he->h_addr); + + if ((fd = socket(PF_INET,SOCK_STREAM,p->p_proto)) == -1) + return(0); + if (connect(fd,(struct sockaddr *)&so_addr,SOCKLEN(&so_addr)) == -1) { + close(fd); + return (0); + } +#else + return (0); +#endif + } /* * Allocate and initialize unit structure |