Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h> //printf
- #include<string.h> //strlen
- #include<stdlib.h> //atoi
- #include<sys/socket.h> //socket
- #include<arpa/inet.h> //inet_addr
- #include <fcntl.h> //for open
- #include <unistd.h> //for close
- #define DEFAULT_BUFLEN 512
- #define DEFAULT_PORT 27015
- char username[32],password[15];
- char chek[2];
- void SendMessage();
- void ReceiveMessage();
- void LogIn();
- void LogOut();
- void LogIn()
- {
- int j;
- begin:
- for(j = 0; j < 15; j++)
- username[j] = '\0';
- for(j = 0; j < 15; j++)
- password[j] = '\0';
- printf("\n");
- printf(" \n Connecting to proxy server \n");
- printf("\n");
- char buffer[256];
- char *ptrBuff;
- ptrBuff = buffer;
- *(ptrBuff++) = 5;
- *(ptrBuff++) = 2;
- *(ptrBuff++) = 0x00;
- *(ptrBuff++) = 0x02;
- send(proxySocket, ptrBuff, buffer-ptrBuff, 0);
- printf("Username: ");
- gets(username);
- printf("Password: ");
- gets(password);
- send(sock, username, 15, 0);
- send(sock, password, 15, 0);
- recv(Proxysock, chek, 2, 0);
- if(chek[0] == '0'){
- printf("\n Wrong username/password! Try again. \n");
- goto begin;
- }
- else if(chek[0] == '1')
- printf("\n You have access to server\n");
- }
- void ReceiveMessage()
- {
- char message[20];
- int j;
- recv(Proxysock,message,256,0);
- printf(" \n You sent this message to server \n");
- printf(message);
- printf("\n");
- }
- void SendMessage()
- {
- char message[256];
- printf("\n Send message to server.\n");
- printf("\n Message: \n");
- printf("\n");
- scanf(" %s",message);
- if(send(Proxysock, message, 256, 0) < 0)
- printf("Sending failed.");
- else
- printf("\n Message sent to server.\n", receiver);
- }
- void LogOut()
- {
- printf("\n You are logged out.\n\n");
- printf(" \n --------------------- \n");
- LogIn();
- }
- int main(int argc , char *argv[])
- {
- char option='1';
- char answer='N';
- struct sockaddr_in proxy_server_side;
- Proxysock = socket(AF_INET , SOCK_STREAM , 0);
- proxy_server_side.sin_addr.s_addr = inet_addr("127.0.0.1");
- proxy_server_side.sin_family = AF_INET;
- proxy_server_side.sin_port = htons(DEFAULT_PORT);
- if (connect(Proxysock , (struct sockaddr *)&proxy_server_side , sizeof(proxy_server_side)) < 0){
- perror("Connect failed. Error");
- return 1;
- }
- LogIn();
- while(answer=='N')
- {
- SendMessage();
- ReceiveMessage();
- printf("Would you like to dissconnect? Y/N \n");
- scanf(answer);
- }
- send(Proxysock,option,2,0);
- LogOut();
- close(Proxysock);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement