Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions
macsocket.h File Reference
#include <Files.h>
#include <OpenTptInternet.h>
#include <utime.h>
#include "prio.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


struct  sockaddr
struct  in_addr
struct  sockaddr_in
struct  hostent
struct  fd_set
struct  protoent
struct  linger
struct  ip_mreq


#define h_addr   h_addr_list[0] /* address, for backward compatiblity */
#define FIONBIO   1
#define SOCK_STREAM   1
#define SOCK_DGRAM   2
#define INADDR_ANY   kOTAnyInetAddress
#define MSG_PEEK   0x2
#define NBBY   8
#define NFDBITS   (sizeof(fd_mask) * NBBY) /* bits per mask */
#define howmany(x, y)   (((x)+((y)-1))/(y))
#define FD_SETSIZE   64
#define FD_SET(n, p)   ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
#define FD_CLR(n, p)   ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
#define FD_ISSET(n, p)   ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
#define FD_ZERO(p)   memset (p, 0, sizeof(*(p)))
#define macsock_gethostbyaddr   PR_GetHostByAddr
#define macsock_socket   PR_Socket
#define macsock_connect   PR_Connect
#define macsock_write   PR_Write
#define macsock_read   PR_Read
#define macsock_close   PR_Close
#define macsock_accept   PR_Accept
#define macsock_bind   PR_Bind
#define macsock_listen   PR_Listen
#define macsock_shutdown   PR_Shutdown
#define macsock_getpeername   PR_GetPeerName
#define macsock_getsockname   PR_GetSockName
#define macsock_socketavailable   PR_SocketAvailable
#define macsock_send   PR_Send
#define macsock_sendto   PR_SendTo
#define macsock_recvfrom   PR_RecvFrom
#define macsock_recv   PR_Recv
#define INADDR_LOOPBACK   0x7F000001
#define SO_LINGER   XTI_LINGER /* linger on close if data present */


typedef unsigned long u_long
typedef long fd_mask
typedef struct fd_set fd_set


unsigned long inet_addr (const char *cp)
char * inet_ntoa (struct in_addr in)
unsigned long htonl (unsigned long hostlong)
unsigned long ntohl (unsigned long netlong)
unsigned short ntohs (unsigned short netshort)
unsigned short htons (unsigned short hostshort)
struct hostentmacsock_gethostbyaddr (const void *addr, int addrlen, int type)
int macsock_socket (int domain, int type, int protocol)
int macsock_ioctl (int sID, unsigned int request, void *value)
int macsock_connect (int sID, struct sockaddr *name, int namelen)
int macsock_write (int sID, const void *buffer, unsigned buflen)
int macsock_read (int sID, void *buf, unsigned nbyte)
int macsock_close (int sID)
int macsock_accept (int sID, struct sockaddr *addr, int *addrlen)
int macsock_bind (int sID, const struct sockaddr *name, int namelen)
int macsock_listen (int sID, int backlog)
int macsock_shutdown (int sID, int how)
int macsock_getpeername (int sID, struct sockaddr *name, int *namelen)
int macsock_getsockname (int sID, struct sockaddr *name, int *namelen)
int macsock_getsockopt (int sID, int level, int optname, void *optval, int *optlen)
int macsock_setsockopt (int sID, int level, int optname, const void *optval, int optlen)
int macsock_socketavailable (int sID, size_t *bytesAvailable)
int macsock_dup (int sID)
int macsock_send (int sID, const void *msg, int len, int flags)
int macsock_sendto (int sID, const void *msg, int len, int flags, struct sockaddr *toAddr, int toLen)
int macsock_recvfrom (int sID, void *buf, int len, int flags, struct sockaddr *from, int *fromLen)
int macsock_recv (int sID, void *buf, int len, int flags)
int select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
struct protoentgetprotobyname (const char *name)
struct protoentgetprotobynumber (int number)
int gethostname (char *name, int namelen)
struct hostentgethostbyname (const char *name)
struct hostentgethostbyaddr (const void *addr, int addrlen, int type)

Class Documentation

struct sockaddr

Definition at line 66 of file macsocket.h.

Class Members
char sa_data
unsigned char sa_family
sa_family_t sa_family
unsigned char sa_len
struct in_addr

Definition at line 73 of file macsocket.h.

Class Members
unsigned long s_addr
in_addr_t s_addr
struct sockaddr_in

Definition at line 77 of file macsocket.h.

