initial
This commit is contained in:
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
*.exe
|
||||||
|
*.ilk
|
||||||
|
*.obj
|
||||||
|
*.pdb
|
||||||
20
beej-guide-networking.sublime-project
Normal file
20
beej-guide-networking.sublime-project
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"folders":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"path": "."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
"build_systems":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "build.bat",
|
||||||
|
"shell_cmd": "build.bat",
|
||||||
|
"selector": "source.c++",
|
||||||
|
"working_dir": "$project_path",
|
||||||
|
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
1969
beej-guide-networking.sublime-workspace
Normal file
1969
beej-guide-networking.sublime-workspace
Normal file
File diff suppressed because it is too large
Load Diff
BIN
debugger.rdbg
Normal file
BIN
debugger.rdbg
Normal file
Binary file not shown.
82
main.c
Normal file
82
main.c
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
#define WIN32_LEAN_AND_MEAN // Say this...
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
#include <winsock2.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
#pragma comment(lib, "Ws2_32.lib")
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Address info
|
||||||
|
|
||||||
|
- ai_flag: address info flag
|
||||||
|
- ai_family: addres info family AF_INET (ipv4) or AF_INET6 (ipv6)
|
||||||
|
- ai_socktype: socket type SOCK_STREAM or SOCK_DGRAM
|
||||||
|
- ai_protocol: use 0 for any
|
||||||
|
- ai_addrlen: size of the ai_addr (below)
|
||||||
|
- ai_addr: pointer sockaddr struct
|
||||||
|
- ai_canonname: canonical hostname
|
||||||
|
- ai_next: linked list to next node
|
||||||
|
|
||||||
|
*/
|
||||||
|
typedef struct addrinfo {
|
||||||
|
int ai_flag; // address info flags
|
||||||
|
int ai_family; // address info famitly ipv4/6
|
||||||
|
int ai_socktype;
|
||||||
|
int ai_protocol;
|
||||||
|
size_t ai_addrlen;
|
||||||
|
sockaddr *ai_addr;
|
||||||
|
char *ai_canonname;
|
||||||
|
|
||||||
|
addrinfo *ai_next;
|
||||||
|
} addrinfo;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Socket address info
|
||||||
|
|
||||||
|
- sa_family: AF_XX (e.g AF_INET)
|
||||||
|
- sa_data: 14 bytes of protocol address
|
||||||
|
*/
|
||||||
|
typedef struct sockaddr {
|
||||||
|
unsigned short sa_family;
|
||||||
|
char *sa_data[14];
|
||||||
|
|
||||||
|
} sockaddr;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef sockaddr_in {
|
||||||
|
short int sin_family;
|
||||||
|
unsigned short int sin_port;
|
||||||
|
struct in_addr sin_addr;
|
||||||
|
unsigned char sin_zero[8];
|
||||||
|
} sockaddr_in;
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
|
||||||
|
{
|
||||||
|
WSADATA wsaData;
|
||||||
|
|
||||||
|
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
|
||||||
|
fprintf(stderr, "WSAStartup failed.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (LOBYTE(wsaData.wVersion) != 2 ||
|
||||||
|
HIBYTE(wsaData.wVersion) != 2)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"Versiion 2.2 of Winsock is not available.\n");
|
||||||
|
WSACleanup();
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("hellow world!");
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user