Hi,everyone,
How to test that the IP port is reachable?
In C,you can do this like that, what should I do in D?
/* C Code*/
https://blog.csdn.net/zhangyingchuang/article/details/51957552
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h> /* inet(3) functions */
#define bool int
#define false 0
#define true 1
bool checkIPandPort(const char* ip, const char* port) {
struct sockaddr_in addr;
int fd = socket(AF_INET, SOCK_STREAM, 0);
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(atoi(port));
addr.sin_addr.s_addr = inet_addr(ip);
if (connect(fd, (struct sockaddr *) &addr, sizeof(struct
sockaddr)) < 0) {
printf("connect error \n");
return false;
}
return true;
}
----------------------------------------------------------
But how to do it in D?
Thanks.