25 March, 2015

MCQ REVIEW (MST-II)

                                                                    SET-I
Questions (8M)
Ans
1Q. SPP stands for
a) Sequence Packet protocol   b)  Sequenced Packet Protocol  c) Sequened Packet Protocol d) Seqence Packet Protol
B
2Q. SNA stands for
a) System Network Architectre    b) System Network Architecture        c) System Network Architeture
d) System Network Architeture
B
3Q. How many layers in XNS and SNA protocol respectively?
     a) 6&5                                b) 5&6                     c) 5&5                     d)6&6
B
4Q. Which protocols need services from other protocols
    a) XNS                                b)SNA                  c)NetBIOS              d)XNS & SNA         e) all  of the above
D
5Q. At least how many arguments are required for Memset() functions?
     a) 2                     b) 3                          c) 4                          d) 5
B
6Q. How many bit of  IP or port  address will be converted by using htons functions?
     a)  16bit                             b)32bit                    c) both a & b           d) None of the above
A
7. Which functions are used for both connectionless and conncetion mode.
    a) Sendto()          b) recvfrom()          c) Sendto & rcvfrom()             d) sendto()&recvfrom().
D
8. Socklen_t is
a) Unsigned integral length of atleast of 32 bit    b) Unsigned integral length of atleast of 16 bit
c) Signed integral length of atleast of 32 bit.        d) Signed integral length of atleast of 16 bit
A
9. After how many hours the KEEPALIVE option is trigger
       a)     1               b)2                           c)3            d)4 
B
10. How many ways to get and set the socket option that affect a socket.
      a) 3                   b)2                             c)4          d)1
A
11. How many arguments are required for setsocket() and getsocket() function respectively.
      a)3&3                                b)5&5                      c)3&5                      d) 5&3
B
12.  IP level is used to indicate
    a) Generic option                        b) IPv4             c) IPv6     d) Both IPV4 and IPV6
B
13. What is difference between TYPE ad TOS.
a) TYPE is used with IPv6  and TOS used with IPV4    b) TYPE is used with generic option and TOS used with IPV4
c) TYPE is used with IPV4 and TOS used with generic option.       d) All of the above
B
14Q. In which function the EOF is by default available ?
     a) printf()                 b) putc ()             c) Snprintf()            d) all of the above
C
15Q. Ctime is a
        a) Function           b) Data type            c) both a & b        d) None
A
16Q. VTAM stands for
   a) Virtual Telecommunication Access Method                b) Virtual Telecomunication Acess Method
   c) Virtual Telecomunication Access Method                   d) Virtual Telecommunication Acces Method
A
                                                                    SET-II
Questions (8M)
Ans
1Q. Which protocols need services from other protocols
       a) XNS                             b)SNA                        c)XNS & SNA            d)NetBIOS                           e) all of above
C
2Q. which one is a connectionless?
     a) TCP and UDP                     b) TCP & IP           c )UDP & IP             d) UDP only
C
3Q. SDLC stands for
       a) Synchrnous Data Link Control                      b) Synchronous Data Link Control
       c) Synchronous data lnk Control                        d) Synchronous Data Lnk Control
B
4Q. VTAM stands for
      a) Virtual Telecomunication Access Method                b) Virtual Telecomunication Acess Method
      c) Virtual Telecommunication Access Method                             d) Virtual Telecommunication Acces Method
C
Q5. Which function is used to convert IPv4 and IPv6 addresses from text to binary form
      a) Inet_pton()                       b) htons()                              c)htonl()                                d) Inet_Addr()
A
Q6. In which function the EOF is by default available ?
       a) getc ()                              b) putc()                               c ) Snprintf()          d) all of the above
C
Q7. Ctime is a
        a) Function                           b) Datatype                             c) both a & b              d) None
A
Q8. SO level is used with
       a) Generic socket option   b) TCP                                      c )IPv4                     d) IPv6
A
Q9.  IP level is used to indicate
      a) Generic option                                    b) IPv6                           c) IPv4                         d) Both IPV4 and IPV6
C
Q10. What is difference between TYPE ad TOS.
a) TYPE is used with IPv6  and TOS used with IPV4         b) TYPE is used with generic option and TOS used with IPV4
c) TYPE is used with IPV4 and TOS used with generic option.              d) All of the above
B
Q11. How many layers in XNS and SNA protocol respectively?
         a) 6&5                                  b)6&6                             c) 5&5                     d) 5&6
D
Q12.  How many arguments are required for setsocket() and getsocket() function respectively.
          a)3&3                               b) 5&3                     c)3&5                 d)5&5
D
Q13. Socklen_t is
        a) Signed integral length of atleast of 32 bit.              b) Unsigned integral length of atleast of 16 bit
        c) Unsigned integral length of atleast of 32 bit           d) Signed integral length of atleast of 16 bit
C
Q14. SNA stands for
       a) System Network Architecture                                 b) System Network Architectre         
       c) System Network Architeture                                   d) System Network Architeture
A
Q15.   Accept system calls used in
a)        Server side                       b) Client side                     c) Both a & b                d) intermediate side
A
Q16. How many bit of  IP or port  address will be converted by using htonl functions?
               a)32bit                              b)  16bit                        c) both a & b                d) None of the above
A


22 March, 2015

NWP-Practical-6

                                                                                     Practical-6

