diff --git a/readme.md b/readme.md index b2e15fc..a1f0364 100644 --- a/readme.md +++ b/readme.md @@ -3,7 +3,7 @@

Morning Tavern

放置一些终端小工具与代码包

-[![Version](https://img.shields.io/badge/Version-1.0.2-207F4C)](https://github.com/waitspring/morning-tavern) +[![Version](https://img.shields.io/badge/Version-1.0.3-207F4C)](https://github.com/waitspring/morning-tavern) [![License](https://img.shields.io/badge/License-Apache%202.0-373834)](https://github.com/waitspring/morning-tavern/blob/master/license) diff --git a/static/morning-tavern/tcping/configure.ac b/static/morning-tavern/tcping/configure.ac index a4466a9..c0fa5bc 100644 --- a/static/morning-tavern/tcping/configure.ac +++ b/static/morning-tavern/tcping/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ([2.69]) -AC_INIT([morning-tavern], [1.0.2], [newsfuxuanming@foxmail.com]) +AC_INIT([morning-tavern], [1.0.3], [newsfuxuanming@foxmail.com]) AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([src/tcping.c]) AC_CONFIG_HEADERS([config.h]) diff --git a/static/morning-tavern/tcping6/configure.ac b/static/morning-tavern/tcping6/configure.ac index 316dcee..6b6dbc4 100644 --- a/static/morning-tavern/tcping6/configure.ac +++ b/static/morning-tavern/tcping6/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ([2.69]) -AC_INIT([morning-tavern], [1.0.2], [newsfuxuanming@foxmail.com]) +AC_INIT([morning-tavern], [1.0.3], [newsfuxuanming@foxmail.com]) AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([src/tcping6.c]) AC_CONFIG_HEADERS([config.h]) diff --git a/static/spec/morning-tavern.spec b/static/spec/morning-tavern.spec index 7ed29cb..b3c3bf3 100755 --- a/static/spec/morning-tavern.spec +++ b/static/spec/morning-tavern.spec @@ -1,5 +1,5 @@ Name: morning-tavern -Version: 1.0.2 +Version: 1.0.3 Release: 1%{?dist} Summary: A good repository for bash tools @@ -42,13 +42,12 @@ install -m 0664 %{_builddir}/%{name}-%{version}/searchme/searchme.conf %{buildro %{_bindir}/tcping6 %changelog +* Sat Jan 08 2023 waitspring +- Support the command tcping for domain * Fri Jan 07 2023 waitspring - Create the package for tcping6 command -- Create the package for tcping command -- Create the package for searchme command * Fri Dec 30 2022 waitspring - Create the package for tcping command -- Create the package for searchme command * Thu Dec 9 2021 waitspring - Create the package for searchme command diff --git a/static/spec/readme.md b/static/spec/readme.md index ee4ad40..d48c2f5 100644 --- a/static/spec/readme.md +++ b/static/spec/readme.md @@ -1,9 +1,9 @@ # RPM 仓库结构 -`/srv/morning-tavern-1.0.2` 的目录结构如下: +`/srv/morning-tavern-1.0.3` 的目录结构如下: ``` -/srv/morning-tavern-1.0.2 +/srv/morning-tavern-1.0.3 │ ├──── searchme │ ├──── searchme @@ -40,7 +40,7 @@ ├──── BUILDROOT ├──── RPMS ├──── SOURCES - │ └──── morning-tavern-1.0.1.tar.gz + │ └──── morning-tavern-1.0.3.tar.gz ├──── SPECS │ └──── morning-tavern.spec └──── SRPMS diff --git a/tcping/readme.md b/tcping/readme.md index 2b75619..7ef2751 100644 --- a/tcping/readme.md +++ b/tcping/readme.md @@ -8,6 +8,7 @@ + 允许在 `Shell` 脚本内配合 `IFS` 命令与循环结构使用 + 允许使用静默工作模式 ++ 允许使用域名, 而实际的 TCP 连接测试使用域名解析得到的第一条 A 记录 + 根据执行结果的不同有不同的退出码: * TCP 连接全部建立成功使用数值 0 作为退出码 * TCP 连接部分建立成功使用数值 1 作为退出码 diff --git a/tcping/tcping.c b/tcping/tcping.c index 43f2567..08e5892 100644 --- a/tcping/tcping.c +++ b/tcping/tcping.c @@ -95,11 +95,13 @@ int judge_ip(char *ip, char **ipp, struct sockaddr_in *addr) { * Todo: 如果传入参数为 IPv6 地址, 抛出错误信息 * Return: IPv4 地址校验成功返回值为 1, IPv4 地址校验失败返回值为 0 */ - struct in_addr ipv4; - struct in6_addr ipv6; + struct in_addr ipv4; + struct in6_addr ipv6; + struct hostent *hostinfo; + const char tag = ':'; const char sign[2] = {'[', ']'}; - + ip[strlen(ip) - strlen(strrchr(ip, tag))] = '\0'; if (strrchr(ip, sign[0])) { ip = &strrchr(ip, sign[0])[1]; @@ -107,6 +109,10 @@ int judge_ip(char *ip, char **ipp, struct sockaddr_in *addr) { if (strrchr(ip, sign[1])) { ip[strlen(ip) - strlen(strrchr(ip, sign[1]))] = '\0'; } + hostinfo = gethostbyname(ip); // 尝试执行域名转换 + if (hostinfo) { + strcpy(ip, inet_ntoa(*(struct in_addr *)hostinfo->h_addr_list[0])); + } if (inet_pton(AF_INET, (char *)ip, &ipv4)) { addr->sin_family = AF_INET; addr->sin_addr.s_addr = inet_addr(ip);