ccplusplus.com
Learn C, C++ Concepts
Monday, August 1, 2011
inet_ntoa sample C code
/* inet_ntoa.c * * Example using inet_ntoa(3): */ #include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
int main(int argc,char **argv) { struct sockaddr_in adr_inet;/* AF_INET */ int len_inet; /* length */ /* * Establish address (pretend we got * this address from a connecting * client): */ memset(&adr_inet,0,sizeof adr_inet); adr_inet.sin_family = AF_INET; adr_inet.sin_port = htons(9000); if ( !inet_aton("127.0.0.23", &adr_inet.sin_addr) ) { puts("bad address."); } len_inet = sizeof adr_inet; /* * Demonstrate use of inet_ntoa(3): */ printf("The IP Address is %s\n", inet_ntoa(adr_inet.sin_addr)); return 0; } /* * OUTPUT * [sgupta@rhel54x64 socket]$ ./inet_ntoa The IP Address is 127.0.0.23 [sgupta@rhel54x64 socket]$ */
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment