![]() | |
| |||||||
| Home | Register | Blogs | FAQ | Members List | Calendar | Downloads | Arcade | Mark Forums Read |
| Languages, Compilers and Interpreters C,C++,C#,.NET,Java,PHP,Perl,SQL and more |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 |
| Консервативный Демагог Join Date: Jan 2002 Location: Кавказская Албания
Posts: 889
Rep Power: 7 Reputation:
10 | Hi there. problema v chem.. <BR><BLOCKQUOTE><font size="1" face="MS Sans Serif, Verdana, Helvetica, sans-serif">code:</font><HR><pre><BR> struct hostent *hp;<BR> long ip;<BR> if((hp=gethostbyname(name))==NULL)<BR> {<BR> fprintf(stderr,"Can't resolve host.\n");<BR> exit(0);<BR> }<BR> memcpy(&ip,(hp->h_addr),4);<BR> return ip;<BR></pre><HR></BLOCKQUOTE> ne pochemuto ne rabotaet.<BR>Who can help me?
__________________ Праздник к нам приходит... |^^^^^^^^^'''^\| ||\__ | ВОДКА-ВОДКА | ||','''|'''''''\_____,_ | _..... _ | ||_ _|'__|_____||.........| | '(@)'(@)'(@)''''''''''''''''''''''*|(@)""""|(@)* |
| | |
| | #2 |
| Administrator Join Date: Sep 2001 Location: Yerevan, Armenia
Posts: 7,144
Blog Entries: 15 Rep Power: 10 Reputation:
278 | Hi.<BR>If that's all you wrote then you forgot WSAStartup which in fact is loading winsock dynamic libraries into your process memory and initializing it so your application can be prepared to call gethostbyname(). The code is following:<BR><BLOCKQUOTE><font size="1" face="MS Sans Serif, Verdana, Helvetica, sans-serif">code:</font><HR><pre><BR> WSADATA wsaData;<BR> if(WSAStartup(0x0101, &wsaData))<BR> {<BR> printf("WSAStartup failed %s\n", WSAGetLastError());<BR> } // Do your stuff here </pre><HR></BLOCKQUOTE> ...and don't forget to call WSACleanup() once you've done with sockets. |
| | |
| | #3 |
| Banned Join Date: Jan 2002 Location: Yerevan
Posts: 1,503
Rep Power: 0 Reputation:
10 | Es ays code ogtagorcel em vor stanam IP- address in standard notation (dotted)...<BR><BLOCKQUOTE><font size="1" face="MS Sans Serif, Verdana, Helvetica, sans-serif">code:</font><HR><pre> <BR> char name[100];<BR> struct hostent *hp;<BR> long ip; WORD wVersionRequested; <BR>WSADATA wsaData; <BR>int err=0; <BR>int wsaerr=0; wVersionRequested = MAKEWORD(1, 1); <BR>err = WSAStartup(wVersionRequested,&wsaData); <BR>wsaerr=WSAGetLastError(); <BR> <BR>if (err != 0) <BR> return 123; <BR> <BR>if ( LOBYTE( wsaData.wVersion )!= 1||HIBYTE( wsaData.wVersion )!= 1) <BR>{<BR> WSACleanup(); <BR> return 1234; <BR>} <BR>if ( LOBYTE( wVersionRequested ) < 1 || <BR> ( LOBYTE( wVersionRequested ) == 1 && <BR> HIBYTE( wVersionRequested ) < 1 ) <BR> )<BR> return WSAVERNOTSUPPORTED; gethostname( name, sizeof( name )); if((hp=gethostbyname(name))==NULL)<BR> {<BR> fprintf(stderr,"Can't resolve host.\n");<BR> exit(0);<BR> } memcpy(&ip,&*(*((*hp).h_addr_list)),4);<BR>//or:<BR> memcpy(&ip,(hp->h_addr),4); //The macro h_addr is defined to be //h_addr_list[0] for compatibility with older //software. <BR> <BR> return ip;<BR> </pre><HR></BLOCKQUOTE> |
| | |
![]() |
| Thread Tools | |
| Display Modes | |
| |