1 #include <errno.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <sys/types.h> 5 #include <sys/socket.h> 6 #include <netinet/in.h> 7 #include <arpa/inet.h> 8 #include <iostream> 9 #include <sys/epoll.h> 10 11 using namespace std; 12 13 int main(int argc, char *argv[]) 14 { 15 if (argc != 3) 16 { 17 cout << "usage: " << argv[0] << " ip port" << endl; 18 return -1; 19 } 20 21 char *szIp = argv[1]; 22 in_addr_t iIp = inet_addr(szIp); 23 if (iIp == INADDR_NONE) 24 { 25 cerr << "fail to parse ip: " << szIp << endl; 26 return -1; 27 } 28 char *pEnd = NULL; 29 uint16_t usPort = strtoul(argv[2], &pEnd, 10); 30 if (*pEnd != '