Skip to content

Commit

Permalink
Merge pull request #3 from mkirchner/features/ipv6
Browse files Browse the repository at this point in the history
Add IPv6 support
  • Loading branch information
mkirchner authored Mar 24, 2023
2 parents fb48839 + 37e9e96 commit 87eccd4
Show file tree
Hide file tree
Showing 5 changed files with 498 additions and 185 deletions.
165 changes: 165 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
---
Language: Cpp
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
AttributeMacros:
- __capability
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeBraces: Linux
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
StatementAttributeLikeMacros:
- Q_EMIT
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: false
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentRequires: false
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PenaltyIndentedWhitespace: 0
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortJavaStaticImport: Before
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Latest
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 4
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
...

18 changes: 7 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ CCFLAGS=-Wall
CC=gcc

tcping.linux: tcping.c
$(CC) -o tcping $(CCFLAGS) -DHAVE_HSTRERROR tcping.c
$(CC) -o tcping $(CCFLAGS) tcping.c

tcping.openbsd: tcping.linux

tcping.solaris: tcping.c
$(CC) $(CCFLAGS) -o tcping -DHAVE_SOLARIS tcping.c -lsocket -lnsl
tcping.macos: tcping.linux

tcping.solaris26: tcping.c
$(CC) $(CCFLAGS) -o tcping tcping.c -lsocket -lnsl
tcping.openbsd: tcping.linux

tcping.aix: tcping.c
$(CC) $(CCFLAGS) -o tcping -DHAVE_STRINGS_H tcping.c
readme: man/tcping.1
groff -man -Tascii man/tcping.1 | col -bx > README

deb-linux: tcping.linux
mkdir -p debian/usr/bin
Expand All @@ -29,8 +25,8 @@ deb-linux: tcping.linux
rm -rf debian

clean:
rm -f tcping.solaris* tcping core *.o *.deb
rm -f tcping core *.o *.deb
rm -rf debian/

dist:
mkdir $(VER) ; cp $(FILES) $(VER)/ ; tar -c $(VER) | gzip -9 > $(VER).tar.gz ; rm -rf $(VER)
mkdir $(VER) ; cp $(FILES)
106 changes: 74 additions & 32 deletions README
Original file line number Diff line number Diff line change
@@ -1,45 +1,87 @@
TCPING(1) User Manuals TCPING(1)

-=[ tcping README

This software may be freely distributed under the terms of
the MIT license. See LICENSE file for details.

As of 2016, the tcping homepage is:
https://github.com/mkirchner/tcping
NAME
tcping - non-blocking TCP connection test

--=[ How to build
SYNOPSIS
tcping [-q] [-f <4|6> ] [-t timeout-sec | -u timeout-usec ] host port

On LiNUX systems: make tcping.linux
On OpenBSD: make tcping.openbsd
On Solaris 7/8: make tcping.solaris
On Solaris 2.6: make tcping.solaris26
On AIX: make tcping.aix
DESCRIPTION
tcping attempts to complete a TCP connection to a host:port combination
within the time interval timeout-[u]sec. The result of the operation
is encoded as a return value.

-=[ Return values
OPTIONS
-q Quiet flag. Suppress all informational output.

Return values to the shell are:
-1 an error occured
0 port is open
1 port is closed
2 connection establishment timed out
-f <4|6>
IP protocol family to use: 4 for IPv4, 6 for IPv6. If left
unspecifed, the implementation will use the protocol family of
the first record returned from getaddrinfo(3), based on the for-
mat of the host parameter. Specifying host as dotted-decimal
IPv4 or hex IPv6 address string will use the respective protocol
stack. Specification as a hostname character string will cause a
dependency on the order of IPv4 and IPv6 records returned from
getaddrinfo(3).

-=[ Notes
-t timeout-sec
Connection timeout in seconds.

1. Non-blocking connetcs are one of the most non-portable areas
of network programming. Hope for the best.
2. I hope AIX support works out fine. The only AIX box I have access
to returns "AIX aixterm3 3 4 0006404B4C00" (whatever this means)
on a 'uname -a'.
-u timeout-usec
Connection timeout in microseconds.

-=[ Acknowledgements
host Destination host. Either a host name node name or a numeric host
address string (i.e., a dotted-decimal IPv4 address or an IPv6
hex address), per RFC 2553.

Many thanks to
Kai Hambrecht
John Smith
Vincent Loriot
port Destination port. Either a service name or a decimal port num-
ber, per RFC 2553.

-=[ Author notes
RETURN VALUES
tcping encodes the result of the connection attempt in its return
value:

Originally released in 2003. If you happen to find any bugs or you have
improved my code, please be so kind to drop me a line. Thank you.
Marc Kirchner <mail(at)marc(dash)kirchner(dot)de>
0 The connection attempt was successful.

1 The connection attempt was unsuccessful.

2 The connection attempt timed out.

255 An error occured.

DIAGNOSTICS
Unless the quiet (-q) flag is set, the following diagnostics are issued
on stderr. The messages align with the program return value (see
above).

<host> port <port> open.
The connection attempt to host:port was successful.
<host> port <port> closed.
The connection attempt to host:port was unsuccessful and the
server side signaled a closed port.
<host> port <port> user timeout.
The connection attempt to host:port did not complete within the
user-defined timeout interval.

AUTHOR
Marc Kirchner <mail at marc-kirchner dot de>

HISTORY
tcping came to be in 2002 as a utility to allow basic TCP connection
checking and to enable failure shortcircutry before issuing network
commands with long timeouts (on Solarix 2.x, Solaris 7/8, AIX and
Linux). IPv6 functionality was added for 2.0.0 in 2023, which also
dropped support for the AIX and Solaris OS.

ACKNOWLEDGEMENTS
Many thanks to Kai Hambrecht, John Smith and Vincent Loriot.

SEE ALSO
nc(1)




Linux MARCH 2023 TCPING(1)
Loading

0 comments on commit 87eccd4

Please sign in to comment.