Main Page Alphabetical List Data Structures File List Data Fields Globals
jbsockets.h File Reference
Contains wrappers for system-specific sockets code, so that the rest of Junkbuster can be more OS-independent.
More...
Go to the source code of this file.
Defines |
|
#define | JBSOCKETS_H_VERSION "$Id: jbsockets.h,v 2.0 2002/06/04 14:34:21 jongfoster Exp $" |
Functions |
| jb_socket | connect_to (const char *host, int portnum, struct client_state *csp) |
| int | write_socket (jb_socket fd, const char *buf, size_t n) |
| int | read_socket (jb_socket fd, char *buf, int n) |
| void | close_socket (jb_socket fd) |
| int | bind_port (const char *hostnam, int portnum, jb_socket *pfd) |
| int | accept_connection (struct client_state *csp, jb_socket fd) |
| unsigned long | resolve_hostname_to_ip (const char *host) |
Variables |
| const char | jbsockets_rcs [] |
| const char | jbsockets_h_rcs [] |
Detailed Description
Contains wrappers for system-specific sockets code, so that the rest of Junkbuster can be more OS-independent.
Contains ifdefs to make this work on many platforms.
-
Log:
-
jbsockets.h,v
Revision 2.0 2002/06/04 14:34:21 jongfoster Moving source files to src/
Revision 1.10 2002/05/26 23:23:10 joergs AmigaOS: Fixed wrong type for len in write_socket()
Revision 1.9 2002/04/08 20:31:41 swa fixed JB spelling
Revision 1.8 2002/03/26 22:29:54 swa we have a new homepage!
Revision 1.7 2002/03/24 13:25:43 swa name change related issues
Revision 1.6 2002/03/13 00:27:05 jongfoster Killing warnings
Revision 1.5 2002/03/09 20:03:52 jongfoster
- Making various functions return int rather than size_t. (Undoing a recent change). Since size_t is unsigned on Windows, functions like read_socket that return -1 on error cannot return a size_t.
THIS WAS A MAJOR BUG - it caused frequent, unpredictable crashes, and also frequently caused JB to jump to 100% CPU and stay there. (Because it thought it had just read ((unsigned)-1) == 4Gb of data...)
- The signature of write_socket has changed, it now simply returns success=0/failure=nonzero.
- Trying to get rid of a few warnings --with-debug on Windows, I've introduced a new type "jb_socket". This is used for the socket file descriptors. On Windows, this is SOCKET (a typedef for unsigned). Everywhere else, it's an int. The error value can't be -1 any more, so it's now JB_INVALID_SOCKET (which is -1 on UNIX, and in Windows it maps to the define INVALID_SOCKET.)
- The signature of bind_port has changed.
Revision 1.4 2002/03/07 03:51:36 oes
- Improved handling of failed DNS lookups
- Fixed compiler warnings etc
Revision 1.3 2001/07/29 19:01:11 jongfoster Changed _FILENAME_H to FILENAME_H_INCLUDED. Added forward declarations for needed structures.
Revision 1.2 2001/06/07 23:06:09 jongfoster The host parameter to connect_to() is now const.
Revision 1.1.1.1 2001/05/15 13:58:54 oes Initial import of version 2.9.3 source tree
Function Documentation
|
|
Accepts a connection on a socket.
Socket must have been created using bind_port(). -
Parameters:
-
| csp |
Client state, cfd, ip_addr_str, and ip_addr_long will be set by this routine. |
| fd |
file descriptor returned from bind_port |
-
Returns:
-
when a connection is accepted, it returns 1 (TRUE). On an error it returns 0 (FALSE).
|
| int bind_port |
( |
const char * |
hostnam, |
|
|
int |
portnum, |
|
|
jb_socket * |
pfd |
|
) |
|
|
|
|
Call socket, set socket options, and listen.
Called by listen_loop to "boot up" our proxy address. -
Parameters:
-
| hostnam |
TCP/IP address to bind/listen to |
| portnum |
port to listen on |
| pfd |
pointer used to return file descriptor. |
-
Returns:
-
if success, returns 0 and sets *pfd. if failure, returns -3 if address is in use, -2 if address unresolvable, -1 otherwise
|
|
|
Closes a TCP/IP socket.
-
Parameters:
-
| fd |
file descriptor of socket to be closed |
-
Returns:
-
void
|
|
|
Open a socket and connect to it.
Will check that this is allowed according to ACL. -
Parameters:
-
| host |
hostname to connect to |
| portnum |
port to connent on |
| csp |
Current client state (buffers, headers, etc...) Not modified, only used for source IP and ACL. |
-
Returns:
-
JB_INVALID_SOCKET => failure, else it is the socket file descriptor.
|
| int read_socket |
( |
jb_socket |
fd, |
|
|
char * |
buf, |
|
|
int |
len |
|
) |
|
|
|
|
Read from a TCP/IP socket in a platform independent way.
-
Parameters:
-
| fd |
file descriptor of the socket to read |
| buf |
pointer to buffer where data will be written Must be >= len bytes long. |
| len |
maximum number of bytes to read |
-
Returns:
-
On success, the number of bytes read is returned (zero indicates end of file), and the file position is advanced by this number. It is not an error if this number is smaller than the number of bytes requested; this may hap- pen for example because fewer bytes are actually available right now (maybe because we were close to end-of-file, or because we are reading from a pipe, or from a terminal, or because read() was interrupted by a signal). On error, -1 is returned, and errno is set appropriately. In this case it is left unspecified whether the file position (if any) changes.
|
| unsigned long resolve_hostname_to_ip |
( |
const char * |
host |
) |
|
|
|
|
Resolve a hostname to an internet tcp/ip address.
NULL or an empty string resolve to INADDR_ANY. -
Parameters:
-
-
Returns:
-
INADDR_NONE => failure, INADDR_ANY or tcp/ip address if succesful.
|
| int write_socket |
( |
jb_socket |
fd, |
|
|
const char * |
buf, |
|
|
size_t |
len |
|
) |
|
|
|
|
Write the contents of buf (for n bytes) to socket fd.
-
Parameters:
-
| fd |
file descriptor (aka. handle) of socket to write to. |
| buf |
pointer to data to be written. |
| len |
length of data to be written to the socket "fd". |
-
Returns:
-
0 on success (entire buffer sent). nonzero on error.
|
Variable Documentation
| const char jbsockets_h_rcs[]
|
|
| const char jbsockets_rcs[]
|
|
Generated on Tue Jun 4 18:54:49 2002 for Privoxy 3.1.1 by
1.2.15