-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindowsNetworking.c
More file actions
32 lines (26 loc) · 818 Bytes
/
windowsNetworking.c
File metadata and controls
32 lines (26 loc) · 818 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
#include "windowsNetworking.h"
#include <winsock2.h>
#include <stdio.h>
void _networking_init(WSADATA * wsa) {
printf("\nInitialising Winsock...\n");
if (WSAStartup(MAKEWORD(2, 2), wsa) != 0)
{
printf("Failed. Error Code : %d", WSAGetLastError());
exit(-1);
}
printf("Initialised.\n");
}
void _networking_create_socket_(SOCKET * s) {
if((*s = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) {
printf("Could not create socket : %d\n", WSAGetLastError());
exit(-1);
}
printf("Socket Created\n");
}
void _networking_socket_bind(SOCKET * s, struct sockaddr_in * server) {
if(bind(*s, (struct sockaddr *) server, sizeof(*server)) == SOCKET_ERROR) {
printf("Bind failed with error code : %d", WSAGetLastError());
exit(-1);
}
puts("bind done");
}