-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathservermain.cpp
More file actions
37 lines (26 loc) · 955 Bytes
/
servermain.cpp
File metadata and controls
37 lines (26 loc) · 955 Bytes
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/* You will to add includes here */
// Included to get the support library
#include <calcLib.h>
// Enable if you want debugging to be printed, see examble below.
// Alternative, pass CFLAGS=-DDEBUG to make, make CFLAGS=-DDEBUG
#define DEBUG
using namespace std;
int main(int argc, char *argv[]){
/*
Read first input, assumes <ip>:<port> syntax, convert into one string (Desthost) and one integer (port).
Atm, works only on dotted notation, i.e. IPv4 and DNS. IPv6 does not work if its using ':'.
*/
char delim[]=":";
char *Desthost=strtok(argv[1],delim);
char *Destport=strtok(NULL,delim);
// *Desthost now points to a sting holding whatever came before the delimiter, ':'.
// *Dstport points to whatever string came after the delimiter.
/* Do magic */
int port=atoi(Destport);
#ifdef DEBUG
printf("Host %s, and port %d.\n",Desthost,port);
#endif
}