How to make the program connect to next IP address without exiting program, if the current connectio

A

Abby

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);
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!!!
 
J

Jack Klein

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,010
Latest member
MerrillEic

Latest Threads

Top