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.
23 #if defined(PERL_OBJECT)
33 static struct servent* nw_savecopyservent(struct servent*d,
39 nw_htonl(u_long hostlong)
41 return htonl(hostlong);
45 nw_htons(u_short hostshort)
47 return htons(hostshort);
51 nw_ntohl(u_long netlong)
53 return ntohl(netlong);
57 nw_ntohs(u_short netshort)
59 return ntohs(netshort);
63 nw_accept(SOCKET s, struct sockaddr *addr, int *addrlen)
65 return ((SOCKET)(accept(s, addr, addrlen)));
69 nw_bind(SOCKET s, const struct sockaddr *addr, int addrlen)
71 return ((int)bind(s, (struct sockaddr *)addr, addrlen));
76 nw_connect(SOCKET s, const struct sockaddr *addr, int addrlen)
78 return((int)connect(s, (struct sockaddr *)addr, addrlen));
108 return(gethostent());
114 return ((struct netent *) getnetent());
120 return ((struct protoent *) getprotoent());
124 nw_gethostbyname(const char *name)
126 return(gethostbyname((char*)name));
130 nw_gethostname(char *name, int len)
132 return(gethostname(name, len));
136 nw_gethostbyaddr(const char *addr, int len, int type)
138 return(gethostbyaddr((char*)addr, len, type));
142 nw_getnetbyaddr(long net, int type)
144 return(getnetbyaddr(net,type));
148 nw_getnetbyname(char *name)
150 return (struct netent *)getnetbyname(name);
154 nw_getpeername(SOCKET s, struct sockaddr *addr, int *addrlen)
156 return((int)getpeername(s, addr, addrlen));
160 nw_getprotobyname(const char *name)
162 return ((struct protoent *)getprotobyname((char*)name));
166 nw_getprotobynumber(int num)
168 return ((struct protoent *)getprotobynumber(num));
172 nw_getservbyname(const char *name, const char *proto)
177 r = getservbyname((char*)name, (char*)proto);
179 /*r = nw_savecopyservent(&nw_servent, r, proto);*/
186 nw_getservbyport(int port, const char *proto)
191 r = getservbyport(port, (char*)proto);
193 //r = nw_savecopyservent(&nw_servent, r, proto);
201 return (struct servent *) getservent();
205 nw_sethostent(int stayopen)
207 sethostent(stayopen);
211 nw_setnetent(int stayopen)
217 nw_setprotoent(int stayopen)
219 setprotoent(stayopen);
223 nw_setservent(int stayopen)
225 setservent(stayopen);
229 nw_setsockopt(SOCKET s, int level, int optname, const char* optval, int optlen)
231 return setsockopt(s, level, optname, optval, optlen);
235 nw_getsockname(SOCKET s, struct sockaddr *addr, int *addrlen)
237 return getsockname(s, addr, addrlen);
241 nw_getsockopt(SOCKET s, int level, int optname, char *optval, int *optlen)
243 return ((int)getsockopt(s, level, optname, optval, optlen));
247 nw_inet_addr(const char *cp)
249 return inet_addr((char*)cp);
252 static struct servent*
253 nw_savecopyservent(struct servent*d, struct servent*s, const char *proto)
255 d->s_name = s->s_name;
256 d->s_aliases = s->s_aliases;
257 d->s_port = s->s_port;
258 #ifndef __BORLANDC__ /* Buggy on Win95 and WinNT-with-Borland-WSOCK */
259 if (/*!IsWin95() && */s->s_proto && strlen(s->s_proto))
260 d->s_proto = s->s_proto;
263 if (proto && strlen(proto))
264 d->s_proto = (char *)proto;
272 nw_socket(int af, int type, int protocol)
276 #ifndef USE_SOCKETS_AS_HANDLES
277 s = socket(af, type, protocol);
280 if((s = socket(af, type, protocol)) == INVALID_SOCKET)
281 //errno = WSAGetLastError();
284 #endif /* USE_SOCKETS_AS_HANDLES */
290 nw_listen(SOCKET s, int backlog)
292 return(listen(s, backlog));
296 nw_send(SOCKET s, const char *buf, int len, int flags)
298 return(send(s,(char*)buf,len,flags));
302 nw_recv(SOCKET s, char *buf, int len, int flags)
304 return (recv(s, buf, len, flags));
308 nw_sendto(SOCKET s, const char *buf, int len, int flags,
309 const struct sockaddr *to, int tolen)
311 return(sendto(s, (char*)buf, len, flags, (struct sockaddr *)to, tolen));
315 nw_recvfrom(SOCKET s, char *buf, int len, int flags, struct sockaddr *from, int *fromlen)
318 int frombufsize = *fromlen;
320 r = recvfrom(s, buf, len, flags, from, fromlen);
321 //Not sure if the is required - chksgp
322 if (r && frombufsize == *fromlen)
323 (void)nw_getpeername(s, from, fromlen);
328 nw_select(int nfds, fd_set* rd, fd_set* wr, fd_set* ex, const struct timeval* timeout)
330 return(select(nfds, rd, wr, ex, (struct timeval*)timeout));
334 nw_shutdown(SOCKET s, int how)
336 return (shutdown(s, how));