adds additional header and link to compile

This commit is contained in:
ergz 2023-04-11 00:26:36 -07:00
parent bda67c531f
commit 079886e767
2 changed files with 23 additions and 13 deletions

View File

@ -1,4 +1,4 @@
@echo off @echo off
cl /nologo /Zi main.c ws2_32.lib cl /nologo /Zi main.c /link ws2_32.lib

34
main.c
View File

@ -1,12 +1,12 @@
#define WIN32_LEAN_AND_MEAN // Say this... #define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windows.h>
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.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_addr: pointer sockaddr struct
- ai_canonname: canonical hostname - ai_canonname: canonical hostname
- ai_next: linked list to next node - ai_next: linked list to next node
*/ */
typedef struct addrinfo {
/*typedef struct addrinfo {
int ai_flag; // address info flags int ai_flag; // address info flags
int ai_family; // address info famitly ipv4/6 int ai_family; // address info famitly ipv4/6
int ai_socktype; int ai_socktype;
@ -33,6 +33,7 @@ typedef struct addrinfo {
addrinfo *ai_next; addrinfo *ai_next;
} addrinfo; } addrinfo;
*/
/* /*
Socket address info Socket address info
@ -40,12 +41,12 @@ Socket address info
- sa_family: AF_XX (e.g AF_INET) - sa_family: AF_XX (e.g AF_INET)
- sa_data: 14 bytes of protocol address, the destination address as well as the port number - 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; unsigned short sa_family;
char *sa_data[14]; char *sa_data[14];
} sockaddr; } sockaddr;
*/
/* /*
Socket Adress Internet (ipv4) 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_addr: address struct
- sin_zero: padding to match sockaddr - sin_zero: padding to match sockaddr
*/ */
typedef sockaddr_in { /*typedef sockaddr_in {
short int sin_family; short int sin_family;
unsigned short int sin_port; unsigned short int sin_port;
in_addr sin_addr; in_addr sin_addr;
@ -67,7 +68,7 @@ typedef sockaddr_in {
typedef struct in_addr { typedef struct in_addr {
uint32_t s_addr; uint32_t s_addr;
} in_addr; } in_addr;
*/
int main() 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); return(0);
} }