-
Notifications
You must be signed in to change notification settings - Fork 11
/
h3wroRemoter.cpp
61 lines (48 loc) · 1.43 KB
/
h3wroRemoter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Server code (command terminal)
// Author: Szymon Kocur
#include <stdio.h>
#include <iostream>
#include <winsock2.h>
#pragma comment(lib, "ws2_32.lib")
int main(int argc, char * argv[])
{
WSADATA wsa;
int result = WSAStartup(MAKEWORD(2, 2), &wsa);
SOCKET mainSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
sockaddr_in service;
memset(&service, 0, sizeof(service));
service.sin_family = AF_INET;
service.sin_addr.s_addr = inet_addr("0.0.0.0");
service.sin_port = htons(13099);
bind(mainSocket, (SOCKADDR *)& service, sizeof(service));
if (listen(mainSocket, 1) == SOCKET_ERROR) {
printf("Error: listening on socket.\n");
getchar();
return 1;
}
SOCKET acceptSocket = SOCKET_ERROR;
printf("Waiting for client to connect ... \n");
while (acceptSocket == SOCKET_ERROR) {
acceptSocket = accept(mainSocket, NULL, NULL);
}
printf("Client connected!\n");
mainSocket = acceptSocket;
while (1) {
char sendbuf[400];
std::cout << "Command: ";
std::cin >> sendbuf;
// Because of terminating input on white spaces (std::cin), code below swap ` with blank space
char message[400];
for(int i = 0; i < 400; i++){
if(sendbuf[i] == '`'){
message[i] = ' ';
continue;
}
message[i] = sendbuf[i];
}
send(mainSocket, message, 400, 0);
std::cout << message << std::endl;
}
getchar();
return 0;
}