Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 306139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:26:22+00:00 2026-05-12T07:26:22+00:00

Assuming that you do not have access to the SOCKET handlers.

  • 0

Assuming that you do not have access to the SOCKET handlers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:26:22+00:00Added an answer on May 12, 2026 at 7:26 am

    Use either GetUdpTable or GetTcpTable functions.

    Example code for GetTcpTable below (from http://msdn.microsoft.com/en-us/library/aa366026%28VS.85%29.aspx)

    // Need to link with Iphlpapi.lib and Ws2_32.lib
    #include <winsock2.h>
    #include <ws2tcpip.h>
    #include <iphlpapi.h>
    #include <stdio.h>
    
    #pragma comment(lib, "iphlpapi.lib")
    #pragma comment(lib, "ws2_32.lib")
    
    #define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
    #define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
    
    /* Note: could also use malloc() and free() */
    
    int main()
    {
    
        // Declare and initialize variables
        PMIB_TCPTABLE pTcpTable;
        DWORD dwSize = 0;
        DWORD dwRetVal = 0;
    
        char szLocalAddr[128];
        char szRemoteAddr[128];
    
        struct in_addr IpAddr;
    
        int i;
    
        pTcpTable = (MIB_TCPTABLE *) MALLOC(sizeof (MIB_TCPTABLE));
        if (pTcpTable == NULL) {
            printf("Error allocating memory\n");
            return 1;
        }
    
        dwSize = sizeof (MIB_TCPTABLE);
    // Make an initial call to GetTcpTable to
    // get the necessary size into the dwSize variable
        if ((dwRetVal = GetTcpTable(pTcpTable, &dwSize, TRUE)) ==
            ERROR_INSUFFICIENT_BUFFER) {
            FREE(pTcpTable);
            pTcpTable = (MIB_TCPTABLE *) MALLOC(dwSize);
            if (pTcpTable == NULL) {
                printf("Error allocating memory\n");
                return 1;
            }
        }
    // Make a second call to GetTcpTable to get
    // the actual data we require
        if ((dwRetVal = GetTcpTable(pTcpTable, &dwSize, TRUE)) == NO_ERROR) {
            printf("\tNumber of entries: %d\n", (int) pTcpTable->dwNumEntries);
            for (i = 0; i < (int) pTcpTable->dwNumEntries; i++) {
                IpAddr.S_un.S_addr = (u_long) pTcpTable->table[i].dwLocalAddr;
                strcpy_s(szLocalAddr, sizeof (szLocalAddr), inet_ntoa(IpAddr));
                IpAddr.S_un.S_addr = (u_long) pTcpTable->table[i].dwRemoteAddr;
                strcpy_s(szRemoteAddr, sizeof (szRemoteAddr), inet_ntoa(IpAddr));
    
                printf("\n\tTCP[%d] State: %ld - ", i,
                       pTcpTable->table[i].dwState);
                switch (pTcpTable->table[i].dwState) {
                case MIB_TCP_STATE_CLOSED:
                    printf("CLOSED\n");
                    break;
                case MIB_TCP_STATE_LISTEN:
                    printf("LISTEN\n");
                    break;
                case MIB_TCP_STATE_SYN_SENT:
                    printf("SYN-SENT\n");
                    break;
                case MIB_TCP_STATE_SYN_RCVD:
                    printf("SYN-RECEIVED\n");
                    break;
                case MIB_TCP_STATE_ESTAB:
                    printf("ESTABLISHED\n");
                    break;
                case MIB_TCP_STATE_FIN_WAIT1:
                    printf("FIN-WAIT-1\n");
                    break;
                case MIB_TCP_STATE_FIN_WAIT2:
                    printf("FIN-WAIT-2 \n");
                    break;
                case MIB_TCP_STATE_CLOSE_WAIT:
                    printf("CLOSE-WAIT\n");
                    break;
                case MIB_TCP_STATE_CLOSING:
                    printf("CLOSING\n");
                    break;
                case MIB_TCP_STATE_LAST_ACK:
                    printf("LAST-ACK\n");
                    break;
                case MIB_TCP_STATE_TIME_WAIT:
                    printf("TIME-WAIT\n");
                    break;
                case MIB_TCP_STATE_DELETE_TCB:
                    printf("DELETE-TCB\n");
                    break;
                default:
                    printf("UNKNOWN dwState value\n");
                    break;
                }
                printf("\tTCP[%d] Local Addr: %s\n", i, szLocalAddr);
                printf("\tTCP[%d] Local Port: %d \n", i,
                       ntohs((u_short)pTcpTable->table[i].dwLocalPort));
                printf("\tTCP[%d] Remote Addr: %s\n", i, szRemoteAddr);
                printf("\tTCP[%d] Remote Port: %d\n", i,
                       ntohs((u_short)pTcpTable->table[i].dwRemotePort));
            }
        } else {
            printf("\tGetTcpTable failed with %d\n", dwRetVal);
            FREE(pTcpTable);
            return 1;
        }
    
        return 0;    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 206k
  • Answers 206k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The actual answer first: See Goz's answer. Keep 24 separate… May 12, 2026 at 9:05 pm
  • Editorial Team
    Editorial Team added an answer This, like other MVC-specific settings, is not settable via Web.config.… May 12, 2026 at 9:05 pm
  • Editorial Team
    Editorial Team added an answer Do you know about language grammars? Assuming yes, you have… May 12, 2026 at 9:05 pm

Related Questions

OK, probably best to give an example here of what I mean. Imagine a
After this comment to one of my questions, I'm thinking if it is better
What is the purist or correct way to access an object's properties from within
Consider the following example. I have an interface MyInterface, and then two abstract classes

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.