3 * Copyright © 2001 Novell, Inc. All Rights Reserved.
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
12 * DESCRIPTION : Socket related functions.
14 * Date : January 2001.
15 * Date Modified: June 26th 2001.
29 nw_htonl(u_long hostlong)
31 return htonl(hostlong);
35 nw_htons(u_short hostshort)
37 return htons(hostshort);
41 nw_ntohl(u_long netlong)
43 return ntohl(netlong);
47 nw_ntohs(u_short netshort)
49 return ntohs(netshort);
53 nw_accept(SOCKET s, struct sockaddr *addr, int *addrlen)
55 return ((SOCKET)(accept(s, addr, addrlen)));
59 nw_bind(SOCKET s, const struct sockaddr *addr, int addrlen)
61 return ((int)bind(s, (struct sockaddr *)addr, addrlen));
66 nw_connect(SOCKET s, const struct sockaddr *addr, int addrlen)
68 return((int)connect(s, (struct sockaddr *)addr, addrlen));
104 return ((struct netent *) getnetent());
110 return ((struct protoent *) getprotoent());
114 nw_gethostbyname(const char *name)
116 return(gethostbyname((char*)name));
120 nw_gethostname(char *name, int len)
122 return(gethostname(name, len));
126 nw_gethostbyaddr(const char *addr, int len, int type)
128 return(gethostbyaddr((char*)addr, len, type));
132 nw_getnetbyaddr(long net, int type)
134 return(getnetbyaddr(net,type));
138 nw_getnetbyname(char *name)
140 return (struct netent *)getnetbyname(name);
144 nw_getpeername(SOCKET s, struct sockaddr *addr, int *addrlen)
146 return((int)getpeername(s, addr, addrlen));
150 nw_getprotobyname(const char *name)
152 return ((struct protoent *)getprotobyname((char*)name));
156 nw_getprotobynumber(int num)
158 return ((struct protoent *)getprotobynumber(num));
162 nw_getservbyname(const char *name, const char *proto)
164 return (struct servent *)getservbyname((char*)name, (char*)proto);
169 nw_getservbyport(int port, const char *proto)
171 return (struct servent *)getservbyport(port, (char*)proto);
177 return (struct servent *) getservent();
181 nw_sethostent(int stayopen)
183 sethostent(stayopen);
187 nw_setnetent(int stayopen)
193 nw_setprotoent(int stayopen)
195 setprotoent(stayopen);
199 nw_setservent(int stayopen)
201 setservent(stayopen);
205 nw_setsockopt(SOCKET s, int level, int optname, const char* optval, int optlen)
207 return setsockopt(s, level, optname, (char*)optval, optlen);
211 nw_getsockname(SOCKET s, struct sockaddr *addr, int *addrlen)
213 return getsockname(s, addr, addrlen);
217 nw_getsockopt(SOCKET s, int level, int optname, char *optval, int *optlen)
219 return ((int)getsockopt(s, level, optname, optval, optlen));
223 nw_inet_addr(const char *cp)
225 return inet_addr((char*)cp);
229 nw_socket(int af, int type, int protocol)
233 #ifndef USE_SOCKETS_AS_HANDLES
234 s = socket(af, type, protocol);
236 if((s = socket(af, type, protocol)) == INVALID_SOCKET)
237 //errno = WSAGetLastError();
240 #endif /* USE_SOCKETS_AS_HANDLES */
246 nw_listen(SOCKET s, int backlog)
248 return(listen(s, backlog));
252 nw_send(SOCKET s, const char *buf, int len, int flags)
254 return(send(s,(char*)buf,len,flags));
258 nw_recv(SOCKET s, char *buf, int len, int flags)
260 return (recv(s, buf, len, flags));
264 nw_sendto(SOCKET s, const char *buf, int len, int flags,
265 const struct sockaddr *to, int tolen)
267 return(sendto(s, (char*)buf, len, flags, (struct sockaddr *)to, tolen));
271 nw_recvfrom(SOCKET s, char *buf, int len, int flags, struct sockaddr *from, int *fromlen)
274 int frombufsize = *fromlen;
276 r = recvfrom(s, buf, len, flags, from, fromlen);
277 //Not sure if the is required - chksgp
278 if (r && frombufsize == *fromlen)
279 (void)nw_getpeername(s, from, fromlen);
284 nw_select(int nfds, fd_set* rd, fd_set* wr, fd_set* ex, const struct timeval* timeout)
286 return(select(nfds, rd, wr, ex, (struct timeval*)timeout));
290 nw_shutdown(SOCKET s, int how)
292 return (shutdown(s, how));