adds additional header and link to compile
This commit is contained in:
parent
bda67c531f
commit
079886e767
|
@ -1,4 +1,4 @@
|
|||
@echo off
|
||||
|
||||
cl /nologo /Zi main.c ws2_32.lib
|
||||
cl /nologo /Zi main.c /link ws2_32.lib
|
||||
|
||||
|
|
34
main.c
34
main.c
|
@ -1,12 +1,12 @@
|
|||
#define WIN32_LEAN_AND_MEAN // Say this...
|
||||
|
||||
#include <windows.h>
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#pragma comment(lib, "Ws2_32.lib")
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
|
||||
|
||||
/*
|
||||
|
@ -20,9 +20,9 @@ Address info
|
|||
- ai_addr: pointer sockaddr struct
|
||||
- ai_canonname: canonical hostname
|
||||
- ai_next: linked list to next node
|
||||
|
||||
*/
|
||||
typedef struct addrinfo {
|
||||
|
||||
/*typedef struct addrinfo {
|
||||
int ai_flag; // address info flags
|
||||
int ai_family; // address info famitly ipv4/6
|
||||
int ai_socktype;
|
||||
|
@ -33,6 +33,7 @@ typedef struct addrinfo {
|
|||
|
||||
addrinfo *ai_next;
|
||||
} addrinfo;
|
||||
*/
|
||||
|
||||
/*
|
||||
Socket address info
|
||||
|
@ -40,12 +41,12 @@ Socket address info
|
|||
- sa_family: AF_XX (e.g AF_INET)
|
||||
- sa_data: 14 bytes of protocol address, the destination address as well as the port number
|
||||
*/
|
||||
typedef struct sockaddr {
|
||||
/*typedef struct sockaddr {
|
||||
unsigned short sa_family;
|
||||
char *sa_data[14];
|
||||
|
||||
} sockaddr;
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
Socket Adress Internet (ipv4)
|
||||
|
@ -57,7 +58,7 @@ This struct is used to replace sockaddr in instances where family = AF_INET
|
|||
- sin_addr: address struct
|
||||
- sin_zero: padding to match sockaddr
|
||||
*/
|
||||
typedef sockaddr_in {
|
||||
/*typedef sockaddr_in {
|
||||
short int sin_family;
|
||||
unsigned short int sin_port;
|
||||
in_addr sin_addr;
|
||||
|
@ -67,7 +68,7 @@ typedef sockaddr_in {
|
|||
typedef struct in_addr {
|
||||
uint32_t s_addr;
|
||||
} in_addr;
|
||||
|
||||
*/
|
||||
|
||||
int main()
|
||||
{
|
||||
|
@ -89,7 +90,16 @@ int main()
|
|||
}
|
||||
}
|
||||
|
||||
printf("hellow world!");
|
||||
|
||||
char ip4[INET_ADDRSTRLEN];
|
||||
struct sockaddr_in sa; // ipv4 ip address
|
||||
|
||||
inet_pton(AF_INET, "10.12.110.57", &(sa.sin_addr));
|
||||
inet_ntop(AF_INET, &(sa.sin_addr), ip4, INET_ADDRSTRLEN);
|
||||
|
||||
printf("the ipv4 address is: %s\n", ip4);
|
||||
|
||||
printf("hellow world!\n");
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue