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!!!
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!!!