Class Members
unsigned char sin_family
sa_family_t sin_family
unsigned char sin_len
unsigned short sin_port
in_port_t sin_port
char sin_zero
unsigned char sin_zero
struct hostent

Definition at line 85 of file macsocket.h.

Collaboration diagram for hostent:
Class Members
char ** h_addr_list
int h_addrtype
char ** h_aliases
int h_length
char * h_name
struct fd_set

Definition at line 119 of file macsocket.h.

Class Members
fd_mask fds_bits
struct protoent

Definition at line 203 of file _beos.h.

Collaboration diagram for protoent:
Class Members
char ** p_aliases
char * p_name
int p_proto
struct linger

Definition at line 228 of file macsocket.h.

Collaboration diagram for linger:
Class Members
int l_linger
int l_onoff
struct ip_mreq

Definition at line 233 of file macsocket.h.

Define Documentation

#define FD_CLR (   n,
)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))

Definition at line 124 of file macsocket.h.

#define FD_ISSET (   n,
)    ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))

Definition at line 125 of file macsocket.h.

#define FD_SET (   n,
)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))

Definition at line 123 of file macsocket.h.

#define FD_SETSIZE   64

Definition at line 118 of file macsocket.h.

#define FD_ZERO (   p)    memset (p, 0, sizeof(*(p)))

Definition at line 126 of file macsocket.h.

#define FIONBIO   1

Definition at line 95 of file macsocket.h.

#define h_addr   h_addr_list[0] /* address, for backward compatiblity */

Definition at line 91 of file macsocket.h.

#define howmany (   x,
)    (((x)+((y)-1))/(y))

Definition at line 116 of file macsocket.h.

#define INADDR_ANY   kOTAnyInetAddress

Definition at line 100 of file macsocket.h.

#define INADDR_LOOPBACK   0x7F000001

Definition at line 218 of file macsocket.h.


Definition at line 225 of file macsocket.h.


Definition at line 98 of file macsocket.h.


Definition at line 99 of file macsocket.h.

#define macsock_accept   PR_Accept

Definition at line 181 of file macsocket.h.

#define macsock_bind   PR_Bind

Definition at line 182 of file macsocket.h.

Definition at line 180 of file macsocket.h.

#define macsock_connect   PR_Connect

Definition at line 177 of file macsocket.h.

#define macsock_gethostbyaddr   PR_GetHostByAddr

Definition at line 175 of file macsocket.h.

#define macsock_getpeername   PR_GetPeerName

Definition at line 185 of file macsocket.h.

#define macsock_getsockname   PR_GetSockName

Definition at line 186 of file macsocket.h.

#define macsock_listen   PR_Listen

Definition at line 183 of file macsocket.h.

Definition at line 179 of file macsocket.h.

#define macsock_recv   PR_Recv

Definition at line 191 of file macsocket.h.

#define macsock_recvfrom   PR_RecvFrom

Definition at line 190 of file macsocket.h.

#define macsock_send   PR_Send

Definition at line 188 of file macsocket.h.

#define macsock_sendto   PR_SendTo

Definition at line 189 of file macsocket.h.

#define macsock_shutdown   PR_Shutdown

Definition at line 184 of file macsocket.h.

#define macsock_socket   PR_Socket

Definition at line 176 of file macsocket.h.

#define macsock_socketavailable   PR_SocketAvailable

Definition at line 187 of file macsocket.h.

Definition at line 178 of file macsocket.h.

#define MSG_PEEK   0x2

Definition at line 104 of file macsocket.h.

#define NBBY   8

Definition at line 111 of file macsocket.h.

#define NFDBITS   (sizeof(fd_mask) * NBBY) /* bits per mask */

Definition at line 113 of file macsocket.h.

Definition at line 103 of file macsocket.h.

Definition at line 220 of file macsocket.h.

#define SO_LINGER   XTI_LINGER /* linger on close if data present */

Definition at line 223 of file macsocket.h.


Definition at line 221 of file macsocket.h.

Definition at line 102 of file macsocket.h.


Definition at line 222 of file macsocket.h.

#define SOCK_DGRAM   2

Definition at line 97 of file macsocket.h.

Definition at line 96 of file macsocket.h.


Definition at line 101 of file macsocket.h.

Typedef Documentation

typedef long fd_mask

Definition at line 112 of file macsocket.h.

typedef struct fd_set fd_set
typedef unsigned long u_long

Definition at line 106 of file macsocket.h.

Function Documentation

