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.
28 // This is defined here since arpa\inet.h defines this array as an extern,
29 // and arpa\inet.h gets included by the inet_ntoa call.
30 char nwinet_scratch[18] = {'\0'};
34 nw_htonl(u_long hostlong)
36 return htonl(hostlong);
40 nw_htons(u_short hostshort)
42 return htons(hostshort);
46 nw_ntohl(u_long netlong)
48 return ntohl(netlong);
52 nw_ntohs(u_short netshort)
54 return ntohs(netshort);
58 nw_accept(SOCKET s, struct sockaddr *addr, int *addrlen)
60 return ((SOCKET)(accept(s, addr, addrlen)));
64 nw_bind(SOCKET s, const struct sockaddr *addr, int addrlen)
66 return ((int)bind(s, (struct sockaddr *)addr, addrlen));
71 nw_connect(SOCKET s, const struct sockaddr *addr, int addrlen)
73 return((int)connect(s, (struct sockaddr *)addr, addrlen));
103 return(gethostent());
109 return ((struct netent *) getnetent());
115 return ((struct protoent *) getprotoent());
119 nw_gethostbyname(const char *name)
121 return(gethostbyname((char*)name));
125 nw_gethostname(char *name, int len)
127 return(gethostname(name, len));
131 nw_gethostbyaddr(const char *addr, int len, int type)
133 return(gethostbyaddr((char*)addr, len, type));
137 nw_getnetbyaddr(long net, int type)
139 return(getnetbyaddr(net,type));
143 nw_getnetbyname(char *name)
145 return (struct netent *)getnetbyname(name);
149 nw_getpeername(SOCKET s, struct sockaddr *addr, int *addrlen)
151 return((int)getpeername(s, addr, addrlen));
155 nw_getprotobyname(const char *name)
157 return ((struct protoent *)getprotobyname((char*)name));
161 nw_getprotobynumber(int num)
163 return ((struct protoent *)getprotobynumber(num));
167 nw_getservbyname(const char *name, const char *proto)
169 return (struct servent *)getservbyname((char*)name, (char*)proto);
174 nw_getservbyport(int port, const char *proto)
176 return (struct servent *)getservbyport(port, (char*)proto);
182 return (struct servent *) getservent();
186 nw_sethostent(int stayopen)
188 #ifdef HAS_SETHOSTENT
189 sethostent(stayopen);
194 nw_setnetent(int stayopen)
202 nw_setprotoent(int stayopen)
204 #ifdef HAS_SETPROTENT
205 setprotoent(stayopen);
210 nw_setservent(int stayopen)
212 #ifdef HAS_SETSERVENT
213 setservent(stayopen);
218 nw_setsockopt(SOCKET s, int level, int optname, const char* optval, int optlen)
220 return setsockopt(s, level, optname, (char*)optval, optlen);
224 nw_getsockname(SOCKET s, struct sockaddr *addr, int *addrlen)
226 return getsockname(s, addr, addrlen);
230 nw_getsockopt(SOCKET s, int level, int optname, char *optval, int *optlen)
232 return ((int)getsockopt(s, level, optname, optval, optlen));
236 nw_inet_addr(const char *cp)
238 return inet_addr((char*)cp);
242 nw_inet_ntoa(struct in_addr in)
244 return inet_ntoa(in);
248 nw_socket(int af, int type, int protocol)
252 #ifndef USE_SOCKETS_AS_HANDLES
253 s = socket(af, type, protocol);
255 if((s = socket(af, type, protocol)) == INVALID_SOCKET)
256 //errno = WSAGetLastError();
259 #endif /* USE_SOCKETS_AS_HANDLES */
265 nw_listen(SOCKET s, int backlog)
267 return(listen(s, backlog));
271 nw_send(SOCKET s, const char *buf, int len, int flags)
273 return(send(s,(char*)buf,len,flags));
277 nw_recv(SOCKET s, char *buf, int len, int flags)
279 return (recv(s, buf, len, flags));
283 nw_sendto(SOCKET s, const char *buf, int len, int flags,
284 const struct sockaddr *to, int tolen)
286 return(sendto(s, (char*)buf, len, flags, (struct sockaddr *)to, tolen));
290 nw_recvfrom(SOCKET s, char *buf, int len, int flags, struct sockaddr *from, int *fromlen)
293 int frombufsize = *fromlen;
295 r = recvfrom(s, buf, len, flags, from, fromlen);
296 //Not sure if the is required - chksgp
297 if (r && frombufsize == *fromlen)
298 (void)nw_getpeername(s, from, fromlen);
303 nw_select(int nfds, fd_set* rd, fd_set* wr, fd_set* ex, const struct timeval* timeout)
305 return(select(nfds, rd, wr, ex, (struct timeval*)timeout));
309 nw_shutdown(SOCKET s, int how)
311 return (shutdown(s, how));