From 079886e767769da2755a8260a6bdd855a5dcf0e6 Mon Sep 17 00:00:00 2001 From: ergz Date: Tue, 11 Apr 2023 00:26:36 -0700 Subject: [PATCH] adds additional header and link to compile --- build.bat | 2 +- main.c | 34 ++++++++++++++++++++++------------ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/build.bat b/build.bat index 871f506..faeb142 100644 --- a/build.bat +++ b/build.bat @@ -1,4 +1,4 @@ @echo off -cl /nologo /Zi main.c ws2_32.lib +cl /nologo /Zi main.c /link ws2_32.lib diff --git a/main.c b/main.c index 0e888c3..eeb7fc4 100644 --- a/main.c +++ b/main.c @@ -1,12 +1,12 @@ -#define WIN32_LEAN_AND_MEAN // Say this... - -#include +#define WIN32_LEAN_AND_MEAN +#include #include +#include + #include #include - -#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); }