By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,947 Members | 1,594 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,947 IT Pros & Developers. It's quick & easy.

How to make the program connect to next IP address without exiting program, if the current connection fail??

P: n/a
I'm writing a code to send/receive udp packet. I'll receive ip address
from user (this is the starting ip), then I'll ask user how many ip he
wants to connect to. For examples:

Please enter 1st ip: 192.168.0.1
How many ip do you want to connect to: 10

Then, my program will create an array to store 10 ip addresses,
starting from
192.168.0.1
....
....
192.168.0.10

Then, I'll use each ip to open socket, send udp packet to each ip in
order. Below is the general idea of what my program does to send and
receive packet.

struct resp_pkt * pkt;
char ip[node][16]; // ip array used to store multiple ip address

for (i=0;i<node;i++){
sockfd = open_socket(ip[i]);
pkt = action(sockfd, udp_pkt);
if(!pkt) {
printf("Connection fail\n");
close(sockfd);
}
close(sockfd);
}

*** My problem is that if it fail to receive udp packet from any ip
address, the program will exit, and will not go on to the next ip. How
can I force it to just send out message and go on to the next ip?? ***

Right now, when it can't connect to the next ip, it will show error
message "Connection fail", then exit the program. Anybody has an idea
how to achieve this? Thank you so much!!!
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 28 Aug 2003 16:53:17 -0700, ab*****@yahoo.com (Abby) wrote in
comp.lang.c:
I'm writing a code to send/receive udp packet. I'll receive ip address
from user (this is the starting ip), then I'll ask user how many ip he
wants to connect to. For examples:


[snip]

You need to ask this in a support newsgroup for your particular
compiler/operating system combination to see what sort of networking
features it provides. C has no built-in support for any sort of
networking at all, so it's off-topic here.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.