Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1298800
  • 博文数量: 287
  • 博客积分: 11000
  • 博客等级: 上将
  • 技术积分: 3833
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-16 08:43
文章分类
文章存档

2013年(15)

2012年(17)

2011年(17)

2010年(135)

2009年(85)

2008年(18)

分类: 系统运维

2010-06-04 16:20:51

Get Service Name for Port Q: Is there any way to retrieve the TCP/IP service (local port name) associated to a local port number ? Just like int the command WRKSRVTBLE. Is there an API for this ? A: - Here's an RPG/IV example of the getservbyport() function: H bnddir( 'QC2LE' ) ** D getservbyport pr * extproc( 'getservbyport' ) D port 10i 0 value D protocol * value options( *string ) ** D servent ds based( p_servent ) D s_name * D s_aliases * D port 10i 0 D s_proto * ** D idx s 10i 0 D name s 128a D protocol s 128a D p_aliases s * dim( 12 ) based( s_aliases ) D aliases s 128a dim( %elem( p_aliases )) ** /free p_servent = getservbyport( 443: *null ); if p_servent <> *null; name = %str( s_name ); protocol = %str( s_proto ); for idx = 1 to %elem( p_aliases ); if p_aliases(idx) = *null; leave; endif; aliases(idx) = %str( p_aliases(idx)); endfor; endif; p_servent = getservbyport( 443: 'udp' ); if p_servent <> *null; name = %str( s_name ); protocol = %str( s_proto ); for idx = 1 to %elem( p_aliases ); if p_aliases(idx) = *null; leave; endif; aliases(idx) = %str( p_aliases(idx)); endfor; endif; *inlr = *on; return; /end-free The first call returns the first server registered to the specified port. The second call returns the service name for the specified port's 'udp' protocol entry. If you need to call the getservbyport() function repeatedly, the setservent() and endservent() functions allow you to control when the service database file is opened and closed, leaving it open for the getservbyport() calls. The getservent() function enables you to retrieve a sequential list of the servers in the service database. Thanks to Carsten Flensburg
阅读(715) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~