2 * Copyright (C) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
3 * Helsinki University of Technology, Finland.
5 * Copyright (C) 2005 - 2007 The AROS Dev Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 #include <aros/asmcall.h>
26 #include <aros/libcall.h>
28 #include <sys/param.h>
29 #include <sys/systm.h>
30 #include <sys/socketvar.h>
31 #include <sys/kernel.h>
32 #include <sys/ioctl.h>
33 #include <sys/protosw.h>
34 #include <sys/malloc.h>
35 #include <sys/synch.h>
38 #include <sys/errno.h>
40 #include <sys/socket.h>
41 #include <net/route.h>
43 #include <kern/amiga_includes.h>
45 #include <api/amiga_api.h>
46 #include <api/amiga_libcallentry.h>
47 #include <api/allocdatabuffer.h>
49 #include <api/apicalls.h>
51 #include <net/if_protos.h>
53 #include <bsdsocket/socketbasetags.h>
55 #include <kern/uipc_domain_protos.h>
56 #include <kern/uipc_socket_protos.h>
57 #include <kern/uipc_socket2_protos.h>
59 #include <exec/semaphores.h>
60 #include <proto/exec.h>
62 #include <api/miami_api.h>
63 #include <kern/amiga_netdb.h>
67 #include <proto/bsdsocket.h>
69 void sethtent(struct SocketBase
*libPtr
)
71 ObtainSemaphoreShared (&ndb_Lock
);
72 libPtr
->HostentNode
= (struct HostentNode
*)NDB
->ndb_Hosts
.mlh_Head
;
75 struct hostent
*gethtent(struct SocketBase
*libPtr
)
77 struct HostentNode
*hn
;
79 hn
= libPtr
->HostentNode
;
81 ObtainSemaphoreShared (&ndb_Lock
);
82 hn
= (struct HostentNode
*)NDB
->ndb_Hosts
.mlh_Head
;
84 if (hn
->hn_Node
.mln_Succ
) {
85 libPtr
->HostentNode
= (struct HostentNode
*)hn
->hn_Node
.mln_Succ
;
91 void endhostent(struct SocketBase
*libPtr
)
93 libPtr
->HostentNode
= NULL
;
94 ReleaseSemaphore (&ndb_Lock
);
98 /* **** GETPROTOENT */
100 struct protoent
*__getprotoent(struct SocketBase
*libPtr
)
102 struct ProtoentNode
*pn
;
104 DSYSCALLS(log(LOG_DEBUG
,"getprotoent() called");)
106 pn
= libPtr
->ProtoentNode
;
108 ObtainSemaphoreShared (&ndb_Lock
);
109 pn
= (struct ProtoentNode
*)NDB
->ndb_Protocols
.mlh_Head
;
111 if (pn
->pn_Node
.mln_Succ
) {
112 libPtr
->ProtoentNode
= (struct ProtoentNode
*)pn
->pn_Node
.mln_Succ
;
118 #if defined(__CONFIG_ROADSHOW__)
119 AROS_LH0(struct protoent
*, getprotoent
,
120 struct SocketBase
*, libPtr
, 95, UL
)
124 return __getprotoent(libPtr
);
130 AROS_LH0(struct protoent
*, Miami_getprotoent
,
131 struct MiamiBase
*, MiamiBase
, 14, Miami
136 return __getprotoent(MiamiBase
->_SocketBase
);
141 /* **** ENDPROTOENT */
143 void __endprotoent(struct SocketBase
*libPtr
)
145 DSYSCALLS(log(LOG_DEBUG
,"endprotoent() called");)
146 libPtr
->ProtoentNode
= NULL
;
147 ReleaseSemaphore (&ndb_Lock
);
152 #if defined(__CONFIG_ROADSHOW__)
153 AROS_LH0(void, endprotoent
,
154 struct SocketBase
*, libPtr
, 94, UL
)
158 __endprotoent(libPtr
);
164 AROS_LH0(void, Miami_endprotoent
,
165 struct MiamiBase
*, MiamiBase
, 15, Miami
170 DSYSCALLS(log(LOG_DEBUG
,"endprotoent() called");)
171 __endprotoent(MiamiBase
->_SocketBase
);
178 AROS_LH0(void, ClearDynDomain
,
179 struct MiamiBase
*, MiamiBase
, 24, Miami
184 struct MinNode
*node
, *nnode
;
186 if (MiamiBase
->DynDomain_Locked
) {
187 ObtainSemaphore (&DynDB
.dyn_Lock
);
188 MiamiBase
->DynDomain_Locked
= 1;
190 for (node
= DynDB
.dyn_Domains
.mlh_Head
; node
->mln_Succ
;) {
191 nnode
= node
->mln_Succ
;
192 bsd_free(node
, NULL
);
195 NewList((struct List
*)&DynDB
.dyn_Domains
);
200 AROS_LH0(void, ClearDynNameServ
,
201 struct MiamiBase
*, MiamiBase
, 9, Miami
206 struct MinNode
*node
, *nnode
;
208 if (MiamiBase
->DynNameServ_Locked
) {
209 ObtainSemaphore (&DynDB
.dyn_Lock
);
210 MiamiBase
->DynNameServ_Locked
= 1;
212 for (node
= DynDB
.dyn_NameServers
.mlh_Head
; node
->mln_Succ
;) {
213 nnode
= node
->mln_Succ
;
214 bsd_free(node
, NULL
);
217 NewList((struct List
*)&DynDB
.dyn_NameServers
);
222 AROS_LH0(void, EndDynDomain
,
223 struct MiamiBase
*, MiamiBase
, 19, Miami
228 if (MiamiBase
->DynDomain_Locked
) {
229 ReleaseSemaphore (&DynDB
.dyn_Lock
);
230 MiamiBase
->DynDomain_Locked
= 0;
231 if (!MiamiBase
->DynNameServ_Locked
)
238 AROS_LH0(void, EndDynNameServ
,
239 struct MiamiBase
*, MiamiBase
, 20, Miami
244 if (MiamiBase
->DynNameServ_Locked
) {
245 ReleaseSemaphore (&DynDB
.dyn_Lock
);
246 MiamiBase
->DynNameServ_Locked
= 0;
247 if (!MiamiBase
->DynDomain_Locked
)
254 AROS_LH1(LONG
, AddDynNameServ
,
255 AROS_LHA(struct sockaddr_in
*, entry
, A0
),
256 struct MiamiBase
*, MiamiBase
, 21, Miami
261 struct NameserventNode
*nsn
;
263 if (entry
->sin_family
!= AF_INET
)
265 if ((nsn
= bsd_malloc(sizeof(struct NameserventNode
), NULL
, NULL
)) == NULL
) {
266 writeErrnoValue(MiamiBase
->_SocketBase
, ENOMEM
);
270 nsn
->nsn_EntSize
= sizeof (nsn
->nsn_Ent
);
271 nsn
->nsn_Ent
.ns_addr
.s_addr
= entry
->sin_addr
.s_addr
;
273 if (MiamiBase
->DynNameServ_Locked
) {
274 ObtainSemaphore (&DynDB
.dyn_Lock
);
275 MiamiBase
->DynNameServ_Locked
= 1;
278 AddTail((struct List
*)&DynDB
.dyn_NameServers
, (struct Node
*)nsn
);
284 AROS_LH1(LONG
, AddDynDomain
,
285 AROS_LHA(STRPTR
, entry
, A0
),
286 struct MiamiBase
*, MiamiBase
, 22, Miami
291 struct DomainentNode
*dn
;
294 nodesize
= sizeof (*dn
) + strlen(entry
) + 1;
295 if ((dn
= bsd_malloc(nodesize
, NULL
, NULL
)) == NULL
) {
296 writeErrnoValue(MiamiBase
->_SocketBase
, ENOMEM
);
299 dn
->dn_EntSize
= nodesize
- sizeof (struct GenentNode
);
300 dn
->dn_Ent
.d_name
= (char *)(dn
+ 1);
302 strcpy((char *)(dn
+ 1), entry
);
304 if (MiamiBase
->DynDomain_Locked
) {
305 ObtainSemaphore (&DynDB
.dyn_Lock
);
306 MiamiBase
->DynDomain_Locked
= 1;
309 AddTail((struct List
*)&DynDB
.dyn_Domains
, (struct Node
*)dn
);
315 AROS_LH0(struct hostent
*, Miami_gethostent
,
316 struct MiamiBase
*, MiamiBase
, 10, Miami
)
320 #if defined(__AROS__)
321 D(bug("[AROSTCP.MIAMI] amiga_ndbent.c: Miami_gethostent()\n"));
324 return gethtent(MiamiBase
->_SocketBase
);
330 AROS_LH0(void, Miami_endhostent
,
331 struct MiamiBase
*, MiamiBase
, 12, Miami
)
335 #if defined(__AROS__)
336 D(bug("[AROSTCP.MIAMI] amiga_ndbent.c: Miami_endhostent()\n"));
339 endhostent(MiamiBase
->_SocketBase
);