/* tcping does a nonblocking connect to test if a port is reachable.
* Its exit codes are:* -1 an error occured
* 0 port is open
* 1 port is closed
* 2 user timeout
*/
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <fcntl.h>
#include <arpa/inet.h>
#define SRV_IP "8.8.8.8"
#define SRV_PORT 53
int main (int argc, char *argv[]) {
int sockfd;
struct sockaddr_in addr;
int error = 0;
int errlen;
int ret;
struct timeval timeout;
fd_set fdrset, fdwset;
timeout.tv_sec=10;
timeout.tv_usec=0;
if((sockfd = socket (AF_INET, SOCK_STREAM, 0)) < 0){
prin