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_getsockname(SOCKET s, struct sockaddr *addr, int *addrlen)
231 return getsockname(s, addr, addrlen);
235 nw_getsockopt(SOCKET s, int level, int optname, char *optval, int *optlen)
237 return ((int)getsockopt(s, level, optname, optval, optlen));
241 nw_inet_addr(const char *cp)
243 return inet_addr((char*)cp);
246 static struct servent*
247 nw_savecopyservent(struct servent*d, struct servent*s, const char *proto)
249 d->s_name = s->s_name;
250 d->s_aliases = s->s_aliases;
251 d->s_port = s->s_port;
252 #ifndef __BORLANDC__ /* Buggy on Win95 and WinNT-with-Borland-WSOCK */
253 if (/*!IsWin95() && */s->s_proto && strlen(s->s_proto))
254 d->s_proto = s->s_proto;
257 if (proto && strlen(proto))
258 d->s_proto = (char *)proto;
266 nw_socket(int af, int type, int protocol)
270 #ifndef USE_SOCKETS_AS_HANDLES
271 s = socket(af, type, protocol);
274 if((s = socket(af, type, protocol)) == INVALID_SOCKET)
275 //errno = WSAGetLastError();
278 #endif /* USE_SOCKETS_AS_HANDLES */
284 nw_listen(SOCKET s, int backlog)
286 return(listen(s, backlog));
290 nw_send(SOCKET s, const char *buf, int len, int flags)
292 return(send(s,(char*)buf,len,flags));
296 nw_recv(SOCKET s, char *buf, int len, int flags)
298 return (recv(s, buf, len, flags));
302 nw_sendto(SOCKET s, const char *buf, int len, int flags,
303 const struct sockaddr *to, int tolen)
305 return(sendto(s, (char*)buf, len, flags, (struct sockaddr *)to, tolen));
309 nw_recvfrom(SOCKET s, char *buf, int len, int flags, struct sockaddr *from, int *fromlen)
312 int frombufsize = *fromlen;
314 r = recvfrom(s, buf, len, flags, from, fromlen);
315 //Not sure if the is required - chksgp
316 if (r && frombufsize == *fromlen)
317 (void)nw_getpeername(s, from, fromlen);
322 nw_select(int nfds, fd_set* rd, fd_set* wr, fd_set* ex, const struct timeval* timeout)
324 return(select(nfds, rd, wr, ex, (struct timeval*)timeout));
328 nw_shutdown(SOCKET s, int how)
330 return (shutdown(s, how));