Hello,
I have one problem, and can think of two possible solutions but I
can't manage to make them work. I'm open to other suggestions if you
thik is better.
[Brief Situation] The main function calls sendSocket, but I don't know
how to tell it where to send the socket. ( I think I'm messing it up
with pointers)
struct hostent *hp;
sendSocket(){
hp= gethostbyname(P ROBLEM HERE);
}
main(){
sendSocket();
}
[Possible First Solution]
This would be probably the best approach to what I need. Ask the user
for the hostname
sendSocket(){
char hostname[256];
printf("Enter hostname: ");
fgets ( hostname, 256, stdin );
hp= gethostbyname(¿ WHAT SHOULD I PUT HERE?);
}
[Possible Second Solution]
A way to make argc and argv available outside the main function.
struct hostent *hp;
sendSocket(){
hp = gethostbyname(a rgv[1]);
}
main(int argc; char *argv[]){
sendSocket();
}
Any suggestion? Thanks 5 2744 ru****@gmail.co m wrote: Hello,
I have one problem, and can think of two possible solutions but I can't manage to make them work. I'm open to other suggestions if you thik is better.
[Brief Situation] The main function calls sendSocket, but I don't know how to tell it where to send the socket. ( I think I'm messing it up with pointers)
struct hostent *hp;
sendSocket(){ hp= gethostbyname(P ROBLEM HERE); }
main(){
int main(void) { sendSocket(); }
As such things are handled in a platform specific way (they are not part
of standard C) please ask in a forum specific to your platform.
[And, of course, you *should* have read the FAQ before posting.]
HTH,
--ag
--
Artie Gold -- Austin, Texas http://goldsays.blogspot.com (new post 8/5) http://www.cafepress.com/goldsays
"If you have nothing to hide, you're not trying!"
Hi,
Sorry. I found that the cause why the first solution didn't work was
the '\n' being introduced in the last position before '\0'.
Thank you Artie. I read the FAQ but didn't find anything about this,
sorry if this wasn't the appropriate group.
Bye
Artie Gold wrote: ru****@gmail.co m wrote: Hello,
I have one problem, and can think of two possible solutions but I can't manage to make them work. I'm open to other suggestions if you thik is better.
[Brief Situation] The main function calls sendSocket, but I don't know how to tell it where to send the socket. ( I think I'm messing it up with pointers)
[...] As such things are handled in a platform specific way (they are not part of standard C) please ask in a forum specific to your platform.
[And, of course, you *should* have read the FAQ before posting.]
While the example is using gethostbyname() , the real question being
asked is "how can I get a string from the user, and pass it to a
function", which would certainly not be off-topic. The fact that
the function is gethostbyname() and not print_foo(), is irrelevant
in this instance.
His followup post showed he found the correct answer -- that fgets()
leaves the newline intact, and he had to remove it before passing the
string to the function.
--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer .h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th***** ********@gmail. com>
Kenneth Brody wrote: Artie Gold wrote:
ru****@gmail. com wrote:
Hello,
I have one problem, and can think of two possible solutions but I can't manage to make them work. I'm open to other suggestions if you thik is better.
[Brief Situation] The main function calls sendSocket, but I don't know how to tell it where to send the socket. ( I think I'm messing it up with pointers)
[...]
As such things are handled in a platform specific way (they are not part of standard C) please ask in a forum specific to your platform.
[And, of course, you *should* have read the FAQ before posting.]
While the example is using gethostbyname() , the real question being asked is "how can I get a string from the user, and pass it to a function", which would certainly not be off-topic. The fact that the function is gethostbyname() and not print_foo(), is irrelevant in this instance.
His followup post showed he found the correct answer -- that fgets() leaves the newline intact, and he had to remove it before passing the string to the function.
Point taken.
However, even in a case like that, it behooves the OP to provide a
visible prototype for any non-standard function (yes I know what
gethostbyname() does -- but not when I'm wearing this hat ;-)).
Cheers,
--ag
--
Artie Gold -- Austin, Texas http://goldsays.blogspot.com (new post 8/5) http://www.cafepress.com/goldsays
"If you have nothing to hide, you're not trying!"
Artie Gold <ar*******@aust in.rr.com> wrote:
# However, even in a case like that, it behooves the OP to provide a
# visible prototype for any non-standard function (yes I know what
# gethostbyname() does -- but not when I'm wearing this hat ;-)).
When you find yourself in a hole, stop digging.
--
SM Ryan http://www.rawbw.com/~wyrmwif/
What kind of convenience store do you run here? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: yawnmoth |
last post by:
using the gethostbyname function seems to noticeably slow down pages.
some of the comments in php.net's gethostbyname entry suggest using a
version that caches the result, but those versions also only speedup
subsequent calls to gethostbyname - the first call is still as slow as
ever.
so is there anything i can do to speed this up? perhapes i can just
implement a function equivalent to gethostbyname using fsockopen, or
something?
|
by: Fortepianissimo |
last post by:
I've tried using
socket.setdefaulttimeout(timeout)
to set the default timeout to 'timeout' for all sockets. The part
that's not clear to me, is that if this will affect
socket.gethostbyname(). In my observation the timeout setting did not
affect the DNS lookup.
It might be my misunderstanding of the semantics here: would
|
by: Glen Conway |
last post by:
Hi,
I'm trying to use the gethostbyname function from wsock32.dll and failing dismally Has anyone got a successful implementation of this in VB.NET? My ulitimate goal is to resolve NetBIOS names to IP Addresses. I can use the framework DNS features if a DNS server is present on the network but this cannot use WINS if no DNS server is available.
Any help or pointers are apprecatiated. Here is the code I've managed to do so far. I've...
|
by: Quentin Carbonneaux |
last post by:
Hello,
I'm writing a little program which has to get a FQDN on his stdin and
return the IP on stdout, we can do it easily with gethostbyname call
but I would like to set up a timeout to this blocking system call. So
I read texts about this and I planed to use a hack with alarm and
setjmp/longjmp. My program works until there is a timeout, when it
occurs, all the gethostbyname calls which follow fail, backtrace in
gdb give me this :
#0 ...
|
by: KL |
last post by:
I have a problem trying to write to a binary file that I want to name
after a particular name from a set. My code for the function follows,
please excuse the horrible mistakes you may see, I am a student, and
trying my best.
void retrieveImage(set<string>finalset, string hostname, string filename){
set<string>::iterator i;
string img, filetoget;
char test;
for (i = finalset.begin();i != finalset.end();i++){
| |
by: Ryan Liu |
last post by:
Hi,
I have problem to connect to database server from a windows 98 machine.
I look at exception trace log, the problem seems not because of database
driver itself.
Seems the problem is because of System.Net.Dns.GetHostByName(String
hostName)
|
by: yawnmoth |
last post by:
I seem to be getting conflicting gethostbyname behavior on different
servers. Before going into detail, here's the script I'm using:
<?
$address = $HTTP_SERVER_VARS;
$rev = implode('.',array_reverse(explode('.', $address)));
$lookup = "$rev.l1.spews.dnsbl.sorbs.net";
echo gethostbyname($lookup);
echo '<br />';
|
by: Andrew DeFaria |
last post by:
I've been having problems with my ISP. One way it seems to manifest
itself is that I can not reach or contact my ISP's DNS servers. IOW a
simply nslookup google.com will fail.
So I tried writing a script that would monitor this. The script calls
gethostbyname for google.com every 15 minutes and logs the status. When
gethostbyname fails however it never comes back. My ISP and internet
connection may come back and nslookup at the command...
|
by: aj |
last post by:
I have the following snippet of code. On some platforms, the delete
calls works, on Linux, it core dumps (memory dump) at the delete
call. Am I responsible for deleting the memory that gethostbyname
allocated?
struct hostent *lHostInfo;
lHostInfo = gethostbyname(ipHost.c_str());
memcpy(&(lDestAddr.sin_addr), lHostInfo->h_addr_list, lHostInfo-
delete lHostInfo;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |