gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

netdb.go (26949B)


      1 // Package netdb provides a Go interface for the protoent and servent
      2 // structures as defined in netdb.h
      3 //
      4 // A pure Go implementation is used by parsing /etc/protocols and
      5 // /etc/services
      6 //
      7 // All return values are pointers that point to the entries in the
      8 // original list of protocols and services. Manipulating the entries
      9 // would affect the entire program.
     10 package netdb // import "modernc.org/libc/honnef.co/go/netdb"
     11 
     12 // Modifications Copyright 2020 The Libc Authors. All rights reserved.
     13 // Use of this source code is governed by a BSD-style
     14 // license that can be found in the LICENSE file.
     15 
     16 import (
     17 	"io/ioutil"
     18 	"os"
     19 	"strconv"
     20 	"strings"
     21 )
     22 
     23 const (
     24 	protocols = `
     25 # Internet (IP) protocols
     26 #
     27 # Updated from http://www.iana.org/assignments/protocol-numbers and other
     28 # sources.
     29 # New protocols will be added on request if they have been officially
     30 # assigned by IANA and are not historical.
     31 # If you need a huge list of used numbers please install the nmap package.
     32 
     33 ip	0	IP		# internet protocol, pseudo protocol number
     34 hopopt	0	HOPOPT		# IPv6 Hop-by-Hop Option [RFC1883]
     35 icmp	1	ICMP		# internet control message protocol
     36 igmp	2	IGMP		# Internet Group Management
     37 ggp	3	GGP		# gateway-gateway protocol
     38 ipencap	4	IP-ENCAP	# IP encapsulated in IP (officially "IP")
     39 st	5	ST		# ST datagram mode
     40 tcp	6	TCP		# transmission control protocol
     41 egp	8	EGP		# exterior gateway protocol
     42 igp	9	IGP		# any private interior gateway (Cisco)
     43 pup	12	PUP		# PARC universal packet protocol
     44 udp	17	UDP		# user datagram protocol
     45 hmp	20	HMP		# host monitoring protocol
     46 xns-idp	22	XNS-IDP		# Xerox NS IDP
     47 rdp	27	RDP		# "reliable datagram" protocol
     48 iso-tp4	29	ISO-TP4		# ISO Transport Protocol class 4 [RFC905]
     49 dccp	33	DCCP		# Datagram Congestion Control Prot. [RFC4340]
     50 xtp	36	XTP		# Xpress Transfer Protocol
     51 ddp	37	DDP		# Datagram Delivery Protocol
     52 idpr-cmtp 38	IDPR-CMTP	# IDPR Control Message Transport
     53 ipv6	41	IPv6		# Internet Protocol, version 6
     54 ipv6-route 43	IPv6-Route	# Routing Header for IPv6
     55 ipv6-frag 44	IPv6-Frag	# Fragment Header for IPv6
     56 idrp	45	IDRP		# Inter-Domain Routing Protocol
     57 rsvp	46	RSVP		# Reservation Protocol
     58 gre	47	GRE		# General Routing Encapsulation
     59 esp	50	IPSEC-ESP	# Encap Security Payload [RFC2406]
     60 ah	51	IPSEC-AH	# Authentication Header [RFC2402]
     61 skip	57	SKIP		# SKIP
     62 ipv6-icmp 58	IPv6-ICMP	# ICMP for IPv6
     63 ipv6-nonxt 59	IPv6-NoNxt	# No Next Header for IPv6
     64 ipv6-opts 60	IPv6-Opts	# Destination Options for IPv6
     65 rspf	73	RSPF CPHB	# Radio Shortest Path First (officially CPHB)
     66 vmtp	81	VMTP		# Versatile Message Transport
     67 eigrp	88	EIGRP		# Enhanced Interior Routing Protocol (Cisco)
     68 ospf	89	OSPFIGP		# Open Shortest Path First IGP
     69 ax.25	93	AX.25		# AX.25 frames
     70 ipip	94	IPIP		# IP-within-IP Encapsulation Protocol
     71 etherip	97	ETHERIP		# Ethernet-within-IP Encapsulation [RFC3378]
     72 encap	98	ENCAP		# Yet Another IP encapsulation [RFC1241]
     73 #	99			# any private encryption scheme
     74 pim	103	PIM		# Protocol Independent Multicast
     75 ipcomp	108	IPCOMP		# IP Payload Compression Protocol
     76 vrrp	112	VRRP		# Virtual Router Redundancy Protocol [RFC5798]
     77 l2tp	115	L2TP		# Layer Two Tunneling Protocol [RFC2661]
     78 isis	124	ISIS		# IS-IS over IPv4
     79 sctp	132	SCTP		# Stream Control Transmission Protocol
     80 fc	133	FC		# Fibre Channel
     81 mobility-header 135 Mobility-Header # Mobility Support for IPv6 [RFC3775]
     82 udplite	136	UDPLite		# UDP-Lite [RFC3828]
     83 mpls-in-ip 137	MPLS-in-IP	# MPLS-in-IP [RFC4023]
     84 manet	138			# MANET Protocols [RFC5498]
     85 hip	139	HIP		# Host Identity Protocol
     86 shim6	140	Shim6		# Shim6 Protocol [RFC5533]
     87 wesp	141	WESP		# Wrapped Encapsulating Security Payload
     88 rohc	142	ROHC		# Robust Header Compression
     89 `
     90 
     91 	services = `
     92 # Network services, Internet style
     93 #
     94 # Note that it is presently the policy of IANA to assign a single well-known
     95 # port number for both TCP and UDP; hence, officially ports have two entries
     96 # even if the protocol doesn't support UDP operations.
     97 #
     98 # Updated from https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml .
     99 #
    100 # New ports will be added on request if they have been officially assigned
    101 # by IANA and used in the real-world or are needed by a debian package.
    102 # If you need a huge list of used numbers please install the nmap package.
    103 
    104 tcpmux		1/tcp				# TCP port service multiplexer
    105 echo		7/tcp
    106 echo		7/udp
    107 discard		9/tcp		sink null
    108 discard		9/udp		sink null
    109 systat		11/tcp		users
    110 daytime		13/tcp
    111 daytime		13/udp
    112 netstat		15/tcp
    113 qotd		17/tcp		quote
    114 msp		18/tcp				# message send protocol
    115 msp		18/udp
    116 chargen		19/tcp		ttytst source
    117 chargen		19/udp		ttytst source
    118 ftp-data	20/tcp
    119 ftp		21/tcp
    120 fsp		21/udp		fspd
    121 ssh		22/tcp				# SSH Remote Login Protocol
    122 telnet		23/tcp
    123 smtp		25/tcp		mail
    124 time		37/tcp		timserver
    125 time		37/udp		timserver
    126 rlp		39/udp		resource	# resource location
    127 nameserver	42/tcp		name		# IEN 116
    128 whois		43/tcp		nicname
    129 tacacs		49/tcp				# Login Host Protocol (TACACS)
    130 tacacs		49/udp
    131 domain		53/tcp				# Domain Name Server
    132 domain		53/udp
    133 bootps		67/udp
    134 bootpc		68/udp
    135 tftp		69/udp
    136 gopher		70/tcp				# Internet Gopher
    137 finger		79/tcp
    138 http		80/tcp		www		# WorldWideWeb HTTP
    139 link		87/tcp		ttylink
    140 kerberos	88/tcp		kerberos5 krb5 kerberos-sec	# Kerberos v5
    141 kerberos	88/udp		kerberos5 krb5 kerberos-sec	# Kerberos v5
    142 iso-tsap	102/tcp		tsap		# part of ISODE
    143 acr-nema	104/tcp		dicom		# Digital Imag. & Comm. 300
    144 pop3		110/tcp		pop-3		# POP version 3
    145 sunrpc		111/tcp		portmapper	# RPC 4.0 portmapper
    146 sunrpc		111/udp		portmapper
    147 auth		113/tcp		authentication tap ident
    148 sftp		115/tcp
    149 nntp		119/tcp		readnews untp	# USENET News Transfer Protocol
    150 ntp		123/udp				# Network Time Protocol
    151 epmap		135/tcp		loc-srv		# DCE endpoint resolution
    152 epmap		135/udp		loc-srv
    153 netbios-ns	137/tcp				# NETBIOS Name Service
    154 netbios-ns	137/udp
    155 netbios-dgm	138/tcp				# NETBIOS Datagram Service
    156 netbios-dgm	138/udp
    157 netbios-ssn	139/tcp				# NETBIOS session service
    158 netbios-ssn	139/udp
    159 imap2		143/tcp		imap		# Interim Mail Access P 2 and 4
    160 snmp		161/tcp				# Simple Net Mgmt Protocol
    161 snmp		161/udp
    162 snmp-trap	162/tcp		snmptrap	# Traps for SNMP
    163 snmp-trap	162/udp		snmptrap
    164 cmip-man	163/tcp				# ISO mgmt over IP (CMOT)
    165 cmip-man	163/udp
    166 cmip-agent	164/tcp
    167 cmip-agent	164/udp
    168 mailq		174/tcp			# Mailer transport queue for Zmailer
    169 mailq		174/udp
    170 xdmcp		177/tcp				# X Display Mgr. Control Proto
    171 xdmcp		177/udp
    172 nextstep	178/tcp		NeXTStep NextStep	# NeXTStep window
    173 nextstep	178/udp		NeXTStep NextStep	#  server
    174 bgp		179/tcp				# Border Gateway Protocol
    175 irc		194/tcp				# Internet Relay Chat
    176 irc		194/udp
    177 smux		199/tcp				# SNMP Unix Multiplexer
    178 smux		199/udp
    179 at-rtmp		201/tcp				# AppleTalk routing
    180 at-rtmp		201/udp
    181 at-nbp		202/tcp				# AppleTalk name binding
    182 at-nbp		202/udp
    183 at-echo		204/tcp				# AppleTalk echo
    184 at-echo		204/udp
    185 at-zis		206/tcp				# AppleTalk zone information
    186 at-zis		206/udp
    187 qmtp		209/tcp				# Quick Mail Transfer Protocol
    188 qmtp		209/udp
    189 z3950		210/tcp		wais		# NISO Z39.50 database
    190 z3950		210/udp		wais
    191 ipx		213/tcp				# IPX
    192 ipx		213/udp
    193 ptp-event	319/udp
    194 ptp-general	320/udp
    195 pawserv		345/tcp				# Perf Analysis Workbench
    196 pawserv		345/udp
    197 zserv		346/tcp				# Zebra server
    198 zserv		346/udp
    199 fatserv		347/tcp				# Fatmen Server
    200 fatserv		347/udp
    201 rpc2portmap	369/tcp
    202 rpc2portmap	369/udp				# Coda portmapper
    203 codaauth2	370/tcp
    204 codaauth2	370/udp				# Coda authentication server
    205 clearcase	371/tcp		Clearcase
    206 clearcase	371/udp		Clearcase
    207 ulistserv	372/tcp				# UNIX Listserv
    208 ulistserv	372/udp
    209 ldap		389/tcp			# Lightweight Directory Access Protocol
    210 ldap		389/udp
    211 imsp		406/tcp			# Interactive Mail Support Protocol
    212 imsp		406/udp
    213 svrloc		427/tcp				# Server Location
    214 svrloc		427/udp
    215 https		443/tcp				# http protocol over TLS/SSL
    216 snpp		444/tcp				# Simple Network Paging Protocol
    217 snpp		444/udp
    218 microsoft-ds	445/tcp				# Microsoft Naked CIFS
    219 microsoft-ds	445/udp
    220 kpasswd		464/tcp
    221 kpasswd		464/udp
    222 submissions	465/tcp		ssmtp smtps urd # Submission over TLS [RFC8314]
    223 saft		487/tcp			# Simple Asynchronous File Transfer
    224 saft		487/udp
    225 isakmp		500/tcp			# IPsec - Internet Security Association
    226 isakmp		500/udp			#  and Key Management Protocol
    227 rtsp		554/tcp			# Real Time Stream Control Protocol
    228 rtsp		554/udp
    229 nqs		607/tcp				# Network Queuing system
    230 nqs		607/udp
    231 npmp-local	610/tcp		dqs313_qmaster		# npmp-local / DQS
    232 npmp-local	610/udp		dqs313_qmaster
    233 npmp-gui	611/tcp		dqs313_execd		# npmp-gui / DQS
    234 npmp-gui	611/udp		dqs313_execd
    235 hmmp-ind	612/tcp		dqs313_intercell	# HMMP Indication / DQS
    236 hmmp-ind	612/udp		dqs313_intercell
    237 asf-rmcp	623/udp		# ASF Remote Management and Control Protocol
    238 qmqp		628/tcp
    239 qmqp		628/udp
    240 ipp		631/tcp				# Internet Printing Protocol
    241 ipp		631/udp
    242 #
    243 # UNIX specific services
    244 #
    245 exec		512/tcp
    246 biff		512/udp		comsat
    247 login		513/tcp
    248 who		513/udp		whod
    249 shell		514/tcp		cmd		# no passwords used
    250 syslog		514/udp
    251 printer		515/tcp		spooler		# line printer spooler
    252 talk		517/udp
    253 ntalk		518/udp
    254 route		520/udp		router routed	# RIP
    255 timed		525/udp		timeserver
    256 tempo		526/tcp		newdate
    257 courier		530/tcp		rpc
    258 conference	531/tcp		chat
    259 netnews		532/tcp		readnews
    260 netwall		533/udp				# for emergency broadcasts
    261 gdomap		538/tcp				# GNUstep distributed objects
    262 gdomap		538/udp
    263 uucp		540/tcp		uucpd		# uucp daemon
    264 klogin		543/tcp				# Kerberized 'rlogin' (v5)
    265 kshell		544/tcp		krcmd		# Kerberized 'rsh' (v5)
    266 dhcpv6-client	546/tcp
    267 dhcpv6-client	546/udp
    268 dhcpv6-server	547/tcp
    269 dhcpv6-server	547/udp
    270 afpovertcp	548/tcp				# AFP over TCP
    271 afpovertcp	548/udp
    272 idfp		549/tcp
    273 idfp		549/udp
    274 remotefs	556/tcp		rfs_server rfs	# Brunhoff remote filesystem
    275 nntps		563/tcp		snntp		# NNTP over SSL
    276 submission	587/tcp				# Submission [RFC4409]
    277 ldaps		636/tcp				# LDAP over SSL
    278 ldaps		636/udp
    279 tinc		655/tcp				# tinc control port
    280 tinc		655/udp
    281 silc		706/tcp
    282 silc		706/udp
    283 kerberos-adm	749/tcp				# Kerberos 'kadmin' (v5)
    284 #
    285 webster		765/tcp				# Network dictionary
    286 webster		765/udp
    287 domain-s	853/tcp				# DNS over TLS [RFC7858]
    288 domain-s	853/udp				# DNS over DTLS [RFC8094]
    289 rsync		873/tcp
    290 ftps-data	989/tcp				# FTP over SSL (data)
    291 ftps		990/tcp
    292 telnets		992/tcp				# Telnet over SSL
    293 imaps		993/tcp				# IMAP over SSL
    294 pop3s		995/tcp				# POP-3 over SSL
    295 #
    296 # From "ssigned Numbers":
    297 #
    298 #> The Registered Ports are not controlled by the IANA and on most systems
    299 #> can be used by ordinary user processes or programs executed by ordinary
    300 #> users.
    301 #
    302 #> Ports are used in the TCP [45,106] to name the ends of logical
    303 #> connections which carry long term conversations.  For the purpose of
    304 #> providing services to unknown callers, a service contact port is
    305 #> defined.  This list specifies the port used by the server process as its
    306 #> contact port.  While the IANA can not control uses of these ports it
    307 #> does register or list uses of these ports as a convienence to the
    308 #> community.
    309 #
    310 socks		1080/tcp			# socks proxy server
    311 socks		1080/udp
    312 proofd		1093/tcp
    313 proofd		1093/udp
    314 rootd		1094/tcp
    315 rootd		1094/udp
    316 openvpn		1194/tcp
    317 openvpn		1194/udp
    318 rmiregistry	1099/tcp			# Java RMI Registry
    319 rmiregistry	1099/udp
    320 kazaa		1214/tcp
    321 kazaa		1214/udp
    322 nessus		1241/tcp			# Nessus vulnerability
    323 nessus		1241/udp			#  assessment scanner
    324 lotusnote	1352/tcp	lotusnotes	# Lotus Note
    325 lotusnote	1352/udp	lotusnotes
    326 ms-sql-s	1433/tcp			# Microsoft SQL Server
    327 ms-sql-s	1433/udp
    328 ms-sql-m	1434/tcp			# Microsoft SQL Monitor
    329 ms-sql-m	1434/udp
    330 ingreslock	1524/tcp
    331 ingreslock	1524/udp
    332 datametrics	1645/tcp	old-radius
    333 datametrics	1645/udp	old-radius
    334 sa-msg-port	1646/tcp	old-radacct
    335 sa-msg-port	1646/udp	old-radacct
    336 kermit		1649/tcp
    337 kermit		1649/udp
    338 groupwise	1677/tcp
    339 groupwise	1677/udp
    340 l2f		1701/tcp	l2tp
    341 l2f		1701/udp	l2tp
    342 radius		1812/tcp
    343 radius		1812/udp
    344 radius-acct	1813/tcp	radacct		# Radius Accounting
    345 radius-acct	1813/udp	radacct
    346 msnp		1863/tcp			# MSN Messenger
    347 msnp		1863/udp
    348 unix-status	1957/tcp			# remstats unix-status server
    349 log-server	1958/tcp			# remstats log server
    350 remoteping	1959/tcp			# remstats remoteping server
    351 cisco-sccp	2000/tcp			# Cisco SCCP
    352 cisco-sccp	2000/udp
    353 search		2010/tcp	ndtp
    354 pipe-server	2010/tcp	pipe_server
    355 nfs		2049/tcp			# Network File System
    356 nfs		2049/udp			# Network File System
    357 gnunet		2086/tcp
    358 gnunet		2086/udp
    359 rtcm-sc104	2101/tcp			# RTCM SC-104 IANA 1/29/99
    360 rtcm-sc104	2101/udp
    361 gsigatekeeper	2119/tcp
    362 gsigatekeeper	2119/udp
    363 gris		2135/tcp		# Grid Resource Information Server
    364 gris		2135/udp
    365 cvspserver	2401/tcp			# CVS client/server operations
    366 cvspserver	2401/udp
    367 venus		2430/tcp			# codacon port
    368 venus		2430/udp			# Venus callback/wbc interface
    369 venus-se	2431/tcp			# tcp side effects
    370 venus-se	2431/udp			# udp sftp side effect
    371 codasrv		2432/tcp			# not used
    372 codasrv		2432/udp			# server port
    373 codasrv-se	2433/tcp			# tcp side effects
    374 codasrv-se	2433/udp			# udp sftp side effect
    375 mon		2583/tcp			# MON traps
    376 mon		2583/udp
    377 dict		2628/tcp			# Dictionary server
    378 dict		2628/udp
    379 f5-globalsite	2792/tcp
    380 f5-globalsite	2792/udp
    381 gsiftp		2811/tcp
    382 gsiftp		2811/udp
    383 gpsd		2947/tcp
    384 gpsd		2947/udp
    385 gds-db		3050/tcp	gds_db		# InterBase server
    386 gds-db		3050/udp	gds_db
    387 icpv2		3130/tcp	icp		# Internet Cache Protocol
    388 icpv2		3130/udp	icp
    389 isns		3205/tcp			# iSNS Server Port
    390 isns		3205/udp			# iSNS Server Port
    391 iscsi-target	3260/tcp
    392 mysql		3306/tcp
    393 mysql		3306/udp
    394 nut		3493/tcp			# Network UPS Tools
    395 nut		3493/udp
    396 distcc		3632/tcp			# distributed compiler
    397 distcc		3632/udp
    398 daap		3689/tcp			# Digital Audio Access Protocol
    399 daap		3689/udp
    400 svn		3690/tcp	subversion	# Subversion protocol
    401 svn		3690/udp	subversion
    402 suucp		4031/tcp			# UUCP over SSL
    403 suucp		4031/udp
    404 sysrqd		4094/tcp			# sysrq daemon
    405 sysrqd		4094/udp
    406 sieve		4190/tcp			# ManageSieve Protocol
    407 epmd		4369/tcp			# Erlang Port Mapper Daemon
    408 epmd		4369/udp
    409 remctl		4373/tcp		# Remote Authenticated Command Service
    410 remctl		4373/udp
    411 f5-iquery	4353/tcp			# F5 iQuery
    412 f5-iquery	4353/udp
    413 ipsec-nat-t	4500/udp			# IPsec NAT-Traversal [RFC3947]
    414 iax		4569/tcp			# Inter-Asterisk eXchange
    415 iax		4569/udp
    416 mtn		4691/tcp			# monotone Netsync Protocol
    417 mtn		4691/udp
    418 radmin-port	4899/tcp			# RAdmin Port
    419 radmin-port	4899/udp
    420 rfe		5002/udp			# Radio Free Ethernet
    421 rfe		5002/tcp
    422 mmcc		5050/tcp	# multimedia conference control tool (Yahoo IM)
    423 mmcc		5050/udp
    424 sip		5060/tcp			# Session Initiation Protocol
    425 sip		5060/udp
    426 sip-tls		5061/tcp
    427 sip-tls		5061/udp
    428 aol		5190/tcp			# AIM
    429 aol		5190/udp
    430 xmpp-client	5222/tcp	jabber-client	# Jabber Client Connection
    431 xmpp-client	5222/udp	jabber-client
    432 xmpp-server	5269/tcp	jabber-server	# Jabber Server Connection
    433 xmpp-server	5269/udp	jabber-server
    434 cfengine	5308/tcp
    435 cfengine	5308/udp
    436 mdns		5353/tcp			# Multicast DNS
    437 mdns		5353/udp
    438 postgresql	5432/tcp	postgres	# PostgreSQL Database
    439 postgresql	5432/udp	postgres
    440 freeciv		5556/tcp	rptp		# Freeciv gameplay
    441 freeciv		5556/udp
    442 amqps		5671/tcp			# AMQP protocol over TLS/SSL
    443 amqp		5672/tcp
    444 amqp		5672/udp
    445 amqp		5672/sctp
    446 ggz		5688/tcp			# GGZ Gaming Zone
    447 ggz		5688/udp
    448 x11		6000/tcp	x11-0		# X Window System
    449 x11		6000/udp	x11-0
    450 x11-1		6001/tcp
    451 x11-1		6001/udp
    452 x11-2		6002/tcp
    453 x11-2		6002/udp
    454 x11-3		6003/tcp
    455 x11-3		6003/udp
    456 x11-4		6004/tcp
    457 x11-4		6004/udp
    458 x11-5		6005/tcp
    459 x11-5		6005/udp
    460 x11-6		6006/tcp
    461 x11-6		6006/udp
    462 x11-7		6007/tcp
    463 x11-7		6007/udp
    464 gnutella-svc	6346/tcp			# gnutella
    465 gnutella-svc	6346/udp
    466 gnutella-rtr	6347/tcp			# gnutella
    467 gnutella-rtr	6347/udp
    468 sge-qmaster	6444/tcp	sge_qmaster	# Grid Engine Qmaster Service
    469 sge-qmaster	6444/udp	sge_qmaster
    470 sge-execd	6445/tcp	sge_execd	# Grid Engine Execution Service
    471 sge-execd	6445/udp	sge_execd
    472 mysql-proxy	6446/tcp			# MySQL Proxy
    473 mysql-proxy	6446/udp
    474 babel		6696/udp			# Babel Routing Protocol
    475 ircs-u		6697/tcp		# Internet Relay Chat via TLS/SSL
    476 afs3-fileserver 7000/tcp	bbs		# file server itself
    477 afs3-fileserver 7000/udp	bbs
    478 afs3-callback	7001/tcp			# callbacks to cache managers
    479 afs3-callback	7001/udp
    480 afs3-prserver	7002/tcp			# users & groups database
    481 afs3-prserver	7002/udp
    482 afs3-vlserver	7003/tcp			# volume location database
    483 afs3-vlserver	7003/udp
    484 afs3-kaserver	7004/tcp			# AFS/Kerberos authentication
    485 afs3-kaserver	7004/udp
    486 afs3-volser	7005/tcp			# volume managment server
    487 afs3-volser	7005/udp
    488 afs3-errors	7006/tcp			# error interpretation service
    489 afs3-errors	7006/udp
    490 afs3-bos	7007/tcp			# basic overseer process
    491 afs3-bos	7007/udp
    492 afs3-update	7008/tcp			# server-to-server updater
    493 afs3-update	7008/udp
    494 afs3-rmtsys	7009/tcp			# remote cache manager service
    495 afs3-rmtsys	7009/udp
    496 font-service	7100/tcp	xfs		# X Font Service
    497 font-service	7100/udp	xfs
    498 http-alt	8080/tcp	webcache	# WWW caching service
    499 http-alt	8080/udp
    500 puppet		8140/tcp			# The Puppet master service
    501 bacula-dir	9101/tcp			# Bacula Director
    502 bacula-dir	9101/udp
    503 bacula-fd	9102/tcp			# Bacula File Daemon
    504 bacula-fd	9102/udp
    505 bacula-sd	9103/tcp			# Bacula Storage Daemon
    506 bacula-sd	9103/udp
    507 xmms2		9667/tcp	# Cross-platform Music Multiplexing System
    508 xmms2		9667/udp
    509 nbd		10809/tcp			# Linux Network Block Device
    510 zabbix-agent	10050/tcp			# Zabbix Agent
    511 zabbix-agent	10050/udp
    512 zabbix-trapper	10051/tcp			# Zabbix Trapper
    513 zabbix-trapper	10051/udp
    514 amanda		10080/tcp			# amanda backup services
    515 amanda		10080/udp
    516 dicom		11112/tcp
    517 hkp		11371/tcp			# OpenPGP HTTP Keyserver
    518 hkp		11371/udp
    519 bprd		13720/tcp			# VERITAS NetBackup
    520 bprd		13720/udp
    521 bpdbm		13721/tcp			# VERITAS NetBackup
    522 bpdbm		13721/udp
    523 bpjava-msvc	13722/tcp			# BP Java MSVC Protocol
    524 bpjava-msvc	13722/udp
    525 vnetd		13724/tcp			# Veritas Network Utility
    526 vnetd		13724/udp
    527 bpcd		13782/tcp			# VERITAS NetBackup
    528 bpcd		13782/udp
    529 vopied		13783/tcp			# VERITAS NetBackup
    530 vopied		13783/udp
    531 db-lsp		17500/tcp			# Dropbox LanSync Protocol
    532 dcap		22125/tcp			# dCache Access Protocol
    533 gsidcap		22128/tcp			# GSI dCache Access Protocol
    534 wnn6		22273/tcp			# wnn6
    535 wnn6		22273/udp
    536 
    537 #
    538 # Datagram Delivery Protocol services
    539 #
    540 rtmp		1/ddp			# Routing Table Maintenance Protocol
    541 nbp		2/ddp			# Name Binding Protocol
    542 echo		4/ddp			# AppleTalk Echo Protocol
    543 zip		6/ddp			# Zone Information Protocol
    544 
    545 #=========================================================================
    546 # The remaining port numbers are not as allocated by IANA.
    547 #=========================================================================
    548 
    549 # Kerberos (Project Athena/MIT) services
    550 # Note that these are for Kerberos v4, and are unofficial.  Sites running
    551 # v4 should uncomment these and comment out the v5 entries above.
    552 #
    553 kerberos4	750/udp		kerberos-iv kdc	# Kerberos (server)
    554 kerberos4	750/tcp		kerberos-iv kdc
    555 kerberos-master	751/udp		kerberos_master	# Kerberos authentication
    556 kerberos-master	751/tcp
    557 passwd-server	752/udp		passwd_server	# Kerberos passwd server
    558 krb-prop	754/tcp		krb_prop krb5_prop hprop # Kerberos slave propagation
    559 krbupdate	760/tcp		kreg		# Kerberos registration
    560 swat		901/tcp				# swat
    561 kpop		1109/tcp			# Pop with Kerberos
    562 knetd		2053/tcp			# Kerberos de-multiplexor
    563 zephyr-srv	2102/udp			# Zephyr server
    564 zephyr-clt	2103/udp			# Zephyr serv-hm connection
    565 zephyr-hm	2104/udp			# Zephyr hostmanager
    566 eklogin		2105/tcp			# Kerberos encrypted rlogin
    567 # Hmmm. Are we using Kv4 or Kv5 now? Worrying.
    568 # The following is probably Kerberos v5  --- ajt@debian.org (11/02/2000)
    569 kx		2111/tcp			# X over Kerberos
    570 iprop		2121/tcp			# incremental propagation
    571 #
    572 # Unofficial but necessary (for NetBSD) services
    573 #
    574 supfilesrv	871/tcp				# SUP server
    575 supfiledbg	1127/tcp			# SUP debugging
    576 
    577 #
    578 # Services added for the Debian GNU/Linux distribution
    579 #
    580 poppassd	106/tcp				# Eudora
    581 poppassd	106/udp
    582 moira-db	775/tcp		moira_db	# Moira database
    583 moira-update	777/tcp		moira_update	# Moira update protocol
    584 moira-ureg	779/udp		moira_ureg	# Moira user registration
    585 spamd		783/tcp				# spamassassin daemon
    586 omirr		808/tcp		omirrd		# online mirror
    587 omirr		808/udp		omirrd
    588 customs		1001/tcp			# pmake customs server
    589 customs		1001/udp
    590 skkserv		1178/tcp			# skk jisho server port
    591 predict		1210/udp			# predict -- satellite tracking
    592 rmtcfg		1236/tcp			# Gracilis Packeten remote config server
    593 wipld		1300/tcp			# Wipl network monitor
    594 xtel		1313/tcp			# french minitel
    595 xtelw		1314/tcp			# french minitel
    596 support		1529/tcp			# GNATS
    597 cfinger		2003/tcp			# GNU Finger
    598 frox		2121/tcp			# frox: caching ftp proxy
    599 ninstall	2150/tcp			# ninstall service
    600 ninstall	2150/udp
    601 zebrasrv	2600/tcp			# zebra service
    602 zebra		2601/tcp			# zebra vty
    603 ripd		2602/tcp			# ripd vty (zebra)
    604 ripngd		2603/tcp			# ripngd vty (zebra)
    605 ospfd		2604/tcp			# ospfd vty (zebra)
    606 bgpd		2605/tcp			# bgpd vty (zebra)
    607 ospf6d		2606/tcp			# ospf6d vty (zebra)
    608 ospfapi		2607/tcp			# OSPF-API
    609 isisd		2608/tcp			# ISISd vty (zebra)
    610 afbackup	2988/tcp			# Afbackup system
    611 afbackup	2988/udp
    612 afmbackup	2989/tcp			# Afmbackup system
    613 afmbackup	2989/udp
    614 xtell		4224/tcp			# xtell server
    615 fax		4557/tcp			# FAX transmission service (old)
    616 hylafax		4559/tcp			# HylaFAX client-server protocol (new)
    617 distmp3		4600/tcp			# distmp3host daemon
    618 munin		4949/tcp	lrrd		# Munin
    619 enbd-cstatd	5051/tcp			# ENBD client statd
    620 enbd-sstatd	5052/tcp			# ENBD server statd
    621 pcrd		5151/tcp			# PCR-1000 Daemon
    622 noclog		5354/tcp			# noclogd with TCP (nocol)
    623 noclog		5354/udp			# noclogd with UDP (nocol)
    624 hostmon		5355/tcp			# hostmon uses TCP (nocol)
    625 hostmon		5355/udp			# hostmon uses UDP (nocol)
    626 rplay		5555/udp			# RPlay audio service
    627 nrpe		5666/tcp			# Nagios Remote Plugin Executor
    628 nsca		5667/tcp			# Nagios Agent - NSCA
    629 mrtd		5674/tcp			# MRT Routing Daemon
    630 bgpsim		5675/tcp			# MRT Routing Simulator
    631 canna		5680/tcp			# cannaserver
    632 syslog-tls	6514/tcp			# Syslog over TLS [RFC5425]
    633 sane-port	6566/tcp	sane saned	# SANE network scanner daemon
    634 ircd		6667/tcp			# Internet Relay Chat
    635 zope-ftp	8021/tcp			# zope management by ftp
    636 tproxy		8081/tcp			# Transparent Proxy
    637 omniorb		8088/tcp			# OmniORB
    638 omniorb		8088/udp
    639 clc-build-daemon 8990/tcp			# Common lisp build daemon
    640 xinetd		9098/tcp
    641 mandelspawn	9359/udp	mandelbrot	# network mandelbrot
    642 git		9418/tcp			# Git Version Control System
    643 zope		9673/tcp			# zope server
    644 webmin		10000/tcp
    645 kamanda		10081/tcp			# amanda backup services (Kerberos)
    646 kamanda		10081/udp
    647 amandaidx	10082/tcp			# amanda backup services
    648 amidxtape	10083/tcp			# amanda backup services
    649 smsqp		11201/tcp			# Alamin SMS gateway
    650 smsqp		11201/udp
    651 xpilot		15345/tcp			# XPilot Contact Port
    652 xpilot		15345/udp
    653 sgi-cmsd	17001/udp		# Cluster membership services daemon
    654 sgi-crsd	17002/udp
    655 sgi-gcd		17003/udp			# SGI Group membership daemon
    656 sgi-cad		17004/tcp			# Cluster Admin daemon
    657 isdnlog		20011/tcp			# isdn logging system
    658 isdnlog		20011/udp
    659 vboxd		20012/tcp			# voice box system
    660 vboxd		20012/udp
    661 binkp		24554/tcp			# binkp fidonet protocol
    662 asp		27374/tcp			# Address Search Protocol
    663 asp		27374/udp
    664 csync2		30865/tcp			# cluster synchronization tool
    665 dircproxy	57000/tcp			# Detachable IRC Proxy
    666 tfido		60177/tcp			# fidonet EMSI over telnet
    667 fido		60179/tcp			# fidonet EMSI over TCP
    668 
    669 # Local services
    670 `
    671 )
    672 
    673 type Protoent struct {
    674 	Name    string
    675 	Aliases []string
    676 	Number  int
    677 }
    678 
    679 type Servent struct {
    680 	Name     string
    681 	Aliases  []string
    682 	Port     int
    683 	Protocol *Protoent
    684 }
    685 
    686 // These variables get populated from /etc/protocols and /etc/services
    687 // respectively.
    688 var (
    689 	Protocols []*Protoent
    690 	Services  []*Servent
    691 )
    692 
    693 func init() {
    694 	protoMap := make(map[string]*Protoent)
    695 
    696 	// Load protocols
    697 	data, err := ioutil.ReadFile("/etc/protocols")
    698 	if err != nil {
    699 		if !os.IsNotExist(err) {
    700 			panic(err)
    701 		}
    702 
    703 		data = []byte(protocols)
    704 	}
    705 
    706 	for _, line := range strings.Split(string(data), "\n") {
    707 		line = strings.TrimSpace(line)
    708 		split := strings.SplitN(line, "#", 2)
    709 		fields := strings.Fields(split[0])
    710 		if len(fields) < 2 {
    711 			continue
    712 		}
    713 
    714 		num, err := strconv.ParseInt(fields[1], 10, 32)
    715 		if err != nil {
    716 			// If we find lines that don't match the expected format we skip over them.
    717 			// The expected format is <protocol> <number> <aliases> ...
    718 			// As we're using strings.Fields for splitting the line, failures can happen if the protocol field contains white spaces.
    719 			continue
    720 		}
    721 
    722 		protoent := &Protoent{
    723 			Name:    fields[0],
    724 			Aliases: fields[2:],
    725 			Number:  int(num),
    726 		}
    727 		Protocols = append(Protocols, protoent)
    728 
    729 		protoMap[fields[0]] = protoent
    730 	}
    731 
    732 	// Load services
    733 	data, err = ioutil.ReadFile("/etc/services")
    734 	if err != nil {
    735 		if !os.IsNotExist(err) {
    736 			panic(err)
    737 		}
    738 
    739 		data = []byte(services)
    740 	}
    741 
    742 	for _, line := range strings.Split(string(data), "\n") {
    743 		line = strings.TrimSpace(line)
    744 		split := strings.SplitN(line, "#", 2)
    745 		fields := strings.Fields(split[0])
    746 		if len(fields) < 2 {
    747 			continue
    748 		}
    749 
    750 		// https://gitlab.com/cznic/libc/-/issues/25
    751 		if strings.Index(fields[1], "/") < 0 {
    752 			continue
    753 		}
    754 
    755 		name := fields[0]
    756 		portproto := strings.SplitN(fields[1], "/", 2)
    757 		port, err := strconv.ParseInt(portproto[0], 10, 32)
    758 		if err != nil {
    759 			// If we find lines that don't match the expected format we skip over them.
    760 			// The expected format is <service-name> <port>/<protocol> [aliases ...]
    761 			// As we're using strings.Fields for splitting the line, failures can happen if the service name field contains white spaces.
    762 			continue
    763 		}
    764 
    765 		proto := portproto[1]
    766 		aliases := fields[2:]
    767 
    768 		Services = append(Services, &Servent{
    769 			Name:     name,
    770 			Aliases:  aliases,
    771 			Port:     int(port),
    772 			Protocol: protoMap[proto],
    773 		})
    774 	}
    775 }
    776 
    777 // Equal checks if two Protoents are the same, which is the case if
    778 // their protocol numbers are identical or when both Protoents are
    779 // nil.
    780 func (this *Protoent) Equal(other *Protoent) bool {
    781 	if this == nil && other == nil {
    782 		return true
    783 	}
    784 
    785 	if this == nil || other == nil {
    786 		return false
    787 	}
    788 
    789 	return this.Number == other.Number
    790 }
    791 
    792 // Equal checks if two Servents are the same, which is the case if
    793 // their port numbers and protocols are identical or when both
    794 // Servents are nil.
    795 func (this *Servent) Equal(other *Servent) bool {
    796 	if this == nil && other == nil {
    797 		return true
    798 	}
    799 
    800 	if this == nil || other == nil {
    801 		return false
    802 	}
    803 
    804 	return this.Port == other.Port &&
    805 		this.Protocol.Equal(other.Protocol)
    806 }
    807 
    808 // GetProtoByNumber returns the Protoent for a given protocol number.
    809 func GetProtoByNumber(num int) (protoent *Protoent) {
    810 	for _, protoent := range Protocols {
    811 		if protoent.Number == num {
    812 			return protoent
    813 		}
    814 	}
    815 	return nil
    816 }
    817 
    818 // GetProtoByName returns the Protoent whose name or any of its
    819 // aliases matches the argument.
    820 func GetProtoByName(name string) (protoent *Protoent) {
    821 	for _, protoent := range Protocols {
    822 		if protoent.Name == name {
    823 			return protoent
    824 		}
    825 
    826 		for _, alias := range protoent.Aliases {
    827 			if alias == name {
    828 				return protoent
    829 			}
    830 		}
    831 	}
    832 
    833 	return nil
    834 }
    835 
    836 // GetServByName returns the Servent for a given service name or alias
    837 // and protocol. If the protocol is nil, the first service matching
    838 // the service name is returned.
    839 func GetServByName(name string, protocol *Protoent) (servent *Servent) {
    840 	for _, servent := range Services {
    841 		if !servent.Protocol.Equal(protocol) {
    842 			continue
    843 		}
    844 
    845 		if servent.Name == name {
    846 			return servent
    847 		}
    848 
    849 		for _, alias := range servent.Aliases {
    850 			if alias == name {
    851 				return servent
    852 			}
    853 		}
    854 	}
    855 
    856 	return nil
    857 }
    858 
    859 // GetServByPort returns the Servent for a given port number and
    860 // protocol. If the protocol is nil, the first service matching the
    861 // port number is returned.
    862 func GetServByPort(port int, protocol *Protoent) *Servent {
    863 	for _, servent := range Services {
    864 		if servent.Port == port && servent.Protocol.Equal(protocol) {
    865 			return servent
    866 		}
    867 	}
    868 
    869 	return nil
    870 }