tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / workbench / network / stacks / AROSTCP / bsdsocket / api / amiga_ndbent.c
blob5ee72926a54660f7ae64ff6eb70af4128b4083c0
1 /*
2 * Copyright (C) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
3 * Helsinki University of Technology, Finland.
4 * All rights reserved.
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,
19 * MA 02111-1307, USA.
23 #include <conf.h>
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>
37 #include <sys/time.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>
61 #include <errno.h>
62 #include <api/miami_api.h>
63 #include <kern/amiga_netdb.h>
65 #include <syslog.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;
80 if (!hn) {
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;
86 return &hn->hn_Ent;
87 } else
88 return NULL;
91 void endhostent(struct SocketBase *libPtr)
93 libPtr->HostentNode = NULL;
94 ReleaseSemaphore (&ndb_Lock);
95 return;
98 /* **** GETPROTOENT */
100 struct protoent *__getprotoent(struct SocketBase *libPtr)
102 struct ProtoentNode *pn;
104 DSYSCALLS(log(LOG_DEBUG,"getprotoent() called");)
106 pn = libPtr->ProtoentNode;
107 if (!pn) {
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;
113 return &pn->pn_Ent;
114 } else
115 return NULL;
118 #if defined(__CONFIG_ROADSHOW__)
119 AROS_LH0(struct protoent *, getprotoent,
120 struct SocketBase *, libPtr, 95, UL)
122 AROS_LIBFUNC_INIT
124 return __getprotoent(libPtr);
126 AROS_LIBFUNC_EXIT
128 #endif
130 AROS_LH0(struct protoent *, Miami_getprotoent,
131 struct MiamiBase *, MiamiBase, 14, Miami
134 AROS_LIBFUNC_INIT
136 return __getprotoent(MiamiBase->_SocketBase);
138 AROS_LIBFUNC_EXIT
141 /* **** ENDPROTOENT */
143 void __endprotoent(struct SocketBase *libPtr)
145 DSYSCALLS(log(LOG_DEBUG,"endprotoent() called");)
146 libPtr->ProtoentNode = NULL;
147 ReleaseSemaphore (&ndb_Lock);
149 return;
152 #if defined(__CONFIG_ROADSHOW__)
153 AROS_LH0(void, endprotoent,
154 struct SocketBase *, libPtr, 94, UL)
156 AROS_LIBFUNC_INIT
158 __endprotoent(libPtr);
160 AROS_LIBFUNC_EXIT
162 #endif
164 AROS_LH0(void, Miami_endprotoent,
165 struct MiamiBase *, MiamiBase, 15, Miami
168 AROS_LIBFUNC_INIT
170 DSYSCALLS(log(LOG_DEBUG,"endprotoent() called");)
171 __endprotoent(MiamiBase->_SocketBase);
173 AROS_LIBFUNC_EXIT
176 /* **** */
178 AROS_LH0(void, ClearDynDomain,
179 struct MiamiBase *, MiamiBase, 24, Miami
182 AROS_LIBFUNC_INIT
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);
193 node = nnode;
195 NewList((struct List *)&DynDB.dyn_Domains);
197 AROS_LIBFUNC_EXIT
200 AROS_LH0(void, ClearDynNameServ,
201 struct MiamiBase *, MiamiBase, 9, Miami
204 AROS_LIBFUNC_INIT
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);
215 node = nnode;
217 NewList((struct List *)&DynDB.dyn_NameServers);
219 AROS_LIBFUNC_EXIT
222 AROS_LH0(void, EndDynDomain,
223 struct MiamiBase *, MiamiBase, 19, Miami
226 AROS_LIBFUNC_INIT
228 if (MiamiBase->DynDomain_Locked) {
229 ReleaseSemaphore (&DynDB.dyn_Lock);
230 MiamiBase->DynDomain_Locked = 0;
231 if (!MiamiBase->DynNameServ_Locked)
232 ndb_Serial++;
235 AROS_LIBFUNC_EXIT
238 AROS_LH0(void, EndDynNameServ,
239 struct MiamiBase *, MiamiBase, 20, Miami
242 AROS_LIBFUNC_INIT
244 if (MiamiBase->DynNameServ_Locked) {
245 ReleaseSemaphore (&DynDB.dyn_Lock);
246 MiamiBase->DynNameServ_Locked = 0;
247 if (!MiamiBase->DynDomain_Locked)
248 ndb_Serial++;
251 AROS_LIBFUNC_EXIT
254 AROS_LH1(LONG, AddDynNameServ,
255 AROS_LHA(struct sockaddr_in *, entry, A0),
256 struct MiamiBase *, MiamiBase, 21, Miami
259 AROS_LIBFUNC_INIT
261 struct NameserventNode *nsn;
263 if (entry->sin_family != AF_INET)
264 return EAFNOSUPPORT;
265 if ((nsn = bsd_malloc(sizeof(struct NameserventNode), NULL, NULL)) == NULL) {
266 writeErrnoValue(MiamiBase->_SocketBase, ENOMEM);
267 return 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);
279 return 0;
281 AROS_LIBFUNC_EXIT
284 AROS_LH1(LONG, AddDynDomain,
285 AROS_LHA(STRPTR, entry, A0),
286 struct MiamiBase *, MiamiBase, 22, Miami
289 AROS_LIBFUNC_INIT
291 struct DomainentNode *dn;
292 short nodesize;
294 nodesize = sizeof (*dn) + strlen(entry) + 1;
295 if ((dn = bsd_malloc(nodesize, NULL, NULL)) == NULL) {
296 writeErrnoValue(MiamiBase->_SocketBase, ENOMEM);
297 return 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);
310 return 0;
312 AROS_LIBFUNC_EXIT
315 AROS_LH0(struct hostent *, Miami_gethostent,
316 struct MiamiBase *, MiamiBase, 10, Miami)
318 AROS_LIBFUNC_INIT
320 #if defined(__AROS__)
321 D(bug("[AROSTCP.MIAMI] amiga_ndbent.c: Miami_gethostent()\n"));
322 #endif
324 return gethtent(MiamiBase->_SocketBase);
326 AROS_LIBFUNC_EXIT
330 AROS_LH0(void, Miami_endhostent,
331 struct MiamiBase *, MiamiBase, 12, Miami)
333 AROS_LIBFUNC_INIT
335 #if defined(__AROS__)
336 D(bug("[AROSTCP.MIAMI] amiga_ndbent.c: Miami_endhostent()\n"));
337 #endif
339 endhostent(MiamiBase->_SocketBase);
341 AROS_LIBFUNC_EXIT