加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
bugfix-fix-bind-port-in-debug-mode.patch 1.67 KB
一键复制 编辑 原始数据 按行查看 历史
hexiaowen 提交于 2019-09-30 11:10 . Package init
diff -Nur ntp-4.2.8p12.bak/ntpdate/ntpdate.c ntp-4.2.8p12/ntpdate/ntpdate.c
--- ntp-4.2.8p12.bak/ntpdate/ntpdate.c 2018-08-14 07:51:07.000000000 -0400
+++ ntp-4.2.8p12/ntpdate/ntpdate.c 2019-01-22 20:20:02.484000000 -0500
@@ -172,6 +172,7 @@
* Counter for keeping track of completed servers
*/
int complete_servers = 0;
+int bind_port = 0;
/*
* File of encryption keys
@@ -346,7 +347,7 @@
/*
* Decode argument list
*/
- while ((c = ntp_getopt(argc, argv, "46a:bBde:k:o:p:qst:uv")) != EOF)
+ while ((c = ntp_getopt(argc, argv, "46a:bBdr:e:k:o:p:qst:uv")) != EOF)
switch (c)
{
case '4':
@@ -371,6 +372,9 @@
case 'd':
++debug;
break;
+ case 'r':
+ bind_port = atoi(ntp_optarg);
+ break;
case 'e':
if (!atolfp(ntp_optarg, &tmp)
|| tmp.l_ui != 0) {
@@ -432,7 +436,7 @@
if (errflg) {
(void) fprintf(stderr,
- "usage: %s [-46bBdqsuv] [-a key#] [-e delay] [-k file] [-p samples] [-o version#] [-t timeo] server ...\n",
+ "usage: %s [-46bBdqsuv] [-a key#] [-e delay] [-k file] [-p samples] [-o version#] [-t timeo] [-r port] server ...\n",
progname);
exit(2);
}
@@ -1774,6 +1778,21 @@
exit(1);
}
}
+ else if (debug && bind_port > 0) {
+ ((struct sockaddr_in *)(res->ai_addr))->sin_port = htons(bind_port);
+ if (bind(fd[nbsock], res->ai_addr,
+ SOCKLEN((sockaddr_u *)res->ai_addr)) < 0) {
+#ifndef SYS_WINNT
+ if (errno == EADDRINUSE)
+#else
+ if (WSAGetLastError() == WSAEADDRINUSE)
+#endif /* SYS_WINNT */
+ msyslog(LOG_ERR, "the NTP socket is in use, exiting");
+ else
+ msyslog(LOG_ERR, "bind() fails: %m");
+ exit(1);
+ }
+ }
#ifdef HAVE_POLL_H
fdmask[nbsock].fd = fd[nbsock];
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化