Skip to content

Commit

Permalink
Merge pull request #5 from waitspring/dev
Browse files Browse the repository at this point in the history
support domain in tcping
  • Loading branch information
waitspring authored Jan 7, 2023
2 parents eb63efb + e9bb82f commit a4e0c0c
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<h1 align="center">Morning Tavern</h1>
<h4 align="center">放置一些终端小工具与代码包</h4>

[![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)

</div>
2 changes: 1 addition & 1 deletion static/morning-tavern/tcping/configure.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AC_PREREQ([2.69])
AC_INIT([morning-tavern], [1.0.2], [[email protected]])
AC_INIT([morning-tavern], [1.0.3], [[email protected]])
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([src/tcping.c])
AC_CONFIG_HEADERS([config.h])
Expand Down
2 changes: 1 addition & 1 deletion static/morning-tavern/tcping6/configure.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AC_PREREQ([2.69])
AC_INIT([morning-tavern], [1.0.2], [[email protected]])
AC_INIT([morning-tavern], [1.0.3], [[email protected]])
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([src/tcping6.c])
AC_CONFIG_HEADERS([config.h])
Expand Down
7 changes: 3 additions & 4 deletions static/spec/morning-tavern.spec
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -42,13 +42,12 @@ install -m 0664 %{_builddir}/%{name}-%{version}/searchme/searchme.conf %{buildro
%{_bindir}/tcping6

%changelog
* Sat Jan 08 2023 waitspring <[email protected]>
- Support the command tcping for domain
* Fri Jan 07 2023 waitspring <[email protected]>
- Create the package for tcping6 command
- Create the package for tcping command
- Create the package for searchme command
* Fri Dec 30 2022 waitspring <[email protected]>
- Create the package for tcping command
- Create the package for searchme command
* Thu Dec 9 2021 waitspring <[email protected]>
- Create the package for searchme command

6 changes: 3 additions & 3 deletions static/spec/readme.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tcping/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

+ 允许在 `Shell` 脚本内配合 `IFS` 命令与循环结构使用
+ 允许使用静默工作模式
+ 允许使用域名, 而实际的 TCP 连接测试使用域名解析得到的第一条 A 记录
+ 根据执行结果的不同有不同的退出码:
* TCP 连接全部建立成功使用数值 0 作为退出码
* TCP 连接部分建立成功使用数值 1 作为退出码
Expand Down
12 changes: 9 additions & 3 deletions tcping/tcping.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,24 @@ 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];
}
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);
Expand Down

0 comments on commit a4e0c0c

Please sign in to comment.