-
Notifications
You must be signed in to change notification settings - Fork 0
/
unp.h
79 lines (64 loc) · 2.34 KB
/
unp.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef __UNP_H__
#define __UNP_H__
#include <stdio.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <strings.h>
#include <string.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <sys/signal.h>
#include <signal.h>
#include <time.h>
#include <limits.h>
#include <poll.h>
#include <sys/un.h>
#include <netdb.h>
#define MAXLINE 4096
#define LISTENQ 1024
#define SERV_PORT 9877
#ifndef INFTIM
#define INFTIM -1
#endif
#ifndef OPEN_MAX
#define OPEN_MAX 1024
#endif
typedef struct sockaddr SA;
pid_t Fork(void);
int Socket(int family, int type, int protocol);
void Listen(int fd, int backlog);
void Bind(int fd, const struct sockaddr *addr, socklen_t addrlen);
int Accept(int fd, struct sockaddr *addr, socklen_t *addrlen);
void Connect(int fd, const struct sockaddr *addr, socklen_t addrlen);
ssize_t readn(int fd, void *buff, size_t nbytes);
ssize_t written(int fd, const void *buff, size_t nbytes);
char* Fgets(char *ptr, int n, FILE *stream);
ssize_t readline(int fd, void *buff, size_t maxlen);
ssize_t Readline(int fd, void *buff, size_t maxlen);
ssize_t Recvfrom(int fd, void *buff, size_t nbytes, int flags,
struct sockaddr *sa, socklen_t *salenptr);
void Sendto(int fd, const void *ptr, size_t nbytes, int flags,
const struct sockaddr *sa, socklen_t salen);
void Write(int fd, const void *ptr, size_t nbytes);
ssize_t Read(int fd, void *ptr, size_t nbytes);
void Inet_pton(int family, const char *src, void *dst);
const char* Inet_ntop(int family, const void *addrptr, char *strptr, size_t len);
char * sock_ntop(const struct sockaddr *sa, socklen_t salen);
char * Sock_ntop(const struct sockaddr *sa, socklen_t salen);
void Getsockname(int fd, struct sockaddr *sa, socklen_t *salenptr);
void Setsockopt(int fd, int level, int optname, const void*optval, socklen_t optlen);
typedef void Sigfunc(int);
Sigfunc* Signal(int signo, Sigfunc *func);
int Select(int maxfdp1, fd_set *rset, fd_set *wset, fd_set *eset,
struct timeval *timeout);
const char* getcurtime();
void str_echo(int sockfd);
void str_cli(FILE *fp, int sockfd);
void dg_echo(int sockfd, SA *pcliaddr, socklen_t clilen);
void dg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen);
int connect_timeo(int sockfd, const SA *addr, socklen_t len, int nsec);
#endif