AIM: WAP to send date and time by server to client by using TCP socket.
Theory: RHS
#include “sys/socket.h> “
#include “netinet/in.h”
#include “arpa/inet.h”
#include “stdio.h”
#include “stdlib.h”
#include “unistd.h”
#include “errno.h”
#include “string.h”
#include “sys/types.h”
#include “time.h”
int main(int argc, char *argv[])
{
    int listenfd = 0, connfd = 0;
    struct sockaddr_in serv_addr;
    char sendBuff[1025];
    time_t ticks;
    listenfd = socket(AF_INET, SOCK_STREAM, 0);
    memset(&serv_addr, '0', sizeof(serv_addr));
    memset(sendBuff, '0', sizeof(sendBuff));
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
    serv_addr.sin_port = htons(5000);
    bind(listenfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
    listen(listenfd, 10);
    while(1)
    {
        connfd = accept(listenfd, (struct sockaddr*)NULL, NULL);
        ticks = time(NULL);
        snprintf(sendBuff, sizeof(sendBuff), "%.24s\r\n", ctime(&ticks));
        write(connfd, sendBuff, strlen(sendBuff));
        close(connfd);
        sleep(1);
     }
}



TCP Client Socket
#include “sys/socket.h> “
#include “netinet/in.h”
#include “arpa/inet.h”
#include “stdio.h”
#include “stdlib.h”
#include “unistd.h”
#include “errno.h”
#include “string.h”
#include “sys/types.h”
#include “time.h”
int main(int argc, char *argv[])
{
    int sockfd = 0, n = 0;
    char recvBuff[1024];
    struct sockaddr_in serv_addr;
    if(argc != 2)
    {
        printf("\n Usage: %s \n",argv[0]);
        return 1;
    }
    memset(recvBuff, '0',sizeof(recvBuff));
    if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
    {
        printf("\n Error : Could not create socket \n");
        return 1;
    }
   memset(&serv_addr, '0', sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_port = htons(5000);
    if(inet_pton(AF_INET, argv[1], &serv_addr.sin_addr)<=0)
    {
        printf("\n inet_pton error occured\n");
        return 1;
    }
    if( connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
    {
       printf("\n Error : Connect Failed \n");
       return 1;
    }
    while ( (n = read(sockfd, recvBuff, sizeof(recvBuff)-1)) > 0)
    {
        recvBuff[n] = 0;
        if(fputs(recvBuff, stdout) == EOF)
        {
            printf("\n Error : Fputs error\n");
        }
    }
    if(n < 0)
    {
       printf("\n Read error \n");
    }
    return 0;
}

Output: LHS
Compile and Run
Firstly Compile and Run the server file on Terminal 1.
Now Compile and Run the client file in Terminal 2, with server IP address.
Now Run client on Terminal 2
$ ./a.out 127.0.0.1 (For same M/C)
Output:
Sun Dec  18 22:22:14 2011on the its socket descriptor.

NWP-Practical-7

                                                                      Practical#7
AIM: Program to convert lower-case character into upper-case character using UDP Socket.
Theory: RHS:
/************* UDP SERVER CODE *******************/

#include “stdio.h”
#include “sys/socket.h”
#include “netinet/in.h”
#include “string.h”
#include “stdlib.h”
int main()
{
  int udpSocket, nBytes;
  char buffer[1024];
  struct sockaddr_in serverAddr, clientAddr;
  struct sockaddr_storage serverStorage;
  socklen_t addr_size, client_addr_size;
  int i;

  /*Create UDP socket*/
  udpSocket = socket(PF_INET, SOCK_DGRAM, 0);

  /*Configure settings in address struct*/
  serverAddr.sin_family = AF_INET;
  serverAddr.sin_port = htons(7891);
  serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
  memset(serverAddr.sin_zero, '\0', sizeof serverAddr.sin_zero);  

  /*Bind socket with address struct*/
  bind(udpSocket, (struct sockaddr *) &serverAddr, sizeof(serverAddr));

  /*Initialize size variable to be used later on*/
  addr_size = sizeof serverStorage;

  while(1){
/* Try to receive any incoming UDP datagram. Address and port of    requesting client will be stored on serverStorage variable */
    nBytes = recvfrom(udpSocket,buffer,1024,0,(struct sockaddr *)&serverStorage, &addr_size);

    /*Convert message received to uppercase*/
    for(i=0;i
      buffer[i] = toupper(buffer[i]);

    /*Send uppercase message back to client, using serverStorage as the address*/
    sendto(udpSocket,buffer,nBytes,0,(struct sockaddr *)&serverStorage,addr_size);
  }

  return 0;
}


/************* UDP CLIENT CODE *******************/
 
//#include “stdio.h” //#include “sys/socket.h” //#include “netinet/in.h” //#include “string.h” //#include “stdlib.h”
int main(){
  int clientSocket, portNum, nBytes;
  char buffer[1024];
  struct sockaddr_in serverAddr;
  socklen_t addr_size;
 
  /*Create UDP socket*/
  clientSocket = socket(PF_INET, SOCK_DGRAM, 0);
 
  /*Configure settings in address struct*/
  serverAddr.sin_family = AF_INET;
  serverAddr.sin_port = htons(7891);
  serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
  memset(serverAddr.sin_zero, '\0', sizeof serverAddr.sin_zero);  
 
  /*Initialize size variable to be used later on*/
  addr_size = sizeof serverAddr;
 
  while(1){
    printf("Type a sentence to send to server:\n");
    fgets(buffer,1024,stdin);
    printf("You typed: %s",buffer);
    nBytes = strlen(buffer) + 1;
    
    /*Send message to server*/
    sendto(clientSocket,buffer,nBytes,0,(struct sockaddr *)&serverAddr,addr_size);
 
    /*Receive message from server*/
                nBytes = recvfrom(clientSocket,buffer,1024,0,NULL, NULL);
    printf("Received from server: %s\n",buffer);
 
  }
  return 0;
}

Output:LHS
Compile & Run
Firstly compile and run server socket on Terminal1.
Secondly compile and run client socket on Terminal2.
Now type string on client socket on Terminal2.

Server will send back a string uppercase.