Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
(ARM).Porting TCP-IP programmer's guide.Ver 1.6.pdf
Скачиваний:
43
Добавлен:
23.08.2013
Размер:
2.64 Mб
Скачать

Miscellaneous Library Functions

9.1Description of misclib files

This section lists the files in misclib and gives an overview of their functions:

app_ping.c on page 9-2

in_utils.c on page 9-2

memman.c on page 9-2

menus.c, menulib.c, and nrmenus.c on page 9-3

nextcarg.c on page 9-3

nvparms.c on page 9-3

parseip.c on page 9-3

reshost.c on page 9-4

strilib.c on page 9-4

strlib.c on page 9-4

tcp_echo.c on page 9-4

timeouts.c on page 9-4

testmenu.c on page 9-5

ttyio.c on page 9-5

udp_echo.c on page 9-5

userpass.c on page 9-5.

9.1.1app_ping.c

The functions within the app_ping.c file implement an interface to the ping facilities available in the \inet directory for the menus subsystem.

9.1.2in_utils.c

This file contains an assortment of general utility functions. They are described in in_utils.c on page 9-6.

9.1.3memman.c

The ARM networking software uses the two functions npalloc() and npfree() to make dynamic memory allocations. In systems that include the standard C library, these can be mapped directly onto calloc() and free() using defined macros in the ipport.h file.

9-2

Copyright © 1998-2001 ARM Limited. All rights reserved.

ARM DUI 0144B

Miscellaneous Library Functions

If you are experiencing memory allocation problems and suspect that memory blocks are being referenced after they have been freed, or that data is being written beyond the end of the allocated area, you may be able to use the npalloc() and npfree() functions implemented in memman.c to help with debugging. If you are using these functions, you may also use the diagnostic function blocklist() which uses dprintf() to print a list of the memory blocks currently in use.

memman.c also contains a function, check_memory(), that you can call at any point in your code. It checks that all of the structures used by the dynamic memory allocation routines in memman.c are still intact and have not been accidentally overwritten.

Typically, you would place calls to check_memory() before and after a section of code that you suspect is corrupting the dynamic memory heap.

9.1.4menus.c, menulib.c, and nrmenus.c

These three files contain functions that implement a menu system that can be readily extended as new modules are added to a project. The menu system is intended to run with your application code, and allows you to exercise different areas of the network protocols. The menus can be accessed either by way of the standard input and output channels, or by way of a TELNET socket or other GenericIO channel.

9.1.5nextcarg.c

This file contains only one function, nextcarg(), that splits a comma-delimited string into its components. It is described in nextcarg.c on page 9-17.

9.1.6nvparms.c

The nvparms.c file contains a large number of routines used to read and parse a configuration file. This configuration file can either reside in nonvolatile Flash memory, or in a file on the native file system. If you choose to store files in flash memory, you must define INCLUDE_FLASHFS in your ipport.h file and provide suitable definitions to nv_ functions in nvfsio.h. If INCLUDE_FLASHFS has not been defined, the standard C library functions, such as fopen(), fgets(), and fclose(), are used.

9.1.7parseip.c

The parseip.c file implements only one function, parse_ipad(), used to parse a string containing a dotted-quad IP address (for example, 192.168.117.43) and return it as an ip_addr value. It is described in parseip.c on page 9-18.

ARM DUI 0144B

Copyright © 1998-2001 ARM Limited. All rights reserved.

9-3

Miscellaneous Library Functions

9.1.8reshost.c

The reshost.c file implements only one function, in_reshost(), used to resolve a host name into an IP address. It is described in reshost.c on page 9-19.

9.1.9strilib.c

There are three functions, stricmp(), strnicmp(), and stristr(), that are implemented in strilib.c. They each perform case-independent string comparisons. They behave just like strcmp(), strncmp(), and strstr(), taking the same arguments and returning the same results, with the exception that each character of each string is converted to lowercase before being compared. The strings passed to these functions are not modified.

9.1.10strlib.c

The strlib.c file contains implementations of the following standard C string functions:

strcat()

strchr()

strcmp()

strcpy()

strlen()

strncmp()

strncpy()

strstr().

If your C libraries do not include these functions, they may be included from the strlib.c file by defining the macro INICHE_LIBS in your ipport.h file, and configuring which particular functions you require in the in_utils.h file.

9.1.11tcp_echo.c

The functions within the tcp_echo.c file implement a menus interface to the TCP echo mechanism, which is useful for testing purposes.

9.1.12timeouts.c

This file contains a single function, inet_timer(), that should be called at least twice per second if you are using a superloop system. It is described in timeouts.c on

page 9-21.

9-4

Copyright © 1998-2001 ARM Limited. All rights reserved.

ARM DUI 0144B

Miscellaneous Library Functions

9.1.13testmenu.c

This file adds three commands to the diagnostic menus system to allow you to send a large number of ICMP ECHO requests or ARP requests to a target host. It is described in testmenu.c on page 9-23.

9.1.14ttyio.c

This file contains an implementation of the dprintf() function that can be used to send debug output by way of a UART driver. The dprintf() function supports the following formatting characters:

%x

unsigned hex

%d

signed decimal

%u

unsigned decimal

%c

character

%s

null-terminated string

%p

unsigned pointer (same as %x)

%lx

unsigned long hex

%ld

signed long decimal

%lu

unsigned long decimal.

If this file is compiled with FIELDWIDTH defined, %[[-]w][.][p]f formats are understood, where w is the minimum field width and p is the precision, indicating the minimum number of digits to be printed. If w is negative, the field is left adjusted. If w starts with a leading zero, the field is padded using zeros instead of spaces.

This function uses dputchar() to perform output.

9.1.15udp_echo.c

The functions within the udp_echo.c file implement a menus interface to the UDP echo mechanism, which is useful for testing purposes.

9.1.16userpass.c

The userpass.c file contains code to implement a simple user/password database. Its functions are described in userpass.c on page 9-24.

ARM DUI 0144B

Copyright © 1998-2001 ARM Limited. All rights reserved.

9-5