- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
SIMP_SRV.C
资源名称:ertos.rar [点击查看]
上传用户:sunrenlu
上传日期:2022-06-13
资源大小:1419k
文件大小:2k
源码类别:
操作系统开发
开发平台:
DOS
- /*
- * simple UDP server - just read data and write it out to the console
- *
- */
- #define LISTEN_PORT 162
- /*
- * Copyright (c) 2000 Erick Engelke
- */
- #include <stdio.h>
- #include <string.h>
- #include <memory.h>
- #include <rtos.h>
- #include <net.h>
- #include <ctype.h>
- #define BUF_SIZ 2048
- void dump(void *ptr, int len )
- {
- unsigned char *p = ptr;
- int x, y, xy;
- char ch;
- cprintf("nr%u (0x%04x) bytesnr", len, len );
- for ( y = 0 ; y < len ; y+= 16 ) {
- cprintf("nr%04x : ", y );
- for ( x = 0 ; x < 16 ; ++x ) {
- xy = x + y;
- cprintf( xy < len ? "%02x " : " ", p[xy] );
- }
- cprintf(" : ");
- for ( x = 0 ; x < 16 ; ++x ) {
- xy = x + y;
- ch = p[ xy ];
- if ( ! isprint( ch )) ch = '*';
- cprintf( xy < len ? "%c" : " ", ch );
- }
- }
- cprintf("nr");
- }
- main(int argc, char **argv)
- {
- udp_Socket *udp;
- static char buffer[ BUF_SIZ ];
- int len;
- rt_init(100);
- sock_init();
- udp = kcalloc( sizeof( udp_Socket ), 1 );
- if ( udp == NULL )
- rt_halt("out of memory");
- if (!udp_open( udp, 161, 0, 0, NULL ))
- rt_halt("unable to open SNMP server socket");
- while ( 1 ){
- if ( kbhit() ) rt_halt("user halted program");
- rt_sleep( 10 );
- tcp_tick( NULL );
- /* look for input */
- if ( (len = sock_dataready( udp )) != 0 ) {
- sock_fastread( udp, buffer, len );
- dump( buffer, len );
- }
- }
- }