-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_template
More file actions
44 lines (34 loc) · 3.35 KB
/
client_template
File metadata and controls
44 lines (34 loc) · 3.35 KB
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
void
send_inet_req()
{
int r;
int clientsock;
struct sockaddr_in client;
char buffer[BUFFSIZE];
if ((clientsock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
die("Doomed!");
memset(&client, 0, sizeof(client)); // Clear struct
client.sin_family = AF_INET; // Internet/IP
client.sin_addr.s_addr = htonl(0x12091645); // 18.9.22.69
client.sin_port = htons(80); // client port
cprintf("Connecting to MIT...\n");
if ((r = connect(clientsock, (struct sockaddr *) &client,
sizeof(client))) < 0)
die("Connection to MIT server failed!");
cprintf("Sending request to MIT...\n");
r = snprintf(buffer, BUFFSIZE, "GET /usmanm/Public/ HTTP/1.1\r\n"
"Host: web.mit.edu\r\n" "\r\n");
if ((r = write(clientsock, buffer, r)) < 0)
die("Request to MIT failed...\n");
while (1)
{
cprintf("Waiting for response from MIT...\n");
// Receive message
if ((r = read(clientsock, buffer, BUFFSIZE)) < 0)
panic("failed to read");
cprintf("Received: %s\n", buffer);
// no keep alive
break;
}
close(clientsock);
}