===============================================================================
                    AIX SOCKMON - Enhanced TCP Socket Monitor
===============================================================================

OVERVIEW
========

AIX SOCKMON is a TCP connection monitoring tool for AIX systems 
that provides real-time monitoring of TCP socket states, process management 
capabilities, and comprehensive network health analysis.

SUPPORT AND LICENSE STATEMENT
==============================

----------------------------------------------
 IBM International Program License Agreement
----------------------------------------------

 Part 1 - General Terms
 -----------------------

 PLEASE READ THIS AGREEMENT CAREFULLY BEFORE USING THE PROGRAM. IBM WILL
 ONLY LICENSE THE PROGRAM TO YOU IF YOU FIRST ACCEPT THE TERMS OF THIS
 AGREEMENT BY USING THE PROGRAM. IF YOU DO NOT AGREE TO THE TERMS OF THIS
 AGREEMENT, PROMPTLY NOTIFY THE PROVIDER OF THE PROGRAM AND REQUEST A
 REFUND OF THE AMOUNT YOU PAID.

 The Program is owned by International Business Machines Corporation or
 one of its subsidiaries (IBM) or an IBM supplier, and is copyrighted and
 licensed, not sold.

 IBM grants you a nonexclusive license for the Program. If IBM grants you
 multiple licenses for the Program, the terms of this Agreement apply to
 each license. The term "Program" means the original program and all
 whole or partial copies of it, including portions merged into other
 programs. A Program consists of machine-readable instructions,
 audio/visual content (such as images, text, recordings, or pictures), and
 related licensed materials.

 This Agreement includes Part 1 - General Terms and Part 2 - Country
 Unique Terms. The terms of Part 2 may replace or modify those of Part 1.
 "License Information," which IBM provides for the Program, may contain
 additional terms regarding the Program. Any such additional terms are
 part of this Agreement.

 1. License

 Use of the Program

 You may use the Program on only one machine at any one time, except as
 otherwise stated in this section. You agree to ensure that anyone who
 uses the Program (accessed either locally or remotely) does so only for
 your authorized use and complies with the terms of this Agreement.
 A Program is considered to be in use when it resides in memory or is
 otherwise stored on a machine. A Program stored on a network server
 solely for the purpose of being distributed to other machines is not
 considered to be in use.

 IBM specifies charges for Programs based on how much you use a Program
 (for example, the number of users), resources (for example, processor
 size), or a combination of both.

 For a Program managed by a license management tool, copies may be made
 and stored on machines under control of that tool, but your use may not
 exceed the total number of users or amount of resource authorized.
 Certain Programs IBM designates for home or travel use may be stored on
 the primary and another machine, provided the Program is not in active
 use on both machines at the same time.

 You may 1) copy the Program for backup and 2) merge the Program into
 another program. You must reproduce the copyright notice and any other
 legend of ownership on each copy, or partial copy, of the Program. You
 may use any portion of the Program IBM marks restricted (for example,
 "Restricted Materials of IBM") only to 1) resolve problems related to the
 use of the Program and 2) modify the Program so that it will work
 together with other products.

 You may not: 1) use, copy, merge, or transfer the Program except as
 provided in this Agreement; 2) reverse assemble, reverse compile, or
 otherwise translate the Program except as specifically permitted by law
 without the possibility of contractual waiver; or 3) sublicense, rent or
 lease the Program.

 Transfer of Rights and Obligations
 You may transfer all your rights and obligations under a license for a
 Program to another party, unless IBM specifies otherwise in its License
 Information.

 To transfer such rights and obligations, you must transfer a copy of this
 Agreement, the License Information, all other documentation (including
 proof of entitlement), and at least one complete, unaltered copy of the
 Program to the other party. Your license is then terminated.
 A Program which IBM licenses in multiples of two or more (for example, as
 a pack) may only be transferred in its entirety. In this case,
 individual licenses may not be transferred.

 2. Charges, Payment, and Taxes

 Payment must be made to the party (either IBM or its reseller) from whom
 you acquired the Program. If you acquired the Program from IBM, you
 agree to pay as IBM specifies. If any authority imposes a duty, tax,
 levy or fee (excluding those based on IBM's net income) on the Program
 supplied by IBM under this Agreement, you agree to pay that amount as IBM
 specifies or supply appropriate exemption documentation.
 You agree to notify IBM or its reseller and pay any applicable charges if
 you change the number of users or amount of resource authorized. IBM
 does not give refunds or credits for charges already due or paid.

 3. Limited Warranty

 For certain Programs IBM warrants that when they are used in the
 specified operating environment they will conform to their
 specifications. IBM does not warrant uninterrupted or error-free
 operation of a Program. The warranty period for a Program expires when
 its Program services are no longer available. IBM will specify in its
 License Information if a Program is warranted or not warranted.
 During the warranty period warranty service is provided, without charge,
 through defect-related Program services. Program services are available
 for at least one year following a Program's general availability.
 Therefore, the duration of warranty service depends on when you obtain
 your license. If a Program does not function as warranted during the
 first year after you obtain your license and IBM is unable to make it do
 so, you may return the Program to the party (either IBM or its reseller)
 from whom you acquired it and your money will be refunded. To be
 eligible, you must have acquired the Program while Program services
 (regardless of the remaining duration) were available for it.
 THESE WARRANTIES REPLACE ALL OTHER WARRANTIES OR CONDITIONS, EXPRESS OR
 IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OR
 CONDITIONS OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 These warranties give you specific legal rights, and you may also have
 other rights which vary from jurisdiction to jurisdiction. Some
 jurisdictions do not allow the exclusion or limitation of implied
 warranties, so the above exclusion or limitation may not apply to you.
 In that event such warranties are limited in duration to the warranty
 period. No warranties apply after that period.

 4. Program Services

 Defect-related Program services are provided for warranted Programs and
 for selected other Programs. If your reported problem can be reproduced
 in the specified operating environment, defect correction information, a
 restriction or a bypass will be issued. Program services are provided
 only for the unmodified portion of a current release of a Program.
 Information regarding how you may obtain Program services will be
 provided by the party (either IBM or its reseller) from whom you acquired
 the Program. The duration of Program services is specified in the
 License Information.

 5. Patents and Copyrights

 If a third party claims that a Program IBM provides to you infringes that
 party's patent or copyright, IBM will, at its expense, defend you against
 that claim and pay all costs, damages, and attorney's fees that a court
 finally awards, provided that you 1) promptly notify IBM in writing of
 the claim and 2) allow IBM to control, and cooperate with IBM in, the
 defense and any related settlement negotiations. If such a claim is made
 or appears likely to be made, you agree to permit IBM to enable you to
 continue to use the Program, or to modify it, or replace it with one that
 is at least functionally equivalent. If IBM determines that none of
 these alternatives is reasonably available, you agree to return the
 Program to IBM on IBM's written request. IBM will then give you a credit
 for a one-time charge Program, provided its total charges have been fully
 paid. This is IBM's entire obligation to you regarding any claim of
 infringement. IBM has no obligation regarding any claim based on any of
 the following: 1) your modification of a Program; 2) the combination,
 operation, or use of a Program with any programs, data, or apparatus that
 IBM did not provide; or 3) infringement by a non-IBM Program.

 6. Limitation of Liability

 Regardless of the basis on which you may be entitled to recover damages
 from IBM, for any claim (including fundamental breach, negligence,
 misrepresentation or other tort), IBM's liability will only be for 1)
 payments referred to in the patents and copyrights terms described above;
 2) bodily injury (including death), and damage to real property and
 tangible personal property; and 3) the amount of any other actual direct
 damages or loss, up to the greater of the equivalent of U.S. $100,000 in
 your local currency or IBM's then generally available license charge for
 the Program.

 IBM WILL NOT BE LIABLE FOR ANY SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES
 OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR
 SAVINGS), EVEN IF IBM, OR ITS RESELLER, HAS BEEN ADVISED OF THE
 POSSIBILITY OF SUCH DAMAGES. SOME JURISDICTIONS DO NOT ALLOW THE
 EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THE
 ABOVE LIMITATION OR EXCLUSION MAY NOT APPLY TO YOU.

 IBM will not be liable for 1) loss of, or damage to, your records or data
 or 2) any damages claimed by you based on any third party claim.
 This limitation of liability also applies to any developer of a Program
 supplied to IBM. It is the maximum for which we are collectively
 responsible.

 7. General

 You may terminate your license at any time. If you do so, all your
 license rights to the Program are terminated. You may keep a copy of the
 Program in your archives. IBM may terminate your license if you fail to
 comply with the terms of this Agreement. If IBM does so, all your
 license rights to the Program are terminated and you must destroy all
 your copies of it.
 You agree to comply with all applicable export laws and regulations.
 Neither party may bring a legal action under this Agreement more than two
 years after the cause of action arose.
 This Agreement is governed by the laws of the country in which you
 acquired the Program.

 -------------------------------------------------------------------------
 IBM International Program License Agreement
 Part 2 - Country Unique Terms
 -------------------------------------------------------------------------

 AUSTRALIA: Limited Warranty (Section 3): The warranties specified this
 Section are in addition to any rights you may have under the Trade
 Practices Act or other legislation and are only limited to the extent
 permitted by the applicable legislation.
 Limitation of Liability (Section 6): The following paragraph is added to
 this Section:
 Where IBM is in breach of a condition or warranty implied by the Trade
 Practices Act 1974, IBM's liability is limited to: (a) where IBM
 supplied services - the cost of having the services supplied again; or
 (b) where IBM supplied goods - the repair or replacement of the goods, or
 the supply of equivalent goods. Where that condition or warranty relates
 to right to sell, quiet possession or clear title, or the goods are of a
 kind ordinarily acquired for personal, domestic or household use or
 consumption, then none of the limitations in this paragraph apply.

 CANADA: General (Section 7): This Agreement is governed by the laws of
 the Province of Ontario.

 CENTRAL EUROPE & RUSSIA: General (Section 7): This Agreement is governed
 by the material laws of Austria. All disputes and controversies between
 the parties arising out of, or in connection with, this Agreement or its
 implementation, performance or interpretation, shall be finally settled
 under the Rules of Arbitration and Reconciliation of the Arbitral Centre
 of the Federal Economic Chamber in Vienna (Vienna Rules), by three
 arbitrators appointed in accordance with said Rules. The arbitration
 shall be held in Vienna, Austria. The official language of the
 proceedings shall be English. The decision of the arbitrators shall be
 final and binding upon both parties and therefore, the parties pursuant
 to paragraph 598(2) of the Austrian Code of Civil Procedure, expressly
 waive the application of paragraph 595(1), figure 7 of said Code. The
 clauses set forth above shall, however, in no way limit our right to
 institute proceedings in any competent court.

 ESTONIA, LATVIA, LITHUANIA: General (Section 7): All disputes arising in
 connection with the present Agreement shall be finally settled in
 Arbitration. Each party shall appoint one arbitrator and they shall
 jointly appoint the chairman. If they cannot agree on the chairman, then
 the chairman shall be appointed by the Central Chamber of Commerce in
 Helsinki. In the Arbitration the law on Arbitration will be adhered to.
 Finnish law shall apply. The arbitrators shall come together in
 Helsinki.

 GERMANY, AUSTRIA, SWITZERLAND: Limited Warranty (Section 3): The
 warranty for an IBM Program covers the functionality of the Program for
 its normal use. In case a Program is delivered without specifications,
 IBM will only warrant that the Program information correctly describes
 the Program and that the Program can be used according to the Program
 information. In case non-IBM Programs are contracted by IBM and
 delivered by IBM, the warranty for IBM Programs is applicable unless
 otherwise agreed in a transaction document. Warranty service for non-IBM
 Programs may be performed by non-IBM manufacturers.
 Limitation of Liability (Section 6): The limitations and exclusions
 specified in the Agreement will not apply to damages caused by us with
 intention or gross negligence. IBM is liable for assured
 characteristics.
 General (Section 7): The limitation on bringing a legal action is not
 applicable in case of tort by either IBM or you, or our agents.

 ISRAEL: General (Section 7): The limitation on bringing a legal action
 will be according to the law of limitation provided a notification
 concerning the cause of action was sent no more than two years after the
 cause of action arose or became known to plaintiff.

 IRELAND: Limited Warranty (Section 3): No statement in this Agreement
 shall affect the statutory rights of consumers.
 
 MIDDLE EASTERN COUNTRIES: ABU-DHABI(UAE), BAHRAIN, DUBAI(UAE), OMAN,
 KUWAIT, QATAR
 General (Section 7): This Agreement is governed by the law and
 jurisdiction of Bahrain.

 NEW ZEALAND: Limited Warranty (Section 3): The warranties specified in
 this Section are in addition to any rights you may have under the
 Consumers Guarantee Act 1993 or other legislation which cannot be
 excluded or limited. The Consumer Guarantees Act 1993 will not apply in
 respect of any goods or services which IBM provides, if you require the
 goods or services for the purposes of a business as defined in that Act.
 Limitation of Liability (Section 6): The following paragraph should be
 added to this Section:
 Where products or services are not acquired for the purposes of a
 business as defined in the Consumer Guarantees Act 1993, the limitations
 in this Section are subject to the limitations in that Act.

 PEOPLE'S REPUBLIC OF CHINA: Charges, Payment, and Taxes (Section 2): All
 banking charges incurred in the People's Republic of China shall be borne
 by you and those incurred outside the People's Republic of China shall be
 borne by us.
 General (Section 7): The laws of the State of New York govern this
 Agreement. Any dispute concerning this Agreement may be settled by
 arbitration. The arbitration will take place in Stockholm, Sweden, under
 the auspices of the International Arbitration Center in English in
 accordance with the rules then in effect under the United Nations
 Commission on International Trade Law (UNCITRAL). The arbitration award
 will be final and binding on both parties and both parties shall act
 accordingly. The arbitration fee shall be borne by the losing party.

 UNITED KINGDOM: Limitation of Liability (Section 6): Add the following
 paragraph at the end of the first paragraph:
 The limitation of liability shall not apply to any breach of IBM's
 obligations implied by Section 12 of the Sales of Goods Act 1979 or
 Section 2 of the Supply of Goods and Services Act 1982.

 UNITED STATES OF AMERICA: General (Section 7): This Agreement is
 governed by the laws of the State of New York.

 -------------------------------------------------------------------------
 Part 3 - License Information for AIX SOCKMON
 -------------------------------------------------------------------------

   THIS PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EX-
   PRESS   OR   IMPLIED,   INCLUDING   THE   IMPLIED   WARRANTIES   OF
   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  IBM does not
   warrant uninterrupted or error free operation of  the  Program,  or
   that the Program is free from claims by a third party of copyright,
   patent, trademark, trade secret, or any other intellectual property
   infringement.    IBM  has  no obligation to provide service, defect
   correction, or any maintenance for the Program. IBM  has  no  obli-
   gation to supply any Program updates or enhancements to you even if
   such are or later become available.

   Under no circumstances is IBM liable for any of the following:

   1.  third-party claims against you for losses or damages;
   2.  loss of, or damage to, your records or data; or
   3.  direct  damages,  lost  profits, lost savings, incidental, spe-
       cial, or indirect damages or other consequential damages,  even
       if IBM or its authorized supplier, has been advised of the pos-
       sibility of such damages.

   Some jurisdictions do not allow these limitations or exclusions, so
   they may not apply to you.

