-
Notifications
You must be signed in to change notification settings - Fork 0
/
sockwrap.h
133 lines (75 loc) · 3.33 KB
/
sockwrap.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
module: sockwrap.h
purpose: definitions of functions in sockwrap.c
reference: Stevens, Unix network programming (3ed)
*/
#ifndef _SOCKWRAP_H
#define _SOCKWRAP_H
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <signal.h>
#define SA struct sockaddr
#define INTERRUPTED_BY_SIGNAL (errno == EINTR)
typedef void Sigfunc(int); /* for signal handlers */
int Socket (int family, int type, int protocol);
void Bind (int sockfd, const SA *myaddr, socklen_t myaddrlen);
void Listen (int sockfd, int backlog);
int Accept (int listen_sockfd, SA *cliaddr, socklen_t *addrlenp);
void Connect (int sockfd, const SA *srvaddr, socklen_t addrlen);
void Close (int fd);
void Shutdown (int fd, int howto);
ssize_t Read (int fd, void *bufptr, size_t nbytes);
void Write (int fd, void *bufptr, size_t nbytes);
ssize_t Recv (int fd, void *bufptr, size_t nbytes, int flags);
ssize_t Recvfrom (int fd, void *bufptr, size_t nbytes, int flags, SA *sa, socklen_t *salenptr);
ssize_t Recvfrom_timeout (int fd, void *bufptr, size_t nbytes, int flags, SA *sa, socklen_t *salenptr, int timeout);
void Sendto (int fd, void *bufptr, size_t nbytes, int flags, const SA *sa, socklen_t salen);
void Send (int fd, void *bufptr, size_t nbytes, int flags);
void Inet_aton (const char *strptr, struct in_addr *addrptr);
void Inet_pton (int af, const char *strptr, void *addrptr);
void Inet_ntop (int af, const void *addrptr, char *strptr, size_t length);
ssize_t readn (int fd, void *vptr, size_t n);
ssize_t Readn (int fd, void *ptr, size_t nbytes);
ssize_t readline_buffered (int fd, void *vptr, size_t maxlen);
ssize_t readline_unbuffered (int fd, void *vptr, size_t maxlen);
ssize_t Readline_buffered (int fd, void *ptr, size_t maxlen);
ssize_t Readline (int fd, void *ptr, size_t maxlen);
ssize_t writen(int fd, const void *vptr, size_t n);
void Writen (int fd, void *ptr, size_t nbytes);
ssize_t sendn (int fd, const void *vptr, size_t n, int flags);
void Sendn (int fd, void *ptr, size_t nbytes, int flags);
int Select (int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, struct timeval *timeout);
pid_t Fork (void);
struct hostent *Gethostbyname (const char *hostname);
void Getsockname (int sockfd, struct sockaddr *localaddr, socklen_t *addrp);
void Getaddrinfo ( const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res);
void
Getpeername(int fd, struct sockaddr *sa, socklen_t *salenptr);
void
Getsockopt(int fd, int level, int optname, void *optval, socklen_t *optlenptr);
void
Setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen);
char *
sock_ntop(const struct sockaddr *sa, socklen_t salen);
char *
Sock_ntop(const struct sockaddr *sa, socklen_t salen);
char *
sock_ntop_host(const struct sockaddr *sa, socklen_t salen);
char *
Sock_ntop_host(const struct sockaddr *sa, socklen_t salen);
void
Fclose(FILE *fp);
char *
Fgets(char *ptr, int n, FILE *stream);
FILE *
Fopen(const char *filename, const char *mode);
void
Fputs(const char *ptr, FILE *stream);
Sigfunc *
signal(int signo, Sigfunc *func);
Sigfunc *
Signal(int signo, Sigfunc *func);
void Print_getaddrinfo_list(struct addrinfo *list_head);
#endif