home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume15 / atos / part01 next >
Encoding:
Text File  |  1990-12-16  |  22.4 KB  |  664 lines

  1. Newsgroups: comp.sources.misc
  2. X-UNIX-From: jude@orville.nas.nasa.gov
  3. subject: v15i097: ATOS - Application-level Type Of Service routing
  4. from: Jude A. George <jude@orville.nas.nasa.gov>
  5. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  6.  
  7. Posting-number: Volume 15, Issue 97
  8. Submitted-by: Jude A. George <jude@orville.nas.nasa.gov>
  9. Archive-name: atos/part01
  10.  
  11. [Hey Phil, when will this show up in NOS?  ;-)  ++bsa]
  12.  
  13. ATOS --  Application-Level Type-of-Service Routing
  14.  
  15. v0.95 October 5, 1990
  16.  
  17. ATOS is a small bit of code that provides network applications with a way
  18. to choose the best network path to a destination when multiple paths are
  19. available.  For example, when two hosts share both an Ethernet and an
  20. UltraNet, they want to route all of their ftp traffic through their UltraNet
  21. interfaces and all of their telnets and rlogins through the Ethernet.
  22. The higher-bandwidth network is better suited for ftp's large-packet
  23. data transfers than for telnet/rlogin "tinygrams".  The proper interface
  24. must be chosen by the application.  A name server ordinarily returns all of
  25. the network addresses for a host, but in no particular order.  Thus the
  26. calling code cannot normally make an intelligent choice of address.  Until
  27. true type-of-service routing is handled by IP and the routing hardware,
  28. we have to solve this problem at a higher layer.
  29.  
  30. The software does require a resolver that has the capability of returning
  31. multiple (all available) network addresses in the hostent data structure.
  32. If you use YP or a host table, as opposed to a name server, and can map only
  33. one IP address to a hostname, ATOS will not help you. 
  34.  
  35. You should have the following files:
  36.  
  37. atos/
  38.   README
  39.   makefile
  40.   man3/
  41.     atos.3n
  42.     sortaddrbytos.3n
  43.     tosroutes.3n
  44.   netinet/
  45.     atos.c
  46.     atos.h
  47.   test.c
  48.   tosroutes
  49.  
  50. The makefile requires this directory structure to build the test program.
  51.  
  52. To use ATOS, compile the source into any C code that makes a call to the
  53. resolver.  After a gethostbyname() or similar call, call sortaddrbytos()
  54. with a pointer to the hostent structure and a TOS code.  This function will
  55. sort the h_addr_list IP addresses in order of descending preference, with
  56. the "best" address at the top.  The sorting is done under the assumption
  57. that the calling code will choose its addresses from the top of the list,
  58. moving downwards.  An /etc/tosroutes file must also be present, which tells
  59. the sorting routine how to compare the available networks against the TOS
  60. codes.  The codes and the format of this file are explained in the man page.
  61. The example file included with this distribution will not work for your
  62. network.
  63.  
  64. To get the maximum benefit from ATOS, incorporate it into heavily used
  65. network software such as ftp and telnet, on hosts that are homed on multiple
  66. networks.  Use a tos code of "T" for ftp, and "D" for telnet.  This will
  67. maximize throughput on the one, and minimize delay on the other.  Caveat:
  68. ftp uses the same port for its control connection and its data connection.
  69. All frequently-used network/tos combinations should be listed in the
  70. /etc/tosroutes file.
  71.  
  72. ATOS has been tested on a VAX 11/780 running BSD 4.3 UNIX, a Cray Y-MP
  73. running UNICOS 5.1.10, a Sun 3/260 and Sun 4/65 running SunOS 4.0.3, and
  74. a Silicon Graphics Iris 4D/320 running IRIX 3.3.  The software is provided
  75. "as is"; use at your own risk.  It is by no means production code, from
  76. any organization.  Neither I, nor any organization I am affiliated with,
  77. assume any resonsibility for its use or misuse.  It is very simple in design,
  78. but because of its nature (it destructively modifies data structures in
  79. the calling code) any usage should be tested extensively.  'Nuff said.
  80.  
  81. ATOS may be freely modified, distributed, and used; all I ask is that it
  82. be distributed with its documentation.  I would like to hear from anyone who
  83. tries it out.  If you've come up with improvements for the sorting routine
  84. or the format of the tosroutes file, I would be happy to incorporate them,
  85. so others may benefit.  I didn't spend much time on this.
  86.  
  87. Many thanks go to John Lekashman and David Ianucci of NASA Ames for their
  88. input.
  89.  
  90. Jude George
  91.  
  92. NAS Program, M/S 258-6
  93. NASA Ames Research Center
  94. Moffett Field, CA 94086
  95.  
  96. jude@nas.nasa.gov
  97.  
  98. -----------------------------------
  99. #! /bin/sh
  100. # This is a shell archive, meaning:
  101. # 1. Remove everything above the #! /bin/sh line.
  102. # 2. Save the resulting text in a file.
  103. # 3. Execute the file with /bin/sh (not csh) to create:
  104. #    atos
  105. # This archive created: Mon Oct 22 11:32:04 1990
  106. export PATH; PATH=/bin:/usr/bin:$PATH
  107. if test ! -d 'atos'
  108. then
  109.     mkdir 'atos'
  110. fi
  111. cd 'atos'
  112. if test -f 'README'
  113. then
  114.     echo shar: "will not over-write existing file 'README'"
  115. else
  116. sed 's/^X//' << \SHAR_EOF > 'README'
  117. XATOS --  Application-Level Type-of-Service Routing
  118. X
  119. Xv0.95 October 5, 1990
  120. X
  121. XATOS is a small bit of code that provides network applications with a way
  122. Xto choose the best network path to a destination when multiple paths are
  123. Xavailable.  For example, when two hosts share both an Ethernet and an
  124. XUltraNet, they want to route all of their ftp traffic through their UltraNet
  125. Xinterfaces and all of their telnets and rlogins through the Ethernet.
  126. XThe higher-bandwidth network is better suited for ftp's large-packet
  127. Xdata transfers than for telnet/rlogin "tinygrams".  The proper interface
  128. Xmust be chosen by the application.  A name server ordinarily returns all of
  129. Xthe network addresses for a host, but in no particular order.  Thus the
  130. Xcalling code cannot normally make an intelligent choice of address.  Until
  131. Xtrue type-of-service routing is handled by IP and the routing hardware,
  132. Xwe have to solve this problem at a higher layer.
  133. X
  134. XThe software does require a resolver that has the capability of returning
  135. Xmultiple (all available) network addresses in the hostent data structure.
  136. XIf you use YP or a host table, as opposed to a name server, and can map only
  137. Xone IP address to a hostname, ATOS will not help you. 
  138. X
  139. XYou should have the following files:
  140. X
  141. Xatos/
  142. X  README
  143. X  makefile
  144. X  man3/
  145. X    atos.3n
  146. X    sortaddrbytos.3n
  147. X    tosroutes.3n
  148. X  netinet/
  149. X    atos.c
  150. X    atos.h
  151. X  test.c
  152. X  tosroutes
  153. X
  154. XThe makefile requires this directory structure to build the test program.
  155. X
  156. XTo use ATOS, compile the source into any C code that makes a call to the
  157. Xresolver.  After a gethostbyname() or similar call, call sortaddrbytos()
  158. Xwith a pointer to the hostent structure and a TOS code.  This function will
  159. Xsort the h_addr_list IP addresses in order of descending preference, with
  160. Xthe "best" address at the top.  The sorting is done under the assumption
  161. Xthat the calling code will choose its addresses from the top of the list,
  162. Xmoving downwards.  An /etc/tosroutes file must also be present, which tells
  163. Xthe sorting routine how to compare the available networks against the TOS
  164. Xcodes.  The codes and the format of this file are explained in the man page.
  165. XThe example file included with this distribution will not work for your
  166. Xnetwork.
  167. X
  168. XTo get the maximum benefit from ATOS, incorporate it into heavily used
  169. Xnetwork software such as ftp and telnet, on hosts that are homed on multiple
  170. Xnetworks.  Use a tos code of "T" for ftp, and "D" for telnet.  This will
  171. Xmaximize throughput on the one, and minimize delay on the other.  Caveat:
  172. Xftp uses the same port for its control connection and its data connection.
  173. XAll frequently-used network/tos combinations should be listed in the
  174. X/etc/tosroutes file.
  175. X
  176. XATOS has been tested on a VAX 11/780 running BSD 4.3 UNIX, a Cray Y-MP
  177. Xrunning UNICOS 5.1.10, a Sun 3/260 and Sun 4/65 running SunOS 4.0.3, and
  178. Xa Silicon Graphics Iris 4D/320 running IRIX 3.3.  The software is provided
  179. X"as is"; use at your own risk.  It is by no means production code, from
  180. Xany organization.  Neither I, nor any organization I am affiliated with,
  181. Xassume any resonsibility for its use or misuse.  It is very simple in design,
  182. Xbut because of its nature (it destructively modifies data structures in
  183. Xthe calling code) any usage should be tested extensively.  'Nuff said.
  184. X
  185. XATOS may be freely modified, distributed, and used; all I ask is that it
  186. Xbe distributed with its documentation.  I would like to hear from anyone who
  187. Xtries it out.  If you've come up with improvements for the sorting routine
  188. Xor the format of the tosroutes file, I would be happy to incorporate them,
  189. Xso others may benefit.  I didn't spend much time on this.
  190. X
  191. XMany thanks go to John Lekashman and David Ianucci of NASA Ames for their
  192. Xinput.
  193. X
  194. XJude George
  195. X
  196. XNAS Program, M/S 258-6
  197. XNASA Ames Research Center
  198. XMoffett Field, CA 94086
  199. X
  200. Xjude@nas.nasa.gov
  201. SHAR_EOF
  202. fi
  203. if test ! -d 'netinet'
  204. then
  205.     mkdir 'netinet'
  206. fi
  207. cd 'netinet'
  208. if test -f 'atos.h'
  209. then
  210.     echo shar: "will not over-write existing file 'atos.h'"
  211. else
  212. sed 's/^X//' << \SHAR_EOF > 'atos.h'
  213. X/*\
  214. X *    ATOS -- Application-Level Type-of-Service Routing
  215. X *
  216. X *    FILE: atos.h
  217. X *
  218. X *    v0.95, 5 October 1990
  219. X *
  220. X *    sortaddrbytos() takes a host entry (struct hostent *) and a tos
  221. X *    (type of service) code, and rearranges the h_addr_list in the
  222. X *    host entry in order of preference for that particular tos.
  223. X *    This is an attempt to solve the problem of routing by tos above
  224. X *    the ip layer, when multiple physical network paths to the
  225. X *    destination host are available.
  226. X *
  227. X *    The function relies on the existence of a file /etc/tosroutes
  228. X *    with each line consisting of three fields: tos, addr, pref.
  229. X *    The tos field is a single character indicating the network
  230. X *    requirements of the calling code: "D" for low delay, "T" for
  231. X *    high throughput, or "R" for high reliability.  Multiple
  232. X *    requirements (low delay AND high throughput) may not be entered.
  233. X *    The addr field is either a network #, subnet #, or full IP #,
  234. X *    and specifies a possible destination.  Typically, only subnet
  235. X *    #'s are useful.  The pref field is a number from 0 to 9 indicating
  236. X *    that tos' preference for that network address, 0 being the most
  237. X *    preferred addr for that tos.
  238. X *
  239. X *    There should be an entry for every local network or subnet,
  240. X *    as a net/subnet that the function does not recognize will always
  241. X *    be sorted down to the bottom of the list.
  242. X *    sortaddrbytos() returns 0, or -1 if there was an error.
  243. X *
  244. X *    Copyright (c) 1990 Jude A. George (jude@nas.nasa.gov)
  245. X *    This code may be freely distributed.  It is believed to be
  246. X *    useful and bug-free, but comes with no warranty whatsoever,
  247. X *    from any party.  It is not production code.
  248. X\*/
  249. X
  250. X#define    ADDRSIZE    16
  251. X#define    STRSIZE        16
  252. X#define    TOSFILE        "/etc/tosroutes"
  253. X#define    ALT_TOSFILE    "./tosroutes"
  254. Xint sortaddrbytos();
  255. SHAR_EOF
  256. fi
  257. if test -f 'atos.c'
  258. then
  259.     echo shar: "will not over-write existing file 'atos.c'"
  260. else
  261. sed 's/^X//' << \SHAR_EOF > 'atos.c'
  262. X/*\
  263. X *    ATOS -- Application-Level Type-of-Service Routing
  264. X *
  265. X *    FILE: atos.c
  266. X *
  267. X *    v0.95, 5 October 1990
  268. X *
  269. X *    sortaddrbytos() takes a host entry (struct hostent *) and a tos
  270. X *    (type of service) code, and rearranges the h_addr_list in the
  271. X *    host entry in order of preference for that particular tos.
  272. X *    This is an attempt to solve the problem of routing by tos above
  273. X *    the ip layer, when multiple physical network paths to the
  274. X *    destination host are available.
  275. X *
  276. X *    The function relies on the existence of a file /etc/tosroutes
  277. X *    with each line consisting of three fields: tos, addr, pref.
  278. X *    The tos field is a single character indicating the network
  279. X *    requirements of the calling code: "D" for low delay, "T" for
  280. X *    high throughput, or "R" for high reliability.  Multiple
  281. X *    requirements (low delay AND high throughput) may not be entered.
  282. X *    The addr field is either a network #, subnet #, or full IP #,
  283. X *    and specifies a possible destination.  Typically, only subnet
  284. X *    #'s are useful.  The pref field is a number from 0 to 9 indicating
  285. X *    that tos' preference for that network address, 0 being the most
  286. X *    preferred addr for that tos.
  287. X *
  288. X *    There should be an entry for every local network or subnet,
  289. X *    as a net/subnet that the function does not recognize will always
  290. X *    be sorted down to the bottom of the list.
  291. X *    sortaddrbytos() returns 0, or -1 if there was an error.
  292. X *
  293. X *    Copyright (c) 1990 Jude A. George (jude@nas.nasa.gov)
  294. X *    This code may be freely distributed.  It is believed to be
  295. X *    useful and bug-free, but comes with no warranty whatsoever,
  296. X *    from any party.  It is not production code.
  297. X\*/
  298. X
  299. X#include <stdio.h>
  300. X#include <netdb.h>
  301. X
  302. X#include <netinet/atos.h>
  303. X
  304. Xstruct tos_ent {
  305. X    struct tos_ent *next;
  306. X    char addr[ADDRSIZE];
  307. X    char tos[STRSIZE];
  308. X    int pref;
  309. X};
  310. X
  311. X/*\
  312. X * Insert an entry into the tos list, sorted by pref.  Low pref value,
  313. X * i.e. more preferred entries, will be placed closer to the head of
  314. X * the list.
  315. X\*/
  316. Xtos_insert(entry,list_ptr)
  317. Xstruct tos_ent *entry;
  318. Xstruct tos_ent **list_ptr;
  319. X{
  320. X    struct tos_ent *cur_ent, *prev_ent;
  321. X
  322. X    if (*list_ptr == NULL) {
  323. X    *list_ptr = entry;
  324. X    return;
  325. X    }
  326. X    prev_ent = NULL;
  327. X    cur_ent = *list_ptr;
  328. X    while(cur_ent != NULL) {
  329. X    if (entry->pref <= cur_ent->pref) {
  330. X        entry->next = cur_ent;
  331. X        if (prev_ent == NULL)
  332. X        *list_ptr = entry;
  333. X        else
  334. X        prev_ent->next = entry;
  335. X        break;
  336. X    }
  337. X    prev_ent = cur_ent;
  338. X    cur_ent = cur_ent->next;
  339. X    }
  340. X}
  341. X
  342. X/*\
  343. X * Sort host_entry->h_addr_list based on tos and the tos file.  Note that
  344. X * a network or subnet entry in the tos file can match a full IP address
  345. X * from the h_addr_list.  (e.g. 129.99 matches 129.99.23.20).
  346. X\*/
  347. Xint sortaddrbytos(host_entry, tos)
  348. Xstruct hostent *host_entry;
  349. Xchar  *tos;
  350. X{
  351. X    struct tos_ent *tos_list, *cur_ent;
  352. X    unsigned char **cur_addr, **cur_addr_top;
  353. X    unsigned char *temp;
  354. X    char addrbuf[ADDRSIZE];
  355. X    int numents = 0;
  356. X    int rval = 1;
  357. X    int i;
  358. X    FILE *fp;
  359. X
  360. X    /*
  361. X     * If host entry is NULL, return with an error.
  362. X     */
  363. X    if (host_entry == NULL)
  364. X    return -1;
  365. X
  366. X    /*
  367. X     * Open the tos file for reading; if file doesn't exist, search for
  368. X     * an alternate.  If still not found, return with an error but don't
  369. X     * change the addr_list.
  370. X     */
  371. X    fp = fopen(TOSFILE,"r");
  372. X    if (fp == NULL) {
  373. X    fp = fopen(ALT_TOSFILE,"r");
  374. X    if (fp == NULL)
  375. X        return -1;
  376. X    }
  377. X
  378. X    /*
  379. X     * Read all tos file entries that have our tos code, and make a list,
  380. X     * sorting in order of pref.
  381. X     */
  382. X    tos_list = NULL;
  383. X    while(rval != EOF) {
  384. X    cur_ent = (struct tos_ent *)malloc(sizeof(struct tos_ent));
  385. X    cur_ent->pref = -1;
  386. X    cur_ent->next = NULL;
  387. X    bzero(cur_ent->addr, ADDRSIZE);
  388. X    bzero(cur_ent->tos, STRSIZE);
  389. X    rval = fscanf(fp, "%s %s %d", cur_ent->tos, cur_ent->addr,
  390. X              &cur_ent->pref);
  391. X    if (!strcmp(cur_ent->tos, tos))
  392. X        tos_insert(cur_ent, &tos_list);
  393. X    }
  394. X    fclose(fp);
  395. X
  396. X    /*
  397. X     * Sort the h_addr_list in order of "preference", using the sorted
  398. X     * tos_list as a guide.  Go down the tos_list; for each entry, look
  399. X     * through the h_addr_list from cur_addr_top downwards; if a match
  400. X     * is found in the h_addr_list, swap that match with the cur_addr_top
  401. X     * of the h_addr_list and lower the cur_addr_top by one.  Keep looking
  402. X     * down the list in case there are multiple matches.  Cur_addr_top is
  403. X     * initially at the head of the h_addr_list.  Note: the string
  404. X     * comparison is performed only up to the length of the tos file's addr
  405. X     * entry, to allow a network or subnet id to match a host's ip address.
  406. X     */
  407. X    cur_addr_top = (unsigned char **)host_entry->h_addr_list;
  408. X    for (cur_ent = tos_list; cur_ent != NULL; cur_ent = cur_ent->next)
  409. X    for (cur_addr = cur_addr_top; *cur_addr != 0; cur_addr++) {
  410. X        bzero(addrbuf, ADDRSIZE);
  411. X        sprintf(addrbuf, "%u.%u.%u.%u", (*cur_addr)[0], (*cur_addr)[1],
  412. X            (*cur_addr)[2], (*cur_addr)[3]);
  413. X        if (!strncmp(addrbuf, cur_ent->addr, strlen(cur_ent->addr))) {
  414. X        temp = *cur_addr_top;
  415. X        *cur_addr_top++ = *cur_addr;
  416. X        *cur_addr = temp;
  417. X        }
  418. X    }
  419. X    return 0;
  420. X}
  421. SHAR_EOF
  422. fi
  423. cd ..
  424. if test -f 'test.c'
  425. then
  426.     echo shar: "will not over-write existing file 'test.c'"
  427. else
  428. sed 's/^X//' << \SHAR_EOF > 'test.c'
  429. X/*\
  430. X *    FILE: test.c
  431. X *
  432. X *    Test function for sortaddrbytos().
  433. X\*/
  434. X
  435. X#include <stdio.h>
  436. X#include <netdb.h>
  437. X
  438. X#include <netinet/atos.h>
  439. X
  440. Xmain(argc,argv)
  441. Xint argc;
  442. Xchar **argv;
  443. X{
  444. X    struct hostent *test_host;
  445. X    unsigned char **addr_list, **i, byte1, byte2, byte3, byte4;
  446. X    int int1, int2, int3, int4;
  447. X
  448. X    if (argc != 3) {
  449. X    printf("Usage:  %s hostname tos\n", argv[0]);
  450. X    exit(0);
  451. X    }
  452. X
  453. X    test_host = gethostbyname(argv[1]);
  454. X
  455. X    if (test_host == NULL) {
  456. X    printf("Bad host name.\n");
  457. X    exit(-1);
  458. X    }
  459. X
  460. X    addr_list = (unsigned char **)test_host->h_addr_list;
  461. X
  462. X    printf("\nOriginal address list for %s:\n\n", test_host->h_name);
  463. X    for(i = addr_list; *i != 0; i++)
  464. X    printf("address: %u.%u.%u.%u\n",(*i)[0],(*i)[1],(*i)[2],(*i)[3]);
  465. X
  466. X    sortaddrbytos(test_host, argv[2]);
  467. X
  468. X    printf("\nSorted address list for %s:\n\n", test_host->h_name);
  469. X    for(i = addr_list; *i != 0; i++)
  470. X    printf("address: %u.%u.%u.%u\n",(*i)[0],(*i)[1],(*i)[2],(*i)[3]);
  471. X}
  472. SHAR_EOF
  473. fi
  474. if test -f 'makefile'
  475. then
  476.     echo shar: "will not over-write existing file 'makefile'"
  477. else
  478. sed 's/^X//' << \SHAR_EOF > 'makefile'
  479. X#
  480. X#    Makefile for sortaddrbytos() test.  If you do not have a system
  481. X#    similar to BSD 4.3, you may have to modify the CFLAGS to include
  482. X#    additional libraries, or change the #include paths.  This makefile
  483. X#    should work, unchanged, on the following systems:  BSD 4.3,
  484. X#    IRIX 3.3, SunOS 4.0.3.  For UNICOS, add -lbsd -lnet.
  485. X#
  486. X#    The install option will install the ATOS source files and man
  487. X#    page in the appropriate directories, if you have write-access.
  488. X#    I will not presume to guess which protection bits you use.
  489. X#
  490. X
  491. XSRCDIR=        /usr/include/netinet
  492. XINCLDIR=    /usr/include/netinet
  493. XMANDIR=        /usr/man/man3
  494. X
  495. XMAN=        man3/atos.3n man3/tosroutes.3n man3/sortaddrbytos.3n
  496. X
  497. XCFLAGS=        -O -I.
  498. X
  499. Xtest:        netinet/atos.h netinet/atos.c test.c
  500. X        cc ${CFLAGS} netinet/atos.c test.c -o test
  501. X
  502. Xinstall:    netinet/atos.h netinet/atos.c ${MAN}
  503. X        cp netinet/atos.c ${SRCDIR}
  504. X        cp netinet/atos.h ${INCLDIR}
  505. X        cp ${MAN} ${MANDIR}
  506. X
  507. Xclean:        
  508. X        rm -f atos.o test.o
  509. X
  510. Xspotless:    
  511. X        rm -f atos.o test.o test
  512. SHAR_EOF
  513. fi
  514. if test -f 'tosroutes'
  515. then
  516.     echo shar: "will not over-write existing file 'tosroutes'"
  517. else
  518. sed 's/^X//' << \SHAR_EOF > 'tosroutes'
  519. XT    129.99.23    5
  520. XT    129.99.32    5
  521. XT    129.99.64    5
  522. XT    129.99.48    5
  523. XT    129.99.196    2
  524. XD    129.99.23    3
  525. XD    129.99.196    4
  526. XD    129.99.32    4
  527. XD    129.99.48    4
  528. XD    129.99.64    4
  529. XD    128.102        7
  530. XT    128.102        7
  531. SHAR_EOF
  532. fi
  533. if test ! -d 'man3'
  534. then
  535.     mkdir 'man3'
  536. fi
  537. cd 'man3'
  538. if test -f 'sortaddrbytos.3n'
  539. then
  540.     echo shar: "will not over-write existing file 'sortaddrbytos.3n'"
  541. else
  542. sed 's/^X//' << \SHAR_EOF > 'sortaddrbytos.3n'
  543. X.\" @(#)sortaddrbytos.3n 0.95 90/10/05;
  544. X.TH SORTADDRBYTOS 3N "5 October 1990"
  545. X.SH NAME
  546. Xsortaddrbytos \- sort host addresses by type of service and preferred
  547. Xnetwork
  548. X.SH SYNOPSIS
  549. X.nf
  550. X.ft B
  551. X#include <stdio.h>
  552. X#include <netdb.h>
  553. X#include <tosroute.h>
  554. X.LP
  555. X.ft B
  556. Xint sortaddrbytos(host_entry, tos)
  557. Xstruct hostent *host_entry;
  558. Xchar *tos;
  559. X.ft R
  560. X.fi
  561. X.IX  "tosroutes file"  ""  "\fLtosroutes\fP \(em network preference codes"
  562. X.SH DESCRIPTION
  563. X.BR sortaddrbytos()
  564. Xtakes a host entry and an internet-standard tos (type of service) code
  565. Xand rearranges the h_addr_list in the host entry in order of preference
  566. Xfor that particular tos.  This is an attempt to solve the problem of routing
  567. Xby tos above the ip layer, when multiple phisical network paths to the
  568. Xdestination host are available.  A name server ordinarily returns all of
  569. Xthe network addresses for a host, but in no particular order.  Thus
  570. Xthe calling code cannot normally make an intelligent choice of address.
  571. X.BR sortaddrbytos()
  572. Xshould be called immediately after
  573. X.BR gethostent(),
  574. X.BR gethostbyname(),
  575. Xor
  576. X.BR gethostbyaddr()
  577. Xin the application program.
  578. X.LP
  579. XThe function relies on the existence of a
  580. Xfile /etc/tosroutes with each line consisting of three fields: tos, addr,
  581. Xand pref.  
  582. XThe tos field is a single character indicating the
  583. Xnetwork requirements of the calling code: "D" for low delay,
  584. X"T" for high throughput, or "R" for high reliability.  Multiple
  585. Xrequirements (low delay AND high throughput) may not be entered.
  586. XThe addr field is either a network id, subnet id, or full IP address,
  587. Xand specifies a possible destination.  Typically, only subnet ids are
  588. Xuseful.  The pref field is a number from 0 to 9 indicating that tos'
  589. Xpreference for that network address, 0 being the most preferred addr
  590. Xfor that tos.  Fields may be separated by tabs or spaces.  
  591. X.LP
  592. XThere should be an entry for every local subnet, as a net/subnet that the
  593. Xfunction does not recognize will always be sorted to the bottom of the
  594. Xlist.  Of course, hosts connected to different subnets will have slightly
  595. Xdifferent entries in their tosroutes files.
  596. X.SH EXAMPLE
  597. X.LP
  598. XHere is portion of an example /etc/tosroutes file for a host that can reach
  599. Xfour networks; 191.255.1 is a low-throughput Ethernet, 191.255.2 is a
  600. Xmedium-throughput FDDI ring, 191.255.3 is a high-throughput UltraNet, and
  601. X191.255.10 is a low-throughput, high-delay satellite link.  In addition,
  602. X191.255.5 is another Ethernet that is an extra hop away, and hence may
  603. Xexperience slightly higher delay than the first Ethernet.
  604. X.LP
  605. X    T       191.255.1       5
  606. X    T       191.255.2       2
  607. X    T       191.255.3       0
  608. X    T       191.255.10      9
  609. X    T       191.255.5       5
  610. X    D       191.255.1       2
  611. X    D       191.255.2       2
  612. X    D       191.255.3       2
  613. X    D       191.255.10      9
  614. X    D       191.255.5       3
  615. X.LP
  616. XA program that wants the best path for high-throughput traffic (e.g. ftp)
  617. Xwould call sortaddrbytos() with "T" as the tos code.  If the destination
  618. Xhost has interfaces 191.255.1.50, 191.255.2, and 191.255.3, the sorting
  619. Xalgorithm will return them in the order 191.255.3, 191.255.2, 191.255.1.
  620. X.SH FILES
  621. X/etc/tosroutes
  622. X.LP
  623. XIf tosroutes is not found in /etc, the current working directory of the
  624. Xcalling code will be searched.
  625. X.SH SEE ALSO
  626. Xgethostent(3N), services(5)
  627. X.SH BUGS
  628. XA name server should be used instead of a static file.  Ideally, this
  629. Xfunction should be integrated into
  630. X.BR gethostent()
  631. Xand the resolver library.
  632. X.LP
  633. XThe function is not very forgiving of errors in the tosroutes file.
  634. X
  635. XThe function uses fscanf() and sprintf().
  636. X
  637. X.SH AUTHOR
  638. XJude Anand George (jude@nas.nasa.gov)
  639. SHAR_EOF
  640. fi
  641. if test -f 'tosroutes.3n'
  642. then
  643.     echo shar: "will not over-write existing file 'tosroutes.3n'"
  644. else
  645. sed 's/^X//' << \SHAR_EOF > 'tosroutes.3n'
  646. X.so man3/sortaddrbytos.3n
  647. X.\" @(#)tosroutes.3n 0.95 90/10/05;
  648. SHAR_EOF
  649. fi
  650. if test -f 'atos.3n'
  651. then
  652.     echo shar: "will not over-write existing file 'atos.3n'"
  653. else
  654. sed 's/^X//' << \SHAR_EOF > 'atos.3n'
  655. X.so man3/sortaddrbytos.3n
  656. X.\" @(#)atos.3n 0.95 90/10/05;
  657. SHAR_EOF
  658. fi
  659. cd ..
  660. cd ..
  661. exit 0
  662. #    End of shell archive
  663.  
  664.