Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

jbsockets.c File Reference

Contains wrappers for system-specific sockets code, so that the rest of Junkbuster can be more OS-independent. More...


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 len)
int read_socket (jb_socket fd, char *buf, int len)
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 [] = "$Id: jbsockets.c,v 2.0 2002/06/04 14:34:21 jongfoster Exp $"
const char jbsockets_h_rcs [] = JBSOCKETS_H_VERSION


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.c,v
Revision 2.0 2002/06/04 14:34:21 jongfoster Moving source files to src/

Revision 1.36 2002/05/26 23:23:10 joergs AmigaOS: Fixed wrong type for len in write_socket()

Revision 1.35 2002/04/26 15:50:04 joergs AmigaOS: No socklen_t, added AMIGA to the systems using int instead.

Revision 1.34 2002/04/08 20:31:41 swa fixed JB spelling

Revision 1.33 2002/04/03 16:02:18 gliptak Correcting compile warning with older gcc

Revision 1.32 2002/03/31 17:18:59 jongfoster Win32 only: Enabling STRICT to fix a VC++ compile warning.

Revision 1.31 2002/03/29 03:33:13 david__schmidt Fix Mac OSX compiler warnings

Revision 1.30 2002/03/27 14:32:43 david__schmidt More compiler warning message maintenance

Revision 1.29 2002/03/26 22:29:54 swa we have a new homepage!

Revision 1.28 2002/03/24 13:25:43 swa name change related issues

Revision 1.27 2002/03/13 00:27:05 jongfoster Killing warnings

Revision 1.26 2002/03/11 22:07:02 david__schmidt OS/2 port maintenance:

Revision 1.25 2002/03/09 20:03:52 jongfoster 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...)

Revision 1.24 2002/03/07 03:51:36 oes Revision 1.23 2002/03/05 00:36:01 jongfoster Fixing bug 514988 - unable to restart Junkbuster

Revision 1.22 2002/03/04 02:08:02 david__schmidt Enable web editing of actions file on OS/2 (it had been broken all this time!)

Revision 1.21 2002/01/09 14:32:33 oes Added support for gethostbyname_r and gethostbyaddr_r.

Revision 1.20 2001/11/16 00:48:48 jongfoster Enabling duplicate-socket detection for all platforms, not just Win32.

Revision 1.19 2001/10/25 03:40:47 david__schmidt Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple threads to call select() simultaneously. So, it's time to do a real, live, native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__ (native). Both versions will work, but using __OS2__ offers multi-threading.

Revision 1.18 2001/09/21 23:02:02 david__schmidt Cleaning up 2 compiler warnings on OS/2.

Revision 1.17 2001/09/13 20:11:46 jongfoster Fixing 2 compiler warnings under Win32

Revision 1.16 2001/07/30 22:08:36 jongfoster Tidying up defines:

Revision 1.15 2001/07/29 17:40:43 jongfoster Fixed compiler warning by adding a cast

Revision 1.14 2001/07/18 13:47:59 oes Eliminated dirty hack for getsockbyname()

Revision 1.13 2001/07/15 13:56:57 jongfoster Removing unused local variable.

Revision 1.12 2001/07/01 17:04:11 oes Bugfix: accept_connection no longer uses the obsolete hstrerror() function

Revision 1.11 2001/06/29 21:45:41 oes Indentation, CRLF->LF, Tab-> Space

Revision 1.10 2001/06/29 13:29:15 oes

Revision 1.9 2001/06/07 23:06:09 jongfoster The host parameter to connect_to() is now const.

Revision 1.8 2001/06/03 19:12:07 oes filled comment

Revision 1.7 2001/05/28 16:14:00 jongfoster Fixing bug in LOG_LEVEL_LOG

Revision 1.6 2001/05/26 17:28:32 jongfoster Fixed LOG_LEVEL_LOG

Revision 1.5 2001/05/26 15:26:15 jongfoster ACL feature now provides more security by immediately dropping connections from untrusted hosts.

Revision 1.4 2001/05/26 00:37:42 jongfoster Cosmetic indentation correction.

Revision 1.3 2001/05/25 21:57:54 jongfoster Now gives a warning under Windows if you try to bind it to a port that's already in use.

Revision 1.2 2001/05/17 23:01:01 oes

Revision 1.1.1.1 2001/05/15 13:58:54 oes Initial import of version 2.9.3 source tree


Function Documentation

int accept_connection struct client_state   csp,
jb_socket    fd
 

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

void close_socket jb_socket    fd
 

Closes a TCP/IP socket.

Parameters:
fd  file descriptor of socket to be closed
Returns:
void

jb_socket connect_to const char *    host,
int    portnum,
struct client_state   csp
 

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:
host  hostname to resolve
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[] = JBSOCKETS_H_VERSION
 

Version information about jbsockets.h.

const char jbsockets_rcs[] = "$Id: jbsockets.c,v 2.0 2002/06/04 14:34:21 jongfoster Exp $"
 

Version information about jbsockets.c.


Generated on Tue Jun 4 18:54:49 2002 for Privoxy 3.1.1 by doxygen1.2.15