c++ - Inspecting C Header Files Further -


i learning networking in c looking @ code of working packet sniffer within microsoft visual basic 2013.

below code creates pointer hostent structure, obtains localhost hostname, , loads hostent structure called local.

struct hostent *local; gethostname(hostname, sizeof(hostname)) local = gethostbyname(hostname); 

the next part enables address printed in dotted decimal notation.

for (i = 0; local->h_addr_list[i] != 0; ++i) {     memcpy(&addr, local->h_addr_list[i], sizeof(struct in_addr));     printf("  interface number : %d address : %s\n",i,inet_ntoa(addr)); } 

now, want understand how works , more . . .

say want understand inet_ntoa(), right-click , choose go definition or go declaration , sends me winsock2.h shows:

inet_ntoa(     __in struct in_addr in ); 

this appears show me parameter not workings of function or return value. means have refer msdn understand happening every time.

my question is: code read happening don't have use docs?

e.g. inet_ntoa function contents?

here are:

#include <stdio.h> #include <stdlib.h> #include <arpa/inet.h>  /* interface of function stupid, requires    static buffer.  relax bit in allow 1 buffer    each thread.  */  static __thread char buffer[18];  char *inet_ntoa (struct in_addr in) {    unsigned char *bytes = (unsigned char *) &in;    __snprintf (buffer, sizeof (buffer), "%d.%d.%d.%d",                bytes[0], bytes[1], bytes[2], bytes[3]);    return buffer; } 

taken inet_ntoa.c, glibc 2.23

remember glibc open source, if want explore bit , learn what's going in under hood, don't hesitate , download !

regards


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -