Back to index

lightning-sunbird  0.9+nobinonly
macsocket.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef macksocket_h___
00039 #define macksocket_h___
00040 
00041 // macsock.h
00042 // Interface visible to xp code
00043 // C socket type definitions and routines
00044 // from sys/socket.h
00045 #include <Files.h>
00046 #include <OpenTptInternet.h>       // All the internet typedefs
00047 #include <utime.h>                        // For timeval
00048 /*
00049  * sleep and delay conflict with the same in unistd.h from Metrowerks.  OT
00050  * defines them as 
00051  *
00052  *    extern pascal void           OTDelay(UInt32 seconds);
00053  *    extern pascal void           OTIdle(void);
00054  *
00055  *    #define sleep(x)      OTDelay(x)
00056  *    #define delay(x)      OTDelay(x)
00057  */
00058 
00059 #undef sleep
00060 #undef delay
00061 
00062 #pragma once
00063 
00064 #include "prio.h"
00065 
00066 struct sockaddr {
00067        unsigned char sa_len;                     /* total length */
00068        unsigned char sa_family;           /* address family */
00069        char   sa_data[14];         /* actually longer; address value */
00070 };
00071 
00072 // from netinet/in.h
00073 struct in_addr {
00074        unsigned long s_addr;
00075 };
00076 
00077 struct sockaddr_in {
00078        unsigned char sin_len;
00079        unsigned char sin_family;          // AF_INET
00080        unsigned short       sin_port;
00081        struct in_addr sin_addr;
00082        char          sin_zero[8];
00083 };
00084 
00085 struct hostent {
00086        char   *h_name;      /* official name of host */
00087        char   **h_aliases;  /* alias list */
00088        int    h_addrtype;   /* host address type */
00089        int    h_length;     /* length of address */
00090        char   **h_addr_list;       /* list of addresses from name server */
00091 #define       h_addr h_addr_list[0]       /* address, for backward compatiblity */
00092 };
00093 
00094 // Necessary network defines, found by grepping unix headers when XP code would not compile
00095 #define FIONBIO 1
00096 #define SOCK_STREAM 1
00097 #define SOCK_DGRAM          2
00098 #define IPPROTO_TCP  INET_TCP             // Default TCP protocol
00099 #define IPPROTO_UDP         INET_UDP             // Default UDP protocol
00100 #define INADDR_ANY          kOTAnyInetAddress
00101 #define SOL_SOCKET          XTI_GENERIC          // Any type of socket
00102 #define SO_REUSEADDR IP_REUSEADDR
00103 #define SO_BROADCAST IP_BROADCAST
00104 #define MSG_PEEK            0x2                         // Just look at a message waiting, donŐt actually read it.
00105 
00106 typedef unsigned long u_long;
00107 
00108 /* ldap.h has its own definition of fd_set */
00109 /* select support */
00110 #if !defined(FD_SET)
00111 #define       NBBY    8
00112 typedef long    fd_mask;
00113 #define NFDBITS (sizeof(fd_mask) * NBBY)  /* bits per mask */
00114 
00115 #ifndef howmany
00116 #define howmany(x, y)   (((x)+((y)-1))/(y))
00117 #endif
00118 #define FD_SETSIZE 64
00119 typedef       struct fd_set{
00120     fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
00121 } fd_set;
00122 
00123 #define       FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
00124 #define       FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
00125 #define       FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
00126 #define       FD_ZERO(p)      memset (p, 0, sizeof(*(p)))
00127 #endif /* !FD_SET */
00128 
00129 
00130 #ifdef __cplusplus
00131 extern "C" {
00132 #endif
00133 
00134 extern unsigned long inet_addr(const char *cp);
00135 extern char *inet_ntoa(struct in_addr in);
00136 
00137 inline unsigned long htonl(unsigned long hostlong) {return hostlong;}
00138 inline unsigned long ntohl(unsigned long netlong) {return netlong;}
00139 inline unsigned short ntohs(unsigned short netshort) {return netshort;}
00140 inline unsigned short htons(unsigned short hostshort) {return hostshort;}
00141 
00142 
00143 // UNIX look-alike routines
00144 // They make sure that the arguments passed in are valid, and then
00145 //
00146 extern struct hostent *macsock_gethostbyaddr(const void *addr, int addrlen, int type);
00147 
00148 extern int macsock_socket(int domain, int type, int protocol);
00149 extern int macsock_ioctl(int sID, unsigned int request, void *value);
00150 extern int macsock_connect(int sID, struct sockaddr *name, int namelen);
00151 extern int macsock_write(int sID, const void *buffer, unsigned buflen);
00152 extern int macsock_read(int sID, void *buf, unsigned nbyte);
00153 extern int macsock_close(int sID);
00154 
00155 extern int macsock_accept(int sID, struct sockaddr *addr, int *addrlen);
00156 extern int macsock_bind(int sID, const struct sockaddr *name, int namelen);
00157 extern int macsock_listen(int sID, int backlog);
00158 
00159 extern int macsock_shutdown(int sID, int how);
00160 extern int macsock_getpeername(int sID, struct sockaddr *name, int *namelen);
00161 extern int macsock_getsockname(int sID, struct sockaddr *name, int *namelen);
00162 extern int macsock_getsockopt(int sID, int level, int optname, void *optval,int *optlen);
00163 extern int macsock_setsockopt(int sID, int level, int optname, const void *optval,int optlen);
00164 extern int macsock_socketavailable(int sID, size_t *bytesAvailable);
00165 extern int macsock_dup(int sID);
00166 
00167 extern int macsock_send(int sID, const void *msg, int len, int flags);
00168 extern int macsock_sendto(int sID, const void *msg, int len, int flags, struct sockaddr *toAddr, int toLen);
00169 extern int macsock_recvfrom(int sID, void *buf, int len, int flags, struct sockaddr *from, int *fromLen);
00170 extern int macsock_recv(int sID, void *buf, int len, int flags);
00171 
00172 extern int select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
00173 
00174 
00175 #define macsock_gethostbyaddr PR_GetHostByAddr
00176 #define macsock_socket PR_Socket
00177 #define macsock_connect PR_Connect
00178 #define macsock_write PR_Write
00179 #define macsock_read PR_Read
00180 #define macsock_close PR_Close
00181 #define macsock_accept PR_Accept
00182 #define macsock_bind PR_Bind
00183 #define macsock_listen PR_Listen
00184 #define macsock_shutdown PR_Shutdown
00185 #define macsock_getpeername PR_GetPeerName
00186 #define macsock_getsockname PR_GetSockName
00187 #define macsock_socketavailable PR_SocketAvailable
00188 #define macsock_send PR_Send
00189 #define macsock_sendto PR_SendTo
00190 #define macsock_recvfrom PR_RecvFrom
00191 #define macsock_recv PR_Recv
00192 
00193 #ifdef __cplusplus
00194 }
00195 #endif
00196 //extern int errno;
00197 
00198 /*
00199 macsock_sendmsg
00200 macsock_readv
00201 macsock_writev
00202 */
00203 
00204 /* New definitions that are not defined in macsock.h in macsock library */
00205 struct protoent {
00206     char      *p_name;             /* official protocol name */
00207     char      **p_aliases;  /* alias list */
00208     int              p_proto;             /* protocol # */
00209 };
00210 
00211 extern struct protoent *getprotobyname(const char * name);
00212 extern struct protoent *getprotobynumber(int number);
00213 
00214 extern int gethostname (char *name, int namelen);
00215 extern struct hostent *gethostbyname(const char * name);
00216 extern struct hostent *gethostbyaddr(const void *addr, int addrlen, int type);
00217 
00218 #define INADDR_LOOPBACK     0x7F000001
00219 
00220 #define SO_KEEPALIVE TCP_KEEPALIVE
00221 #define SO_RCVBUF           XTI_RCVBUF
00222 #define SO_SNDBUF           XTI_SNDBUF
00223 #define SO_LINGER       XTI_LINGER          /* linger on close if data present */
00224 
00225 #define IPPROTO_IP          INET_IP
00226 
00227 /* Get/Set sock opt until fixed in NSPR 2.0 */
00228 struct  linger {
00229         int     l_onoff;                /* option on/off */
00230         int     l_linger;               /* linger time */
00231 };
00232 
00233 struct ip_mreq {
00234         struct in_addr  imr_multiaddr;  /* IP multicast address of group */
00235         struct in_addr  imr_interface;  /* local IP address of interface */
00236 };
00237 
00238 #endif /* macksocket_h___ */