1
0

netent.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. /*++
  2. Copyright (c) 2013 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. netent.c
  9. Abstract:
  10. This module implements support for network, protocol, and service name
  11. resolution.
  12. Author:
  13. Evan Green 8-Jan-2014
  14. Environment:
  15. User Mode C Library
  16. --*/
  17. //
  18. // ------------------------------------------------------------------- Includes
  19. //
  20. #include "libcp.h"
  21. #include <netdb.h>
  22. //
  23. // ---------------------------------------------------------------- Definitions
  24. //
  25. //
  26. // ------------------------------------------------------ Data Type Definitions
  27. //
  28. //
  29. // ----------------------------------------------- Internal Function Prototypes
  30. //
  31. //
  32. // -------------------------------------------------------------------- Globals
  33. //
  34. //
  35. // Define the error variable set by the gethostbyaddr and gethostbyname
  36. // functions.
  37. //
  38. LIBC_API __THREAD int h_errno;
  39. //
  40. // ------------------------------------------------------------------ Functions
  41. //
  42. LIBC_API
  43. struct hostent *
  44. gethostbyaddr (
  45. const void *Address,
  46. socklen_t Length,
  47. int FamilyType
  48. )
  49. /*++
  50. Routine Description:
  51. This routine returns a host entry containing addresses of the given family
  52. type. This function is neither thread safe nor reentrant.
  53. Arguments:
  54. Address - Supplies a pointer to the address (whose type depends on the
  55. family type parameter).
  56. Length - Supplies the length of the address buffer.
  57. FamilyType - Supplies the family type of the address to return.
  58. Return Value:
  59. Returns a pointer to the host information. This buffer may be overwritten
  60. by subsequent calls to this routine.
  61. NULL on failure, and h_errno will be set to contain more information.
  62. Common values for h_errno are:
  63. HOST_NOT_FOUND if no such host is known.
  64. NO_DATA if the server recognized the request and the name, but no address
  65. is available.
  66. NO_RECOVERY if an unexpected server failure occurred.
  67. TRY_AGAIN if a temporary and possibly transient error occurred, such as a
  68. failure of the server to responsd.
  69. --*/
  70. {
  71. //
  72. // TODO: Implement gethostbyaddr.
  73. //
  74. h_errno = NO_RECOVERY;
  75. return NULL;
  76. }
  77. LIBC_API
  78. struct hostent *
  79. gethostbyname (
  80. const char *Name
  81. )
  82. /*++
  83. Routine Description:
  84. This routine returns a host entry containing addresses of family AF_INET
  85. for the host with the given name. This function is neither thread safe nor
  86. reentrant.
  87. Arguments:
  88. Name - Supplies a pointer to a null terminated string containing the name
  89. of the node.
  90. Return Value:
  91. Returns a pointer to the host information. This buffer may be overwritten
  92. by subsequent calls to this routine.
  93. NULL on failure, and h_errno will be set to contain more information.
  94. Common values for h_errno are:
  95. HOST_NOT_FOUND if no such host is known.
  96. NO_DATA if the server recognized the request and the name, but no address
  97. is available.
  98. NO_RECOVERY if an unexpected server failure occurred.
  99. TRY_AGAIN if a temporary and possibly transient error occurred, such as a
  100. failure of the server to responsd.
  101. --*/
  102. {
  103. //
  104. // TODO: Implement gethostbyname.
  105. //
  106. h_errno = NO_RECOVERY;
  107. return NULL;
  108. }
  109. LIBC_API
  110. void
  111. sethostent (
  112. int StayOpen
  113. )
  114. /*++
  115. Routine Description:
  116. This routine opens a connection to the host database and sets the next
  117. entry for retrieval to the first entry in the database. This routine is
  118. neither reentrant nor thread safe.
  119. Arguments:
  120. StayOpen - Supplies a value that if non-zero indicates that the connection
  121. shall not be closed by a call to gethostent, gethostbyname or
  122. gethostbyaddr, and the implementation may maintain an open file
  123. descriptor.
  124. Return Value:
  125. None.
  126. --*/
  127. {
  128. //
  129. // TODO: Implement sethostent.
  130. //
  131. return;
  132. }
  133. LIBC_API
  134. struct hostent *
  135. gethostent (
  136. void
  137. )
  138. /*++
  139. Routine Description:
  140. This routine reads the next entry in the host database. This routine is
  141. neither thread safe nor reentrant.
  142. Arguments:
  143. None.
  144. Return Value:
  145. Returns a pointer to the next entry in the host database. This buffer may
  146. be overwritten by subsequent calls to this routine, gethostbyname, or
  147. gethostbyaddr.
  148. --*/
  149. {
  150. //
  151. // TODO: Implement gethostent.
  152. //
  153. return NULL;
  154. }
  155. LIBC_API
  156. void
  157. endhostent (
  158. void
  159. )
  160. /*++
  161. Routine Description:
  162. This routine closes any open database connection established by the
  163. sethostent routine.
  164. Arguments:
  165. None.
  166. Return Value:
  167. None.
  168. --*/
  169. {
  170. //
  171. // TODO: Implement endhostent.
  172. //
  173. return;
  174. }
  175. LIBC_API
  176. void
  177. setnetent (
  178. int StayOpen
  179. )
  180. /*++
  181. Routine Description:
  182. This routine opens a connection to the network database and sets the next
  183. entry for retrieval to the first entry in the database. This routine is
  184. neither reentrant nor thread safe.
  185. Arguments:
  186. StayOpen - Supplies a value that if non-zero indicates that the
  187. implementation may maintain an open file descriptor to the network
  188. database.
  189. Return Value:
  190. None.
  191. --*/
  192. {
  193. //
  194. // TODO: Implement setnetent.
  195. //
  196. return;
  197. }
  198. LIBC_API
  199. struct netent *
  200. getnetent (
  201. void
  202. )
  203. /*++
  204. Routine Description:
  205. This routine reads the next entry in the network database. This routine is
  206. neither thread safe nor reentrant.
  207. Arguments:
  208. None.
  209. Return Value:
  210. Returns a pointer to the next entry in the network database. This buffer
  211. may be overwritten by subsequent calls to this routine, getnetbyaddr, or
  212. getnetbyname.
  213. --*/
  214. {
  215. //
  216. // TODO: Implement getnetent.
  217. //
  218. return NULL;
  219. }
  220. LIBC_API
  221. void
  222. endnetent (
  223. void
  224. )
  225. /*++
  226. Routine Description:
  227. This routine closes any open database connection established by the
  228. setnetent routine.
  229. Arguments:
  230. None.
  231. Return Value:
  232. None.
  233. --*/
  234. {
  235. //
  236. // TODO: Implement endnetent.
  237. //
  238. return;
  239. }
  240. LIBC_API
  241. struct netent *
  242. getnetbyaddr (
  243. uint32_t Network,
  244. int AddressFamily
  245. )
  246. /*++
  247. Routine Description:
  248. This routine searches the network database from the beginning and attempts
  249. to find the first entry matching the given address family (in
  250. netent.n_addrtype) and network number (in netent.n_net). This routine is
  251. neither thread safe nor reentrant.
  252. Arguments:
  253. Network - Supplies the network to match against.
  254. AddressFamily - Supplies the address type to match against.
  255. Return Value:
  256. Returns a pointer to a matching entry in the network database. This buffer
  257. may be overwritten by subsequent calls to this routine, getnetent, or
  258. getnetbyname.
  259. NULL on failure.
  260. --*/
  261. {
  262. //
  263. // TODO: Implement getnetbyaddr.
  264. //
  265. return NULL;
  266. }
  267. LIBC_API
  268. struct netent *
  269. getnetbyname (
  270. const char *Name
  271. )
  272. /*++
  273. Routine Description:
  274. This routine searches the network database from the beginning and attempts
  275. to find the first entry matching the given name (in netent.n_name). This
  276. routine is neither thread safe nor reentrant.
  277. Arguments:
  278. Name - Supplies a pointer to a string containing the name of the network to
  279. search for.
  280. Return Value:
  281. Returns a pointer to a matching entry in the network database. This buffer
  282. may be overwritten by subsequent calls to this routine, getnetent, or
  283. getnetbyaddr.
  284. NULL on failure.
  285. --*/
  286. {
  287. //
  288. // TODO: Implement getnetbyname.
  289. //
  290. return NULL;
  291. }
  292. LIBC_API
  293. void
  294. setprotoent (
  295. int StayOpen
  296. )
  297. /*++
  298. Routine Description:
  299. This routine opens a connection to the protocol database and sets the next
  300. entry for retrieval to the first entry in the database. This routine is
  301. neither reentrant nor thread safe.
  302. Arguments:
  303. StayOpen - Supplies a value that if non-zero indicates that the
  304. implementation may maintain an open file descriptor to the protocol
  305. database.
  306. Return Value:
  307. None.
  308. --*/
  309. {
  310. //
  311. // TODO: Implement setprotoent.
  312. //
  313. return;
  314. }
  315. LIBC_API
  316. struct protoent *
  317. getprotoent (
  318. void
  319. )
  320. /*++
  321. Routine Description:
  322. This routine reads the next entry in the protocol database. This routine is
  323. neither thread safe nor reentrant.
  324. Arguments:
  325. None.
  326. Return Value:
  327. Returns a pointer to the next entry in the protocol database. This buffer
  328. may be overwritten by subsequent calls to this routine, getprotobyname, or
  329. getnetbynumber.
  330. --*/
  331. {
  332. //
  333. // TODO: Implement getprotoent.
  334. //
  335. return NULL;
  336. }
  337. LIBC_API
  338. void
  339. endprotoent (
  340. void
  341. )
  342. /*++
  343. Routine Description:
  344. This routine closes any open database connection established by the
  345. setprotoent routine. This routine is neither thread safe nor reentrant.
  346. Arguments:
  347. None.
  348. Return Value:
  349. None.
  350. --*/
  351. {
  352. //
  353. // TODO: Implement endprotoent.
  354. //
  355. return;
  356. }
  357. LIBC_API
  358. struct protoent *
  359. getprotobynumber (
  360. int ProtocolNumber
  361. )
  362. /*++
  363. Routine Description:
  364. This routine searches the protocol database from the beginning and attempts
  365. to find the first entry matching the given protocol number. This routine is
  366. neither thread safe nor reentrant.
  367. Arguments:
  368. ProtocolNumber - Supplies the number of the protocol to find.
  369. Return Value:
  370. Returns a pointer to a matching entry in the protocol database. This buffer
  371. may be overwritten by subsequent calls to this routine, getprotoent, or
  372. getprotobyname.
  373. NULL on failure.
  374. --*/
  375. {
  376. //
  377. // TODO: Implement getprotobynumber.
  378. //
  379. return NULL;
  380. }
  381. LIBC_API
  382. struct protoent *
  383. getprotobyname (
  384. const char *Name
  385. )
  386. /*++
  387. Routine Description:
  388. This routine searches the protocol database from the beginning and attempts
  389. to find the first entry matching the given name. This routine is neither
  390. thread safe nor reentrant.
  391. Arguments:
  392. Name - Supplies a pointer to a string containing the name of the protocol
  393. to search for.
  394. Return Value:
  395. Returns a pointer to a matching entry in the protocol database. This buffer
  396. may be overwritten by subsequent calls to this routine, getprotoent, or
  397. getprotobynumber.
  398. NULL on failure.
  399. --*/
  400. {
  401. //
  402. // TODO: Implement getprotobyname.
  403. //
  404. return NULL;
  405. }
  406. LIBC_API
  407. void
  408. setservent (
  409. int StayOpen
  410. )
  411. /*++
  412. Routine Description:
  413. This routine opens a connection to the network service database and sets
  414. the next entry for retrieval to the first entry in the database. This
  415. routine is neither reentrant nor thread safe.
  416. Arguments:
  417. StayOpen - Supplies a value that if non-zero indicates that the
  418. implementation may maintain an open file descriptor to the protocol
  419. database.
  420. Return Value:
  421. None.
  422. --*/
  423. {
  424. //
  425. // TODO: Implement setservent.
  426. //
  427. return;
  428. }
  429. LIBC_API
  430. struct servent *
  431. getservent (
  432. void
  433. )
  434. /*++
  435. Routine Description:
  436. This routine reads the next entry in the network service database. This
  437. routine is neither thread safe nor reentrant.
  438. Arguments:
  439. None.
  440. Return Value:
  441. Returns a pointer to the next entry in the network service database. This
  442. buffer may be overwritten by subsequent calls to this routine,
  443. getservbyname, or getservbyport.
  444. --*/
  445. {
  446. //
  447. // TODO: Implement getservent.
  448. //
  449. return NULL;
  450. }
  451. LIBC_API
  452. void
  453. endservent (
  454. void
  455. )
  456. /*++
  457. Routine Description:
  458. This routine closes any open database connection established by the
  459. setservent routine. This routine is neither thread safe nor reentrant.
  460. Arguments:
  461. None.
  462. Return Value:
  463. None.
  464. --*/
  465. {
  466. //
  467. // TODO: Implement endservent.
  468. //
  469. return;
  470. }
  471. LIBC_API
  472. struct servent *
  473. getservbyport (
  474. int Port,
  475. const char *Protocol
  476. )
  477. /*++
  478. Routine Description:
  479. This routine searches the protocol database from the beginning and attempts
  480. to find the first entry where the given port matches the s_port member and
  481. the protocol name matches the s_proto member of the servent structure.
  482. Arguments:
  483. Port - Supplies the port number to match, in network byte order.
  484. Protocol - Supplies an optional pointer to a string containing the protocol
  485. to match. If this is null, any protocol will match.
  486. Return Value:
  487. Returns a pointer to a matching entry in the network service database. This
  488. buffer may be overwritten by subsequent calls to this routine, getservent,
  489. or getprotobyname.
  490. NULL on failure.
  491. --*/
  492. {
  493. //
  494. // TODO: Implement getservbyport.
  495. //
  496. return NULL;
  497. }
  498. LIBC_API
  499. struct servent *
  500. getservbyname (
  501. const char *Name,
  502. const char *Protocol
  503. )
  504. /*++
  505. Routine Description:
  506. This routine searches the network service database from the beginning and
  507. attempts to find the first entry where the given name matches the s_name
  508. member and the given protcol matches the s_proto member. This routine is
  509. neither thread safe nor reentrant.
  510. Arguments:
  511. Name - Supplies a pointer to a string containing the name of the service
  512. to search for.
  513. Protocol - Supplies an optional pointer to the string containing the
  514. protocol to match. If this is null, any protocol will match.
  515. Return Value:
  516. Returns a pointer to a matching entry in the network service database. This
  517. buffer may be overwritten by subsequent calls to this routine, getservent,
  518. or getservbyport.
  519. NULL on failure.
  520. --*/
  521. {
  522. //
  523. // TODO: Implement getservbyname.
  524. //
  525. return NULL;
  526. }
  527. //
  528. // --------------------------------------------------------- Internal Functions
  529. //