FILE INTEGRITY VERIFICATION
============================

Before using the program, verify the integrity of the binary file:

MD5 Checksum Verification:
  $ csum -h MD5 sockmon
  6889feda929f03e42d3fc5e3d30f1d6a  sockmon

AIX sum Command Verification:
  $ sum sockmon
  36845   150 sockmon

NOTE: If the checksums do not match the values above, do not use the binary 
as it may have been corrupted or tampered with.

INSTALLATION
============

1. Make the program executable:
   $ chmod 755 sockmon

2. Optionally, copy to a directory in your PATH:
   $ cp sockmon /usr/local/bin/

USAGE
=====

./sockmon [OPTIONS]

OPTIONS:
  -i                     Interactive mode
  -d                     Run as background daemon
  -states <list>         Comma-separated list of TCP states to monitor
                         (overrides saved configuration)
  --list-states          Show all available TCP states and exit
  -r <seconds>           Refresh interval for interactive mode (default: 5)
  -dr <seconds>          Daemon report interval (default: 60)
  -v                     Verbose output
  -debug                 Enable debug mode
  -cpu <percent>         CPU usage threshold for alerts
  -mem <kb>              Memory usage threshold for alerts
  -conn <count>          Connection count threshold for alerts
  -h, --help             Show this help message

TCP STATES AVAILABLE FOR MONITORING:
  CLOSE_WAIT   - Waiting for connection termination
  TIME_WAIT    - Waiting for enough time to pass
  FIN_WAIT_1   - Waiting for termination request
  FIN_WAIT_2   - Waiting for termination request
  SYN_SENT     - Waiting for matching connection request
  SYN_RCVD     - Waiting for confirming connection request
  ESTABLISHED  - Connection established
  LISTEN       - Listening for incoming connections
  CLOSING      - Closing connection
  LAST_ACK     - Waiting for final ACK

