2 * Copyright (c) 1994, 1995. Netscape Communications Corporation. All
5 * Use of this software is governed by the terms of the license agreement for
6 * the Netscape Communications or Netscape Comemrce Server between the
11 /* ------------------------------------------------------------------------ */
15 * net.h: system specific networking definitions
26 #include "file.h" /* for client file descriptors */
28 #include "pblock.h" /* for client data block */
31 /* This should be a user-given parameter later */
32 #define NET_BUFFERSIZE 8192
34 #define NET_READ_TIMEOUT 120
35 #define NET_WRITE_TIMEOUT 300
37 #define SSL_HANDSHAKE_TIMEOUT 300
39 #if defined(NET_SOCKETS) || defined(NET_SSL)
44 #include <sys/types.h>
45 #include <sys/socket.h>
46 #include <netinet/in.h> /* sockaddr and in_addr */
47 #include <arpa/inet.h> /* inet_ntoa */
48 #include <netdb.h> /* hostent stuff */
49 #endif /* NET_WINSOCK */
56 /* -------------------------------- Global -------------------------------- */
58 extern int net_enabledns
;
61 /* ------------------------------ Data types ------------------------------ */
65 typedef SOCKET SYS_NETFD
;
67 typedef int SYS_NETFD
;
68 #endif /* NET_WINSOCK */
70 #define SYS_NET_ERRORFD -1
73 /* -------------------------------- Macros -------------------------------- */
76 /* These may be different for non-UNIX systems. */
80 #define net_socket socket
81 #define net_setsockopt setsockopt
82 #define net_getsockopt getsockopt
83 #define net_listen listen
84 #define net_select select
85 #define net_getpeername getpeername
88 #define net_close(sd) close(sd)
90 #else /* NET_WINSOCK */
91 #define net_close(sd) closesocket(sd)
92 #define system_netbind bind
93 int net_bind(SYS_NETFD s
, const struct sockaddr
*name
, int namelen
);
94 #endif /* NET_WINSOCK */
96 #ifdef DAEMON_NEEDS_SEMAPHORE
97 #define net_accept net_semaccept
98 #else /* ! DAEMON_NEEDS_SEMAPHORE */
99 #define net_accept accept
100 #endif /* DAEMON_NEEDS_SEMAPHORE */
103 #define net_close(sd) SSL_Close(sd)
104 #define net_socket SSL_Socket
105 #define net_setsockopt SSL_SetSockOpt
106 #define net_getsockopt SSL_GetSockOpt
109 #define net_bind SSL_Bind
111 #define system_netbind SSL_Bind
112 int net_bind(SYS_NETFD s
, const struct sockaddr
*name
, int namelen
);
115 #define net_listen SSL_Listen
116 #define net_select select /* !!! */
117 #define net_getpeername SSL_GetPeerName
118 #define net_accept SSL_Accept
119 #endif /* ! NET_SSL */
122 /* Users should never call the system_net* functions. */
124 #define system_netread(sd, buf, sz) SSL_Read(sd, buf, sz)
125 #define system_netwrite SSL_Write
126 #else /* ! NET_SSL */
128 #if !defined(NET_WINSOCK)
129 #define system_netread(sd, buf, sz) read(sd, buf, sz)
130 #define system_netwrite write
131 #else /* NET_WINSOCK */
132 #define system_netread(sd, buf, sz) recv(sd, buf, sz, 0)
133 #define system_netwrite(sd, buf, sz) send(sd, buf, sz, 0)
134 #endif /* ! NET_WINSOCK */
138 int net_read(SYS_NETFD sd
, char *buf
, int sz
, int timeout
);
139 int net_write(SYS_NETFD sd
, char *buf
, int sz
);
141 #ifdef DAEMON_NEEDS_SEMAPHORE
142 int net_semaccept_init(int port
);
143 int net_semaccept(int s
, struct sockaddr
*addr
, int *addrlen
);
144 void net_semaccept_terminate();
148 /* ------------------------------ Prototypes ------------------------------ */
152 * net_find_fqdn looks through the given hostent structure trying to find
153 * a FQDN for the host. If it finds none, it returns NULL. Otherwise, it
154 * returns a newly allocated copy of that string.
157 char *net_find_fqdn(struct hostent
*p
);
160 * net_ip2host transforms the given textual IP number into a FQDN. If it
161 * can't find a FQDN, it will return what it can get. Otherwise, NULL.
163 * verify is whether or not the function should verify the hostname it
164 * gets. This takes an extra query but is safer for use in access control.
167 char *net_ip2host(char *ip
, int verify
);
170 * net_sendmail sends mail to the specified recipient with the given subject
171 * and message. Currently uses external programs.
174 int net_sendmail(char *to
, char *subject
, char *msg
);