Logo 
Search:

Networking Articles

Submit Article
Home » Articles » Networking » TCP/IPRSS Feeds

TCP/IP program to print connection status information

Posted By: Milind Mishra     Category: Networking     Views: 2666

TCP/IP program to print connection status information.

Code for TCP/IP program to print connection status information in Networking

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

#include <stdio.h>

externchar    doecho, sndbinary, rcvbinary;    /* telnet options */externchar    *host, scrname[];
extern    FILE    *scrfp;

/*ARGSUSED*/int
status(FILE *sfp, FILE *tfp, int c)
{
    struct    sockaddr_in    sin;
    int            sinlen;

    fprintf(tfp, "\nconnected to \"%s\" ", host);

    sinlen = sizeof(sin);
    if (getsockname(fileno(sfp), (struct sockaddr *)&sin,
            &sinlen) == 0)
        fprintf(tfp, "local port %d ", ntohs(sin.sin_port));
    sinlen = sizeof(sin);
    if (getpeername(fileno(sfp), (struct sockaddr *)&sin,
            &sinlen) == 0)
        fprintf(tfp, "remote port %d ", ntohs(sin.sin_port));
    (void) putc('\n', tfp);
    if (doecho || sndbinary || rcvbinary) {
        printf("options in effect: ");
        if (doecho)
            fprintf(tfp, "remote_echo ");
        if (sndbinary)
            fprintf(tfp, "send_binary ");
        if (rcvbinary)
            fprintf(tfp, "receive_binary ");
        (void) putc('\n', tfp);
    }
    if (scrfp)
        fprintf(tfp, "scripting to file \"%s\"\n", scrname);
    return 0;
}
  
Share: 


Didn't find what you were looking for? Find more on TCP/IP program to print connection status information Or get search suggestion and latest updates.

Milind Mishra
Milind Mishra author of TCP/IP program to print connection status information is from India.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!