Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- l#include <stdio.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <string.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <netdb.h>
- int authentication(int socket);
- int main(int argc, char *argv[]) {
- struct sockaddr_in server;
- struct hostent *host;
- char uname[100];
- char buffer[5000];
- int portno,socky,n;
- int length = 0,ch,i,p;
- char cha;
- int *new_sock;
- int orig_length = 0;
- if(argc < 3) {
- perror("insufficient inputs"); //checking the inputs
- exit(1);
- }
- if((socky = socket(AF_INET,SOCK_STREAM,0)) < 0) {
- perror("nerror in socket creation"); //socket creation
- exit(1);
- }
- printf("nsocket successfully created");
- server.sin_family = AF_INET;
- portno = atoi(argv[2]);
- server.sin_port = htons(portno);
- host = gethostbyname(argv[1]);
- if(host == NULL) {
- perror("nerror in getting host address");
- exit(1);
- }
- memcpy (&server.sin_addr.s_addr, host->h_addr,host->h_length);
- if((connect(socky,&server,sizeof(server)))<0) {
- perror("nerror in connection");
- exit(1);
- }
- while(1) {
- printf("n select an option");
- printf("n1->student loginn2->Instructor loginn3->Admin loginn");
- printf("n came near scanf");
- scanf("%d",&ch);
- //printf("nselected value: %c",ch)
- if(ch == 1) {
- p = authentication(socky);
- } else {
- printf("n invalid option");
- }
- }
- return 0;
- }
- int authentication(int socky) {
- char buffer[5000];
- char cha;
- char uname[100];
- int n,i;
- bzero(buffer,5000);
- buffer[0] = '1';
- buffer[1] = '