Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I know it might be difficult or maybe easy, but can anyone tell me what this code does or what it is doing?
Thanks
DS

void get_this_machine_ip(char *_retIP)
{
   char host_name[128];
   struct hostent *hs;
   struct in_addr in;

   memset( host_name, 0x00, sizeof(host_name) );
   gethostname(host_name,128);
   hs = gethostbyname(host_name);

   memcpy( &in, hs->h_addr, hs->h_length );
   strcpy( _retIP, inet_ntoa(in) );
}

void translate_ip(DWORD _ip, char *_cip)
{
   struct in_addr in;

	in.S_un.S_addr = _ip;
	strcpy( _cip, inet_ntoa(in) );
}

void decode_tcp(char *_packet)
{
   TCPHEADER *tcp_header = (TCPHEADER *)_packet;
   BYTE flags = ( ntohs(tcp_header->info_ctrl) & 0x003F ); 

   printf("\n         source port      : %ld", htons(tcp_header->source_port));
}
Posted
Updated 1-May-11 7:05am
v2
Comments
Sandeep Mewara 1-May-11 10:40am    
If it's not your code, you must have copied it from somewhere, right? If so, there must be some reason/idea based on which it was reason. You can use that or share to look at this code piece.
Member 7766180 1-May-11 12:47pm    
No not my code! What is the Void mean? If I remove this code then the code doesn't build.
R. Giskard Reventlov 1-May-11 11:28am    
Hmm: at a guess I would say it is retrieving the IP address of the machine upon which the code is being run: I get that from the method signature: be surprised if it were doing ayhting else given that signature. :-)
Member 7766180 1-May-11 12:49pm    
The earlier part of the code is grabing the IP. I thought this had something else going on, perhaps voiding something if it doesn't find whatever.
Graham Breach 1-May-11 13:22pm    
No, the "void" bit means that the functions don't return values. You should really learn something about the language before you try to modify the code.

The void in the function prototype simply means that the function does not return anything via "return", everything is return by reference. You can interpret what each function does by the name (and get further details by looking at individual method calls within).

get_this_machine_ip(char *_retIP) //<-- Grabs the IP address of machine running the program (returns in _retIP)
translate_ip(DWORD _ip, char *_cip) //<-- Translates IP from one format to another (returns in _cip)
decode_tcp(char *_packet) //<-- Decodes source port from _packet (prints to screen)
 
Share this answer
 
Comments
Member 7766180 1-May-11 14:11pm    
Thank you! Once again!
DS
Albert Holguin 1-May-11 14:22pm    
no prob :)
Sergey Alexandrovich Kryukov 1-May-11 18:46pm    
Yes, but this answer is overkill. (My 5).
Please see my answer.
--SA
Bad question! If you did not take the labor of reading elementary C++ book which would explain you the very basic (at least it would explain you what's void is; otherwise you won't be able even to start coding), the CodeProject answers won't help you, not matter how good they are.

Learn at least the very basic and come back!
I only want to make your work reasonably effective and help you avoid wasting time.

Thank you for understanding.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900