INTERACTIVE MODE CONTROLS:
  1-5             Switch between views (Health/Processes/Tree/States/ProcessMgmt)
  q               Quit application
  e               Export current view to timestamped file
  r               Force refresh
  s               Save configuration (in States view)
  UP/DOWN         Navigate in configuration and management modes
  SPACE           Toggle selections
  k               Kill selected processes
  a               Select all processes for termination

DAEMON MODE CONFIGURATION:
  Method 1 - Command Line (Recommended):
    Use -states flag to specify TCP states directly
    Example: ./sockmon -d -states CLOSE_WAIT,FIN_WAIT_1,SYN_SENT

  Method 2 - Interactive Configuration:
    1. Run interactive mode: ./sockmon -i
    2. Press '4' to enter States view
    3. Use SPACE to toggle states, 's' to save
    4. Run daemon mode: ./sockmon -d

  Configuration file: /tmp/sockmon_daemon_config.dat

EXAMPLES
========

Interactive Mode:
  $ ./sockmon -i                                    # Basic interactive mode
  $ ./sockmon -i -r 2 -cpu 80                       # 2s refresh, 80% CPU alert

Daemon Mode:
  $ ./sockmon -d -states CLOSE_WAIT                 # Monitor CLOSE_WAIT only
  $ ./sockmon -d -states CLOSE_WAIT,FIN_WAIT_1      # Monitor multiple states
  $ ./sockmon -d -dr 300 -states TIME_WAIT          # Daemon with 5-min reports
  $ ./sockmon -d -states TIME_WAIT -v               # Daemon with verbose output

Utilities:
  $ ./sockmon --list-states                         # Show available states
  $ ./sockmon --help                                # Show help message

KEY FEATURES
============

- Real-time TCP connection monitoring with support for all TCP states
- Interactive interface with multiple views (Health, Processes, 
  Tree, States, Process Management)
- Daemon mode with configurable reporting intervals and state monitoring
- Process management capabilities including selective process termination
- Comprehensive network health analysis and reporting
- Enhanced socket details parsing with complete connection information
- Export functionality for reports and analysis
- Command-line state specification for daemon mode operation

CONFIGURATION FILES
====================

- Daemon Configuration: /tmp/sockmon_daemon_config.dat
- Daemon PID File: /tmp/sockmon_daemon.pid
- Export Files: /tmp/sockmon_export_TIMESTAMP.txt
- Daemon Reports: /tmp/sockmon_daemon_report_TIMESTAMP.txt

SYSTEM REQUIREMENTS
===================

- Operating System: AIX 7.1 or later
- Libraries Required: 
  * libperfstat (for system performance statistics)
  * curses (for interactive interface)
- Privileges: Root or appropriate privileges for process management features
- Memory: Minimum 32 MB available memory
- Disk Space: 10 MB for temporary files and reports

ldd sockmon
sockmon needs:
         /usr/lib/libc.a(shr.o)
         /usr/lib/libcurses.a(shr42.o)
         /usr/lib/libperfstat.a(shr.o)
         /unix
         /usr/lib/libcrypt.a(shr.o)
         /usr/lib/libpthreads.a(shr_xpg5.o)
         /usr/lib/libcfg.a(shr.o)
         /usr/lib/libodm.a(shr.o)
         /usr/lib/liblvm.a(shr.o)
         /usr/lib/libcorcfg.a(shr.o)
         /usr/lib/libpthreads.a(shr_comm.o)
         /usr/lib/libsrc.a(shr.o)

