[prev in list] [next in list] [prev in thread] [next in thread]
List: mingw-users
Subject: RE: [Mingw-users] [mingw - C/C++] gethostname() is failing
From: "WELLS, ROGER K." <ROGER.K.WELLS () saic ! com>
Date: 2005-11-21 16:37:10
Message-ID: DE31A43DBCABD64A9397DDFD45B89220DBA6CF () 0015-its-exmb01 ! us ! saic ! com
[Download RAW message or body]
I think that the error is just telling you that you haven't allocated any
memory to hold the name. In any case you have allocate storage for the
hostname:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>
#define MAX_HOST_LEN 512
int main()
{
int counter = 2;
char hostname[MAX_HOST_LEN];
WORD wVersionRequested;
WSADATA wsaData;
wVersionRequested = MAKEWORD(1, 1);
if (WSAStartup(wVersionRequested,&wsaData))
{
printf("\nWSAStartup() failed");
exit(1);
}
counter = gethostname(hostname, MAX_HOST_LEN);
printf("Details: %d, %s\n", counter, hostname);
return 0;
}
This gives: Details: 0, rwells-w2k
On my system: WinXP SP2, GCC 3.4.4
Roger Wells, P.E.
SAIC
221 Third St
Newport, RI 02840
401-847-4210 (voice)
401-849-1585 (fax)
roger.k.wells@saic.com
-----Original Message-----
From: mingw-users-admin@lists.sourceforge.net
[mailto:mingw-users-admin@lists.sourceforge.net] On Behalf Of
SourceForge.net
Sent: Monday, November 21, 2005 10:56 AM
To: noreply@sourceforge.net
Subject: [Mingw-users] [mingw - C/C++] gethostname() is failing
Read and respond to this message at:
https://sourceforge.net/forum/message.php?msg_id=3436821
By: db_parida
Hi All,
I am stuck at a place when the gethostname() function is failing even if I
have
loaded the library.
See the code below. The result ('counter')is always -1. Please help me...
Code:
-------------
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>
#define MAX_HOST_LEN 512
int main()
{
int counter=2;
char *hostname;
WORD wVersionRequested;
WSADATA wsaData;
wVersionRequested = MAKEWORD(1, 1);
if (WSAStartup(0x0101,&wsaData))
{
printf("\nWSAStartup() failed");
exit(1);
}
counter=gethostname(hostname, MAX_HOST_LEN);
printf("Details: %d",counter);
return 0;
}
______________________________________________________________________
You are receiving this email because you elected to monitor this forum.
To stop monitoring this forum, login to SourceForge.net and visit:
https://sourceforge.net/forum/unmonitor.php?forum_id=286529
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc. Get Certified Today
Register for a JBoss Training Course. Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
_______________________________________________
MinGW-users mailing list
MinGW-users@lists.sourceforge.net
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc. Get Certified Today
Register for a JBoss Training Course. Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
_______________________________________________
MinGW-users mailing list
MinGW-users@lists.sourceforge.net
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic