File: socketlib.h

package info (click to toggle)
wput 0.6.2%2Bgit20130413-14
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 2,688 kB
  • sloc: ansic: 6,854; sh: 3,460; makefile: 72; sed: 16
file content (69 lines) | stat: -rw-r--r-- 1,920 bytes parent folder | download | duplicates (8)
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
#ifndef __SOCKET_H
#define __SOCKET_H

#include "config.h"

#ifdef HAVE_SSL
# ifndef WIN32
#  include <gnutls/openssl.h>
# endif
#endif

#ifndef WIN32

#include <sys/types.h>
#include <sys/socket.h>

#define closesocket(x) close(x)
#define WPUT_EINTR EINTR
#else
#include "windows.h"
#endif

#define PROXY_OFF   0
#define PROXY_SOCKS 1
#define PROXY_HTTP  2

typedef struct _proxy_settings {
	unsigned int   ip;
	unsigned short port;
	char *         user;
	char *         pass;
	unsigned int   bind:1;
	unsigned int   type:2;
} proxy_settings;

typedef struct _wput_socket {
	int fd;
#ifdef HAVE_SSL
	SSL     * ssl;
	SSL_CTX * ctx;
#endif
} wput_socket;

wput_socket * socket_new();
void          socket_set_default_timeout(int timeout);
wput_socket * socket_connect(const unsigned int ip, const unsigned short port);
wput_socket * socket_listen(unsigned bindaddr, unsigned short * s_port);
wput_socket * socket_accept(wput_socket * sock);
void          socket_close(wput_socket * sock);
#ifdef HAVE_SSL
int           socket_transform_to_ssl(wput_socket * sock);
#endif

char * socket_read_line(wput_socket * sock);
int    socket_read (wput_socket * sock, void *buf, size_t len);
int    socket_write(wput_socket * sock, void *buf, size_t len);

int get_ip_addr(char* hostname, unsigned int * ip);
int get_local_ip(int sockfd, char * local_ip);

int socket_set_blocking(int sock, unsigned char block);
int socket_is_data_writeable(int s, int timeout);
int socket_is_data_readable(int s, int timeout);
wput_socket * socket_timeout_connect(wput_socket * sock, struct sockaddr *remote_addr, size_t size, int timeout);
wput_socket * proxy_init(proxy_settings * ps);
wput_socket * proxy_listen(proxy_settings * ps, unsigned int * ip, unsigned short * port);
wput_socket * proxy_accept(wput_socket * server);
wput_socket * proxy_connect(proxy_settings * ps, unsigned int ip, unsigned short port, const char * hostname);
#endif