TROUBLESHOOTING
===============

Common Issues:

1. Permission Denied Errors:
   - Ensure the binary has execute permissions: chmod 755 sockmon
   - Some features require root privileges

2. Library Not Found:
   - Ensure libperfstat and ncurses libraries are installed
   - Check library paths with ldd sockmon

3. No TCP States Monitored in Daemon Mode:
   - Use -states parameter to specify states explicitly
   - Or configure states in interactive mode and save with 's' key

4. Terminal Display Issues:
   - Ensure terminal supports curses
   - Try resizing terminal window
   - Use debug mode: ./sockmon -i -debug

Debug Mode:
Enable debug output for troubleshooting:
  $ ./sockmon -i -debug
  $ ./sockmon -d -states CLOSE_WAIT -debug

AUTHOR AND VERSION INFORMATION
==============================

Author: Mustafa Atallah (mustafa.atallah@ibm.com)
Version: 1.0
Created: 2025/07/15
Compatible: AIX 7.1+

RELATED DOCUMENTATION
=====================

For additional technical information and updates, refer to the IBM AIX 
documentation and technotes available through IBM Support:
https://www.ibm.com/support/pages/node/7241023

===============================================================================
Disclaimer: This program is provided AS-IS with no warranty or support by IBM. 
Use at your own risk and ensure proper testing in your environment before 
production use.
===============================================================================