-
Notifications
You must be signed in to change notification settings - Fork 10
/
netutil.h
38 lines (30 loc) · 863 Bytes
/
netutil.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma once
#ifndef NETUTIL_H
#define NETUTIL_H
#include <stdint.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <vector>
#include <string>
class NetUtil
{
public:
// if success, return nonblock socket fd
static int Listen(const char * serverIp, uint16_t port);
// if success, return block socket fd
static int Connect(const char * serverIp, uint16_t port);
static void SetReuseAddr(int fd, int optval = 1);
static void SetNonblock(int fd);
static void SetNoDelay(int fd, int optval = 1);
static void SetAddr(const char * serverIp, uint16_t port, sockaddr_in & sockAddr);
static void GetIpByDomain(const char * domain, std::vector<std::string> & vecIp);
};
#endif