struct hostent* gethostbyaddr ( const void addr,
int  addrlen,
int  type 
) [read]
struct hostent* gethostbyname ( const char *  name) [read]
int gethostname ( char *  name,
int  namelen 
struct protoent* getprotobyname ( const char *  name) [read]

Definition at line 46 of file btmisc.c.

    return 0;
struct protoent* getprotobynumber ( int  number) [read]

Definition at line 51 of file btmisc.c.

    return 0;
unsigned long htonl ( unsigned long  hostlong) [inline]

Definition at line 137 of file macsocket.h.

{return hostlong;}
unsigned short htons ( unsigned short  hostshort) [inline]

Definition at line 140 of file macsocket.h.

{return hostshort;}
unsigned long inet_addr ( const char *  cp)
char* inet_ntoa ( struct in_addr  in)

Definition at line 707 of file mozock.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int macsock_accept ( int  sID,
struct sockaddr addr,
int addrlen 
int macsock_bind ( int  sID,
const struct sockaddr name,
int  namelen 
int macsock_close ( int  sID)
int macsock_connect ( int  sID,
struct sockaddr name,
int  namelen 
int macsock_dup ( int  sID)
struct hostent* macsock_gethostbyaddr ( const void addr,
int  addrlen,
int  type 
) [read]
int macsock_getpeername ( int  sID,
struct sockaddr name,
int namelen 
int macsock_getsockname ( int  sID,
struct sockaddr name,
int namelen 
int macsock_getsockopt ( int  sID,
int  level,
int  optname,
void optval,
int optlen 
int macsock_ioctl ( int  sID,
unsigned int  request,
void value 
int macsock_listen ( int  sID,
int  backlog 
int macsock_read ( int  sID,
void buf,
unsigned  nbyte 
int macsock_recv ( int  sID,
void buf,
int  len,
int  flags 
int macsock_recvfrom ( int  sID,
void buf,
int  len,
int  flags,
struct sockaddr from,
int fromLen 
int macsock_send ( int  sID,
const void msg,
int  len,
int  flags 
int macsock_sendto ( int  sID,
const void msg,
int  len,
int  flags,
struct sockaddr toAddr,
int  toLen 
int macsock_setsockopt ( int  sID,
int  level,
int  optname,
const void optval,
int  optlen 
int macsock_shutdown ( int  sID,
int  how 
int macsock_socket ( int  domain,
int  type,
int  protocol 
int macsock_socketavailable ( int  sID,
size_t *  bytesAvailable 
int macsock_write ( int  sID,
const void buffer,
unsigned  buflen 
unsigned long ntohl ( unsigned long  netlong) [inline]

Definition at line 138 of file macsocket.h.

{return netlong;}
unsigned short ntohs ( unsigned short  netshort) [inline]

Definition at line 139 of file macsocket.h.

{return netshort;}
int select ( int  nfds,
fd_set readfds,
fd_set writefds,
fd_set exceptfds,
struct timeval timeout 

Definition at line 115 of file uxwrap.c.

    int osfd;
    _PRUnixPollDesc *unixpds, *unixpd, *eunixpd;
    PRInt32 pdcnt;
    PRIntervalTime timeout;
    int retVal;
#if defined(HPUX9) || defined(AIX_RENAME_SELECT)
    fd_set *rd = (fd_set*) rl;
    fd_set *wr = (fd_set*) wl;
    fd_set *ex = (fd_set*) el;

#if 0
     * Easy special case: zero timeout.  Simply call the native
     * select() with no fear of blocking.
    if (tv != NULL && tv->tv_sec == 0 && tv->tv_usec == 0) {
#if defined(HPUX9) || defined(AIX_RENAME_SELECT)
        return _MD_SELECT(width, rl, wl, el, tv);
        return _MD_SELECT(width, rd, wr, ex, tv);

    if (!_pr_initialized) {
        return _MD_SELECT(width, rd, wr, ex, tv);       

    if (width < 0 || width > FD_SETSIZE) {
        errno = EINVAL;
        return -1;

    /* Compute timeout */
    if (tv) {
         * These acceptable ranges for t_sec and t_usec are taken
         * from the select() man pages.
        if (tv->tv_sec < 0 || tv->tv_sec > 100000000
                || tv->tv_usec < 0 || tv->tv_usec >= 1000000) {
            errno = EINVAL;
            return -1;

        /* Convert microseconds to ticks */
        timeout = PR_MicrosecondsToInterval(1000000*tv->tv_sec + tv->tv_usec);
    } else {
        /* tv being a NULL pointer means blocking indefinitely */
        timeout = PR_INTERVAL_NO_TIMEOUT;

    /* Check for no descriptors case (just doing a timeout) */
    if ((!rd && !wr && !ex) || !width) {
        return 0;

     * Set up for PR_Poll().  The PRPollDesc array is allocated
     * dynamically.  If this turns out to have high performance
     * penalty, one can change to use a large PRPollDesc array
     * on the stack, and allocate dynamically only when it turns
     * out to be not large enough.
     * I allocate an array of size 'width', which is the maximum
     * number of fds we may need to poll.
    unixpds = (_PRUnixPollDesc *) PR_CALLOC(width * sizeof(_PRUnixPollDesc));
    if (!unixpds) {
        errno = ENOMEM;
        return -1;

    pdcnt = 0;
    unixpd = unixpds;
    for (osfd = 0; osfd < width; osfd++) {
        int in_flags = 0;
        if (rd && FD_ISSET(osfd, rd)) {
            in_flags |= _PR_UNIX_POLL_READ;
        if (wr && FD_ISSET(osfd, wr)) {
            in_flags |= _PR_UNIX_POLL_WRITE;
        if (ex && FD_ISSET(osfd, ex)) {
            in_flags |= _PR_UNIX_POLL_EXCEPT;
        if (in_flags) {
            unixpd->osfd = osfd;
            unixpd->in_flags = in_flags;
            unixpd->out_flags = 0;

     * see comments in mozilla/cmd/xfe/mozilla.c (look for
     * "PR_XGetXtHackFD")
     int needToLockXAgain;
     needToLockXAgain = 0;
     if (rd && (_pr_xt_hack_fd != -1)
             && FD_ISSET(_pr_xt_hack_fd, rd) && PR_XIsLocked()
             && (!_pr_xt_hack_okayToReleaseXLock
             || _pr_xt_hack_okayToReleaseXLock())) {
         needToLockXAgain = 1;

    /* This is the potentially blocking step */
    retVal = _PR_WaitForMultipleFDs(unixpds, pdcnt, timeout);

     if (needToLockXAgain) {

    if (retVal > 0) {
        /* Compute select results */
        if (rd) ZAP_SET(rd, width);
        if (wr) ZAP_SET(wr, width);
        if (ex) ZAP_SET(ex, width);

         * The return value can be either the number of ready file
         * descriptors or the number of set bits in the three fd_set's.
        retVal = 0;  /* we're going to recompute */
        eunixpd = unixpds + pdcnt;
        for (unixpd = unixpds; unixpd < eunixpd; unixpd++) {
            if (unixpd->out_flags) {
                int nbits = 0;  /* The number of set bits on for this fd */

                if (unixpd->out_flags & _PR_UNIX_POLL_NVAL) {
                    errno = EBADF;
                    PR_LOG(_pr_io_lm, PR_LOG_ERROR,
                            ("select returns EBADF for %d", unixpd->osfd));
                    retVal = -1;
                 * If a socket has a pending error, it is considered
                 * both readable and writable.  (See W. Richard Stevens,
                 * Unix Network Programming, Vol. 1, 2nd Ed., Section 6.3,
                 * pp. 153-154.)  We also consider a socket readable if
                 * it has a hangup condition.
                if (rd && (unixpd->in_flags & _PR_UNIX_POLL_READ)
                        && (unixpd->out_flags & (_PR_UNIX_POLL_READ
                        | _PR_UNIX_POLL_ERR | _PR_UNIX_POLL_HUP))) {
                    FD_SET(unixpd->osfd, rd);
                if (wr && (unixpd->in_flags & _PR_UNIX_POLL_WRITE)
                        && (unixpd->out_flags & (_PR_UNIX_POLL_WRITE
                        | _PR_UNIX_POLL_ERR))) {
                    FD_SET(unixpd->osfd, wr);
                if (ex && (unixpd->in_flags & _PR_UNIX_POLL_WRITE)
                        && (unixpd->out_flags & PR_POLL_EXCEPT)) {
                    FD_SET(unixpd->osfd, ex);
                PR_ASSERT(nbits > 0);
#if defined(HPUX) || defined(SOLARIS) || defined(SUNOS4) || defined(OSF1) || defined(AIX)
                retVal += nbits;
#else /* IRIX */
                retVal += 1;

    PR_ASSERT(tv || retVal != 0);
    PR_LOG(_pr_io_lm, PR_LOG_MIN, ("select returns %d", retVal));

    return retVal;