Logo 
Search:

Networking Articles

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

TCP/IP program to Iterative UDP server for TIME service

Posted By: Milind Mishra     Category: Networking     Views: 5655

TCP/IP program to Iterative UDP server for TIME service.

Code for TCP/IP program to Iterative UDP server for TIME service in Networking

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

#include <stdio.h>
#include <time.h>
#include <string.h>

externint    errno;

int    passiveUDP(constchar *service);
int    errexit(constchar *format, ...);

#define    UNIXEPOCH    2208988800    /* UNIX epoch, in UCT secs    *//*------------------------------------------------------------------------ * main - Iterative UDP server for TIME service *------------------------------------------------------------------------ */int
main(int argc, char *argv[])
{
    struct sockaddr_in fsin;    /* the from address of a client    */char    *service = "time";    /* service name or port number    */char    buf[1];            /* "input" buffer; any size > 0    */int    sock;            /* server socket        */
    time_t    now;            /* current time            */int    alen;            /* from-address length        */switch (argc) {
    case    1:
        break;
    case    2:
        service = argv[1];
        break;
    default:
        errexit("usage: UDPtimed [port]\n");
    }

    sock = passiveUDP(service);

    while (1) {
        alen = sizeof(fsin);
        if (recvfrom(sock, buf, sizeof(buf), 0,
                (struct sockaddr *)&fsin, &alen) < 0)
            errexit("recvfrom: %s\n", strerror(errno));
        (void) time(&now);
        now = htonl((u_long)(now + UNIXEPOCH));
        (void) sendto(sock, (char *)&now, sizeof(now), 0,
            (struct sockaddr *)&fsin, sizeof(fsin));
    }
}
  
Share: 


Didn't find what you were looking for? Find more on TCP/IP program to Iterative UDP server for TIME service Or get search suggestion and latest updates.

Milind Mishra
Milind Mishra author of TCP/IP program to Iterative UDP server for TIME service 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!