Is there a way I can test to make sure the socket I have currently is valid, and is there a better way than the below method for connecting via IP (more reliable?)
CODE
int wifiConnectIP(u32 ip, unsigned short port)
{
int sock = 0;
struct sockaddr_in tcp_sain;
sock = socket(AF_INET,SOCK_STREAM,0);
tcp_sain.sin_addr.s_addr = ip;
tcp_sain.sin_family = AF_INET;
tcp_sain.sin_port = htons(port);
connect(sock, (struct sockaddr *)&tcp_sain, sizeof(tcp_sain));
int i = 1;
ioctl(sock, FIONBIO, &i); // set non-blocking
return sock;
}
{
int sock = 0;
struct sockaddr_in tcp_sain;
sock = socket(AF_INET,SOCK_STREAM,0);
tcp_sain.sin_addr.s_addr = ip;
tcp_sain.sin_family = AF_INET;
tcp_sain.sin_port = htons(port);
connect(sock, (struct sockaddr *)&tcp_sain, sizeof(tcp_sain));
int i = 1;
ioctl(sock, FIONBIO, &i); // set non-blocking
return sock;
}
Also, as a side note, DNS on my DS seems very unreliable. The wifi lib test seems to do it fine, but in my code it locks up on the request 4 times out of 5, eventually going to black screens....