diff --git a/libc-test/src/functionalext/supplement/manual/network/getnameinfo.c b/libc-test/src/functionalext/supplement/manual/network/getnameinfo.c index fd5b00d689fe2be59d5a2bafad69aabd3cf15827..26110fca5957697cc8650c77e92be7885eb143ce 100644 --- a/libc-test/src/functionalext/supplement/manual/network/getnameinfo.c +++ b/libc-test/src/functionalext/supplement/manual/network/getnameinfo.c @@ -18,6 +18,7 @@ #include #include #include "functionalext.h" +#define HTTP_PORT 80 const int INFO_RESULT = 0; const int FAMILY_NOTSUPPORTED = -6; @@ -166,6 +167,26 @@ void getnameinfo_0700() EXPECT_EQ("getnameinfo_0700", ret, FAMILY_NOTSUPPORTED); } +void getnameinfo_0900() +{ + int ret; + char *ptr = "127.0.0.1"; + char hostname[128] = {0}; + char servername[128] = {0}; + struct sockaddr_in addrDst; + + memset(&addrDst, 0, sizeof(addrDst)); + addrDst.sin_family = AF_INET; + addrDst.sin_addr.s_addr = inet_addr(ptr); + addrDst.sin_port = htons(HTTP_PORT); + + ret = getnameinfo((struct sockaddr *)&addrDst, sizeof(addrDst), hostname, sizeof(hostname), + servername, sizeof(servername), 0); + EXPECT_EQ("getnameinfo_0900", ret, 0); + EXPECT_STREQ("getnameinfo_0900 hostname", hostname, "localhost"); + EXPECT_STREQ("getnameinfo_0900 hostname", servername, "http"); +} + int main(int argc, char *argv[]) { getnameinfo_0100(); @@ -175,5 +196,6 @@ int main(int argc, char *argv[]) getnameinfo_0500(); getnameinfo_0600(); getnameinfo_0700(); + getnameinfo_0900(); return t_status; } diff --git a/libc-test/src/functionalext/supplement/network/getservbyname.c b/libc-test/src/functionalext/supplement/network/getservbyname.c index b07188b74e97c15f731c61e96957155594917af0..c0a8c66864c7ec9c5f109d44935fa37b6f6c85c9 100755 --- a/libc-test/src/functionalext/supplement/network/getservbyname.c +++ b/libc-test/src/functionalext/supplement/network/getservbyname.c @@ -15,6 +15,8 @@ #include #include "functionalext.h" +#define FTP_PORT 21 +#define HTTP_PORT 80 /** * @tc.name : getservbyname_0100 @@ -45,9 +47,35 @@ void getservbyname_0200(void) EXPECT_PTREQ("getservbyname_0200", se, NULL); } +/** + * @tc.name : getservbyname_0300 + * @tc.desc : Get the service information of the specified port + * @tc.level : Level 0 +*/ +void getservbyname_0300(void) +{ + struct servent *se = getservbyname("ftp", "tcp"); + EXPECT_NE("getservbyname_0300", se, NULL); + EXPECT_EQ("getservbyname_0300", ntohs(se->s_port), FTP_PORT); +} + +/** + * @tc.name : getservbyname_0400 + * @tc.desc : Get the service information of the specified port + * @tc.level : Level 0 +*/ +void getservbyname_0400(void) +{ + struct servent *se = getservbyname("http", "tcp"); + EXPECT_NE("getservbyname_0400", se, NULL); + EXPECT_EQ("getservbyname_0400", ntohs(se->s_port), HTTP_PORT); +} + int main(void) { getservbyname_0100(); getservbyname_0200(); + getservbyname_0300(); + getservbyname_0400(); return t_status; } \ No newline at end of file diff --git a/musl_src.gni b/musl_src.gni index 4a953dded4108ce83c4d1b1de55fdac74217c9bb..9b46a1420dbaba18b2c3cc96424621cd155022f5 100644 --- a/musl_src.gni +++ b/musl_src.gni @@ -2087,6 +2087,7 @@ musl_src_porting_file = [ "src/internal/pthread_impl.h", "src/internal/locale_impl.h", "src/internal/syscall.h", + "src/internal/services.h", "ldso/namespace.h", "ldso/ns_config.h", "ldso/strops.h", @@ -2108,6 +2109,7 @@ musl_src_porting_file = [ "src/malloc/realloc.c", "src/network/inet_legacy.c", "src/network/lookup_name.c", + "src/network/lookup_serv.c", "src/network/resolvconf.c", "src/network/socket.c", "src/passwd/getspnam_r.c", diff --git a/porting/linux/user/src/internal/services.h b/porting/linux/user/src/internal/services.h new file mode 100644 index 0000000000000000000000000000000000000000..c6e75793e598982ba4bcbb39b824c7aa235fe430 --- /dev/null +++ b/porting/linux/user/src/internal/services.h @@ -0,0 +1,573 @@ +// Network services, Internet style +// +// Note that it is presently the policy of IANA to assign a single well-known +// port number for both TCP and UDP, hence, officially ports have two entries +// even if the protocol doesn't support UDP operations. +// +// Updated from http://www.iana.org/assignments/port-numbers and other +// sources like http://www.freebsd.org/cgi/cvsweb.cgi/src/etc/services . +// New ports will be added on request if they have been officially assigned +// by IANA and used in the real-world or are needed by a debian package. +// If you need a huge list of used numbers please install the nmap package. +#ifndef SYSTEM_SERVICES_HEADER +#define SYSTEM_SERVICES_HEADER + + +PORT_DESC("tcpmux 1/tcp\r\n"), +PORT_DESC("echo 7/tcp\r\n"), +PORT_DESC("echo 7/udp\r\n"), +PORT_DESC("discard 9/tcp sink null\r\n"), +PORT_DESC("discard 9/udp sink null\r\n"), +PORT_DESC("systat 11/tcp users\r\n"), +PORT_DESC("daytime 13/tcp\r\n"), +PORT_DESC("daytime 13/udp\r\n"), +PORT_DESC("netstat 15/tcp\r\n"), +PORT_DESC("qotd 17/tcp quote\r\n"), +PORT_DESC("msp 18/tcp\r\n"), +PORT_DESC("msp 18/udp\r\n"), +PORT_DESC("chargen 19/tcp ttytst source\r\n"), +PORT_DESC("chargen 19/udp ttytst source\r\n"), +PORT_DESC("ftp-data 20/tcp\r\n"), +PORT_DESC("ftp 21/tcp\r\n"), +PORT_DESC("fsp 21/udp fspd\r\n"), +PORT_DESC("ssh 22/tcp\r\n"), +PORT_DESC("ssh 22/udp\r\n"), +PORT_DESC("telnet 23/tcp\r\n"), +PORT_DESC("smtp 25/tcp mail\r\n"), +PORT_DESC("time 37/tcp timserver\r\n"), +PORT_DESC("time 37/udp timserver\r\n"), +PORT_DESC("rlp 39/udp resource\r\n"), +PORT_DESC("nameserver 42/tcp name\r\n"), +PORT_DESC("whois 43/tcp nicname\r\n"), +PORT_DESC("tacacs 49/tcp\r\n"), +PORT_DESC("tacacs 49/udp\r\n"), +PORT_DESC("re-mail-ck 50/tcp\r\n"), +PORT_DESC("re-mail-ck 50/udp\r\n"), +PORT_DESC("domain 53/tcp\r\n"), +PORT_DESC("domain 53/udp\r\n"), +PORT_DESC("mtp 57/tcp\r\n"), +PORT_DESC("tacacs-ds 65/tcp\r\n"), +PORT_DESC("tacacs-ds 65/udp\r\n"), +PORT_DESC("bootps 67/tcp\r\n"), +PORT_DESC("bootps 67/udp\r\n"), +PORT_DESC("bootpc 68/tcp\r\n"), +PORT_DESC("bootpc 68/udp\r\n"), +PORT_DESC("tftp 69/udp\r\n"), +PORT_DESC("gopher 70/tcp\r\n"), +PORT_DESC("gopher 70/udp\r\n"), +PORT_DESC("rje 77/tcp netrjs\r\n"), +PORT_DESC("finger 79/tcp\r\n"), +PORT_DESC("http 80/tcp www\r\n"), +PORT_DESC("http 80/udp\r\n"), +PORT_DESC("link 87/tcp ttylink\r\n"), +PORT_DESC("kerberos 88/tcp kerberos5 krb5 kerberos-sec\r\n"), +PORT_DESC("kerberos 88/udp kerberos5 krb5 kerberos-sec\r\n"), +PORT_DESC("supdup 95/tcp\r\n"), +PORT_DESC("hostnames 101/tcp hostname\r\n"), +PORT_DESC("iso-tsap 102/tcp tsap\r\n"), +PORT_DESC("acr-nema 104/tcp dicom\r\n"), +PORT_DESC("acr-nema 104/udp dicom\r\n"), +PORT_DESC("csnet-ns 105/tcp cso-ns\r\n"), +PORT_DESC("csnet-ns 105/udp cso-ns\r\n"), +PORT_DESC("rtelnet 107/tcp\r\n"), +PORT_DESC("rtelnet 107/udp\r\n"), +PORT_DESC("pop2 109/tcp postoffice pop-2 \r\n"), +PORT_DESC("pop2 109/udp pop-2\r\n"), +PORT_DESC("pop3 110/tcp pop-3\r\n"), +PORT_DESC("pop3 110/udp pop-3\r\n"), +PORT_DESC("sunrpc 111/tcp portmapper\r\n"), +PORT_DESC("sunrpc 111/udp portmapper\r\n"), +PORT_DESC("auth 113/tcp authentication tap ident\r\n"), +PORT_DESC("sftp 115/tcp\r\n"), +PORT_DESC("uucp-path 117/tcp\r\n"), +PORT_DESC("nntp 119/tcp readnews untp\r\n"), +PORT_DESC("ntp 123/tcp\r\n"), +PORT_DESC("ntp 123/udp\r\n"), +PORT_DESC("pwdgen 129/tcp\r\n"), +PORT_DESC("pwdgen 129/udp\r\n"), +PORT_DESC("loc-srv 135/tcp epmap\r\n"), +PORT_DESC("loc-srv 135/udp epmap\r\n"), +PORT_DESC("netbios-ns 137/tcp\r\n"), +PORT_DESC("netbios-ns 137/udp\r\n"), +PORT_DESC("netbios-dgm 138/tcp\r\n"), +PORT_DESC("netbios-dgm 138/udp\r\n"), +PORT_DESC("netbios-ssn 139/tcp\r\n"), +PORT_DESC("netbios-ssn 139/udp\r\n"), +PORT_DESC("imap2 143/tcp imap\r\n"), +PORT_DESC("imap2 143/udp imap\r\n"), +PORT_DESC("snmp 161/tcp\r\n"), +PORT_DESC("snmp 161/udp\r\n"), +PORT_DESC("snmp-trap 162/tcp snmptrap\r\n"), +PORT_DESC("snmp-trap 162/udp snmptrap\r\n"), +PORT_DESC("cmip-man 163/tcp\r\n"), +PORT_DESC("cmip-man 163/udp\r\n"), +PORT_DESC("cmip-agent 164/tcp\r\n"), +PORT_DESC("cmip-agent 164/udp\r\n"), +PORT_DESC("mailq 174/tcp\r\n"), +PORT_DESC("mailq 174/udp\r\n"), +PORT_DESC("xdmcp 177/tcp\r\n"), +PORT_DESC("xdmcp 177/udp\r\n"), +PORT_DESC("nextstep 178/tcp NeXTStep NextStep\r\n"), +PORT_DESC("nextstep 178/udp NeXTStep NextStep\r\n"), +PORT_DESC("bgp 179/tcp\r\n"), +PORT_DESC("bgp 179/udp\r\n"), +PORT_DESC("prospero 191/tcp\r\n"), +PORT_DESC("prospero 191/udp\r\n"), +PORT_DESC("irc 194/tcp\r\n"), +PORT_DESC("irc 194/udp\r\n"), +PORT_DESC("smux 199/tcp\r\n"), +PORT_DESC("smux 199/udp\r\n"), +PORT_DESC("at-rtmp 201/tcp\r\n"), +PORT_DESC("at-rtmp 201/udp\r\n"), +PORT_DESC("at-nbp 202/tcp\r\n"), +PORT_DESC("at-nbp 202/udp\r\n"), +PORT_DESC("at-echo 204/tcp\r\n"), +PORT_DESC("at-echo 204/udp\r\n"), +PORT_DESC("at-zis 206/tcp\r\n"), +PORT_DESC("at-zis 206/udp\r\n"), +PORT_DESC("qmtp 209/tcp\r\n"), +PORT_DESC("qmtp 209/udp\r\n"), +PORT_DESC("z3950 210/tcp wais\r\n"), +PORT_DESC("z3950 210/udp wais\r\n"), +PORT_DESC("ipx 213/tcp\r\n"), +PORT_DESC("ipx 213/udp\r\n"), +PORT_DESC("imap3 220/tcp\r\n"), +PORT_DESC("imap3 220/udp\r\n"), +PORT_DESC("pawserv 345/tcp\r\n"), +PORT_DESC("pawserv 345/udp\r\n"), +PORT_DESC("zserv 346/tcp\r\n"), +PORT_DESC("zserv 346/udp\r\n"), +PORT_DESC("fatserv 347/tcp\r\n"), +PORT_DESC("fatserv 347/udp\r\n"), +PORT_DESC("rpc2portmap 369/tcp\r\n"), +PORT_DESC("rpc2portmap 369/udp\r\n"), +PORT_DESC("codaauth2 370/tcp\r\n"), +PORT_DESC("codaauth2 370/udp\r\n"), +PORT_DESC("clearcase 371/tcp Clearcase\r\n"), +PORT_DESC("clearcase 371/udp Clearcase\r\n"), +PORT_DESC("ulistserv 372/tcp\r\n"), +PORT_DESC("ulistserv 372/udp\r\n"), +PORT_DESC("ldap 389/tcp\r\n"), +PORT_DESC("ldap 389/udp\r\n"), +PORT_DESC("imsp 406/tcp\r\n"), +PORT_DESC("imsp 406/udp\r\n"), +PORT_DESC("svrloc 427/tcp\r\n"), +PORT_DESC("svrloc 427/udp\r\n"), +PORT_DESC("https 443/tcp\r\n"), +PORT_DESC("https 443/udp\r\n"), +PORT_DESC("snpp 444/tcp\r\n"), +PORT_DESC("snpp 444/udp\r\n"), +PORT_DESC("microsoft-ds 445/tcp\r\n"), +PORT_DESC("microsoft-ds 445/udp\r\n"), +PORT_DESC("kpasswd 464/tcp\r\n"), +PORT_DESC("kpasswd 464/udp\r\n"), +PORT_DESC("urd 465/tcp ssmtp smtps \r\n"), +PORT_DESC("saft 487/tcp\r\n"), +PORT_DESC("saft 487/udp\r\n"), +PORT_DESC("isakmp 500/tcp\r\n"), +PORT_DESC("isakmp 500/udp\r\n"), +PORT_DESC("rtsp 554/tcp\r\n"), +PORT_DESC("rtsp 554/udp\r\n"), +PORT_DESC("nqs 607/tcp\r\n"), +PORT_DESC("nqs 607/udp\r\n"), +PORT_DESC("npmp-local 610/tcp dqs313_qmaster\r\n"), +PORT_DESC("npmp-local 610/udp dqs313_qmaster\r\n"), +PORT_DESC("npmp-gui 611/tcp dqs313_execd\r\n"), +PORT_DESC("npmp-gui 611/udp dqs313_execd\r\n"), +PORT_DESC("hmmp-ind 612/tcp dqs313_intercell\r\n"), +PORT_DESC("hmmp-ind 612/udp dqs313_intercell\r\n"), +PORT_DESC("asf-rmcp 623/udp\r\n"), +PORT_DESC("qmqp 628/tcp\r\n"), +PORT_DESC("qmqp 628/udp\r\n"), +PORT_DESC("ipp 631/tcp\r\n"), +PORT_DESC("ipp 631/udp\r\n"), +PORT_DESC("exec 512/tcp\r\n"), +PORT_DESC("biff 512/udp comsat\r\n"), +PORT_DESC("login 513/tcp\r\n"), +PORT_DESC("who 513/udp whod\r\n"), +PORT_DESC("shell 514/tcp cmd\r\n"), +PORT_DESC("syslog 514/udp\r\n"), +PORT_DESC("printer 515/tcp spooler\r\n"), +PORT_DESC("talk 517/udp\r\n"), +PORT_DESC("ntalk 518/udp\r\n"), +PORT_DESC("route 520/udp router routed\r\n"), +PORT_DESC("timed 525/udp timeserver\r\n"), +PORT_DESC("tempo 526/tcp newdate\r\n"), +PORT_DESC("courier 530/tcp rpc\r\n"), +PORT_DESC("conference 531/tcp chat\r\n"), +PORT_DESC("netnews 532/tcp readnews\r\n"), +PORT_DESC("netwall 533/udp\r\n"), +PORT_DESC("gdomap 538/tcp\r\n"), +PORT_DESC("gdomap 538/udp\r\n"), +PORT_DESC("uucp 540/tcp uucpd\r\n"), +PORT_DESC("klogin 543/tcp\r\n"), +PORT_DESC("kshell 544/tcp krcmd\r\n"), +PORT_DESC("dhcpv6-client 546/tcp\r\n"), +PORT_DESC("dhcpv6-client 546/udp\r\n"), +PORT_DESC("dhcpv6-server 547/tcp\r\n"), +PORT_DESC("dhcpv6-server 547/udp\r\n"), +PORT_DESC("afpovertcp 548/tcp\r\n"), +PORT_DESC("afpovertcp 548/udp\r\n"), +PORT_DESC("idfp 549/tcp\r\n"), +PORT_DESC("idfp 549/udp\r\n"), +PORT_DESC("remotefs 556/tcp rfs_server rfs\r\n"), +PORT_DESC("nntps 563/tcp snntp\r\n"), +PORT_DESC("nntps 563/udp snntp\r\n"), +PORT_DESC("submission 587/tcp\r\n"), +PORT_DESC("submission 587/udp\r\n"), +PORT_DESC("ldaps 636/tcp\r\n"), +PORT_DESC("ldaps 636/udp\r\n"), +PORT_DESC("tinc 655/tcp\r\n"), +PORT_DESC("tinc 655/udp\r\n"), +PORT_DESC("silc 706/tcp\r\n"), +PORT_DESC("silc 706/udp\r\n"), +PORT_DESC("kerberos-adm 749/tcp\r\n"), +PORT_DESC("webster 765/tcp\r\n"), +PORT_DESC("webster 765/udp\r\n"), +PORT_DESC("rsync 873/tcp\r\n"), +PORT_DESC("rsync 873/udp\r\n"), +PORT_DESC("ftps-data 989/tcp\r\n"), +PORT_DESC("ftps 990/tcp\r\n"), +PORT_DESC("telnets 992/tcp\r\n"), +PORT_DESC("telnets 992/udp\r\n"), +PORT_DESC("imaps 993/tcp\r\n"), +PORT_DESC("imaps 993/udp\r\n"), +PORT_DESC("ircs 994/tcp\r\n"), +PORT_DESC("ircs 994/udp\r\n"), +PORT_DESC("pop3s 995/tcp\r\n"), +PORT_DESC("pop3s 995/udp\r\n"), +PORT_DESC("socks 1080/tcp\r\n"), +PORT_DESC("socks 1080/udp\r\n"), +PORT_DESC("proofd 1093/tcp\r\n"), +PORT_DESC("proofd 1093/udp\r\n"), +PORT_DESC("rootd 1094/tcp\r\n"), +PORT_DESC("rootd 1094/udp\r\n"), +PORT_DESC("openvpn 1194/tcp\r\n"), +PORT_DESC("openvpn 1194/udp\r\n"), +PORT_DESC("rmiregistry 1099/tcp\r\n"), +PORT_DESC("rmiregistry 1099/udp\r\n"), +PORT_DESC("kazaa 1214/tcp\r\n"), +PORT_DESC("kazaa 1214/udp\r\n"), +PORT_DESC("nessus 1241/tcp\r\n"), +PORT_DESC("nessus 1241/udp\r\n"), +PORT_DESC("lotusnote 1352/tcp lotusnotes\r\n"), +PORT_DESC("lotusnote 1352/udp lotusnotes\r\n"), +PORT_DESC("ms-sql-s 1433/tcp\r\n"), +PORT_DESC("ms-sql-s 1433/udp\r\n"), +PORT_DESC("ms-sql-m 1434/tcp\r\n"), +PORT_DESC("ms-sql-m 1434/udp\r\n"), +PORT_DESC("ingreslock 1524/tcp\r\n"), +PORT_DESC("ingreslock 1524/udp\r\n"), +PORT_DESC("prospero-np 1525/tcp\r\n"), +PORT_DESC("prospero-np 1525/udp\r\n"), +PORT_DESC("datametrics 1645/tcp old-radius\r\n"), +PORT_DESC("datametrics 1645/udp old-radius\r\n"), +PORT_DESC("sa-msg-port 1646/tcp old-radacct\r\n"), +PORT_DESC("sa-msg-port 1646/udp old-radacct\r\n"), +PORT_DESC("kermit 1649/tcp\r\n"), +PORT_DESC("kermit 1649/udp\r\n"), +PORT_DESC("groupwise 1677/tcp\r\n"), +PORT_DESC("groupwise 1677/udp\r\n"), +PORT_DESC("l2f 1701/tcp l2tp\r\n"), +PORT_DESC("l2f 1701/udp l2tp\r\n"), +PORT_DESC("radius 1812/tcp\r\n"), +PORT_DESC("radius 1812/udp\r\n"), +PORT_DESC("radius-acct 1813/tcp radacct\r\n"), +PORT_DESC("radius-acct 1813/udp radacct\r\n"), +PORT_DESC("msnp 1863/tcp\r\n"), +PORT_DESC("msnp 1863/udp\r\n"), +PORT_DESC("unix-status 1957/tcp\r\n"), +PORT_DESC("log-server 1958/tcp\r\n"), +PORT_DESC("remoteping 1959/tcp\r\n"), +PORT_DESC("cisco-sccp 2000/tcp\r\n"), +PORT_DESC("cisco-sccp 2000/udp\r\n"), +PORT_DESC("search 2010/tcp ndtp\r\n"), +PORT_DESC("pipe-server 2010/tcp pipe_server\r\n"), +PORT_DESC("nfs 2049/tcp\r\n"), +PORT_DESC("nfs 2049/udp\r\n"), +PORT_DESC("gnunet 2086/tcp\r\n"), +PORT_DESC("gnunet 2086/udp\r\n"), +PORT_DESC("rtcm-sc104 2101/tcp\r\n"), +PORT_DESC("rtcm-sc104 2101/udp\r\n"), +PORT_DESC("gsigatekeeper 2119/tcp\r\n"), +PORT_DESC("gsigatekeeper 2119/udp\r\n"), +PORT_DESC("gris 2135/tcp\r\n"), +PORT_DESC("gris 2135/udp\r\n"), +PORT_DESC("cvspserver 2401/tcp\r\n"), +PORT_DESC("cvspserver 2401/udp\r\n"), +PORT_DESC("venus 2430/tcp\r\n"), +PORT_DESC("venus 2430/udp\r\n"), +PORT_DESC("venus-se 2431/tcp\r\n"), +PORT_DESC("venus-se 2431/udp\r\n"), +PORT_DESC("codasrv 2432/tcp\r\n"), +PORT_DESC("codasrv 2432/udp\r\n"), +PORT_DESC("codasrv-se 2433/tcp\r\n"), +PORT_DESC("codasrv-se 2433/udp\r\n"), +PORT_DESC("mon 2583/tcp\r\n"), +PORT_DESC("mon 2583/udp\r\n"), +PORT_DESC("dict 2628/tcp\r\n"), +PORT_DESC("dict 2628/udp\r\n"), +PORT_DESC("f5-globalsite 2792/tcp\r\n"), +PORT_DESC("f5-globalsite 2792/udp\r\n"), +PORT_DESC("gsiftp 2811/tcp\r\n"), +PORT_DESC("gsiftp 2811/udp\r\n"), +PORT_DESC("gpsd 2947/tcp\r\n"), +PORT_DESC("gpsd 2947/udp\r\n"), +PORT_DESC("gds-db 3050/tcp gds_db\r\n"), +PORT_DESC("gds-db 3050/udp gds_db\r\n"), +PORT_DESC("icpv2 3130/tcp icp\r\n"), +PORT_DESC("icpv2 3130/udp icp\r\n"), +PORT_DESC("iscsi-target 3260/tcp\r\n"), +PORT_DESC("mysql 3306/tcp\r\n"), +PORT_DESC("mysql 3306/udp\r\n"), +PORT_DESC("nut 3493/tcp\r\n"), +PORT_DESC("nut 3493/udp\r\n"), +PORT_DESC("distcc 3632/tcp\r\n"), +PORT_DESC("distcc 3632/udp\r\n"), +PORT_DESC("daap 3689/tcp\r\n"), +PORT_DESC("daap 3689/udp\r\n"), +PORT_DESC("svn 3690/tcp subversion\r\n"), +PORT_DESC("svn 3690/udp subversion\r\n"), +PORT_DESC("suucp 4031/tcp\r\n"), +PORT_DESC("suucp 4031/udp\r\n"), +PORT_DESC("sysrqd 4094/tcp\r\n"), +PORT_DESC("sysrqd 4094/udp\r\n"), +PORT_DESC("sieve 4190/tcp\r\n"), +PORT_DESC("epmd 4369/tcp\r\n"), +PORT_DESC("epmd 4369/udp\r\n"), +PORT_DESC("remctl 4373/tcp\r\n"), +PORT_DESC("remctl 4373/udp\r\n"), +PORT_DESC("f5-iquery 4353/tcp\r\n"), +PORT_DESC("f5-iquery 4353/udp\r\n"), +PORT_DESC("ipsec-nat-t 4500/udp\r\n"), +PORT_DESC("iax 4569/tcp\r\n"), +PORT_DESC("iax 4569/udp\r\n"), +PORT_DESC("mtn 4691/tcp\r\n"), +PORT_DESC("mtn 4691/udp\r\n"), +PORT_DESC("radmin-port 4899/tcp\r\n"), +PORT_DESC("radmin-port 4899/udp\r\n"), +PORT_DESC("rfe 5002/udp\r\n"), +PORT_DESC("rfe 5002/tcp\r\n"), +PORT_DESC("mmcc 5050/tcp\r\n"), +PORT_DESC("mmcc 5050/udp\r\n"), +PORT_DESC("sip 5060/tcp\r\n"), +PORT_DESC("sip 5060/udp\r\n"), +PORT_DESC("sip-tls 5061/tcp\r\n"), +PORT_DESC("sip-tls 5061/udp\r\n"), +PORT_DESC("aol 5190/tcp\r\n"), +PORT_DESC("aol 5190/udp\r\n"), +PORT_DESC("xmpp-client 5222/tcp jabber-client\r\n"), +PORT_DESC("xmpp-client 5222/udp jabber-client\r\n"), +PORT_DESC("xmpp-server 5269/tcp jabber-server\r\n"), +PORT_DESC("xmpp-server 5269/udp jabber-server\r\n"), +PORT_DESC("cfengine 5308/tcp\r\n"), +PORT_DESC("cfengine 5308/udp\r\n"), +PORT_DESC("mdns 5353/tcp\r\n"), +PORT_DESC("mdns 5353/udp\r\n"), +PORT_DESC("postgresql 5432/tcp postgres\r\n"), +PORT_DESC("postgresql 5432/udp postgres\r\n"), +PORT_DESC("freeciv 5556/tcp rptp\r\n"), +PORT_DESC("freeciv 5556/udp\r\n"), +PORT_DESC("amqps 5671/tcp\r\n"), +PORT_DESC("amqp 5672/tcp\r\n"), +PORT_DESC("amqp 5672/udp\r\n"), +PORT_DESC("amqp 5672/sctp\r\n"), +PORT_DESC("ggz 5688/tcp\r\n"), +PORT_DESC("ggz 5688/udp\r\n"), +PORT_DESC("x11 6000/tcp x11-0\r\n"), +PORT_DESC("x11 6000/udp x11-0\r\n"), +PORT_DESC("x11-1 6001/tcp\r\n"), +PORT_DESC("x11-1 6001/udp\r\n"), +PORT_DESC("x11-2 6002/tcp\r\n"), +PORT_DESC("x11-2 6002/udp\r\n"), +PORT_DESC("x11-3 6003/tcp\r\n"), +PORT_DESC("x11-3 6003/udp\r\n"), +PORT_DESC("x11-4 6004/tcp\r\n"), +PORT_DESC("x11-4 6004/udp\r\n"), +PORT_DESC("x11-5 6005/tcp\r\n"), +PORT_DESC("x11-5 6005/udp\r\n"), +PORT_DESC("x11-6 6006/tcp\r\n"), +PORT_DESC("x11-6 6006/udp\r\n"), +PORT_DESC("x11-7 6007/tcp\r\n"), +PORT_DESC("x11-7 6007/udp\r\n"), +PORT_DESC("gnutella-svc 6346/tcp\r\n"), +PORT_DESC("gnutella-svc 6346/udp\r\n"), +PORT_DESC("gnutella-rtr 6347/tcp\r\n"), +PORT_DESC("gnutella-rtr 6347/udp\r\n"), +PORT_DESC("sge-qmaster 6444/tcp sge_qmaster\r\n"), +PORT_DESC("sge-qmaster 6444/udp sge_qmaster\r\n"), +PORT_DESC("sge-execd 6445/tcp sge_execd\r\n"), +PORT_DESC("sge-execd 6445/udp sge_execd\r\n"), +PORT_DESC("mysql-proxy 6446/tcp\r\n"), +PORT_DESC("mysql-proxy 6446/udp\r\n"), +PORT_DESC("afs3-fileserver 7000/tcp bbs\r\n"), +PORT_DESC("afs3-fileserver 7000/udp bbs\r\n"), +PORT_DESC("afs3-callback 7001/tcp\r\n"), +PORT_DESC("afs3-callback 7001/udp\r\n"), +PORT_DESC("afs3-prserver 7002/tcp\r\n"), +PORT_DESC("afs3-prserver 7002/udp\r\n"), +PORT_DESC("afs3-vlserver 7003/tcp\r\n"), +PORT_DESC("afs3-vlserver 7003/udp\r\n"), +PORT_DESC("afs3-kaserver 7004/tcp\r\n"), +PORT_DESC("afs3-kaserver 7004/udp\r\n"), +PORT_DESC("afs3-volser 7005/tcp\r\n"), +PORT_DESC("afs3-volser 7005/udp\r\n"), +PORT_DESC("afs3-errors 7006/tcp\r\n"), +PORT_DESC("afs3-errors 7006/udp\r\n"), +PORT_DESC("afs3-bos 7007/tcp\r\n"), +PORT_DESC("afs3-bos 7007/udp\r\n"), +PORT_DESC("afs3-update 7008/tcp\r\n"), +PORT_DESC("afs3-update 7008/udp\r\n"), +PORT_DESC("afs3-rmtsys 7009/tcp\r\n"), +PORT_DESC("afs3-rmtsys 7009/udp\r\n"), +PORT_DESC("font-service 7100/tcp xfs\r\n"), +PORT_DESC("font-service 7100/udp xfs\r\n"), +PORT_DESC("http-alt 8080/tcp webcache\r\n"), +PORT_DESC("http-alt 8080/udp\r\n"), +PORT_DESC("bacula-dir 9101/tcp\r\n"), +PORT_DESC("bacula-dir 9101/udp\r\n"), +PORT_DESC("bacula-fd 9102/tcp\r\n"), +PORT_DESC("bacula-fd 9102/udp\r\n"), +PORT_DESC("bacula-sd 9103/tcp\r\n"), +PORT_DESC("bacula-sd 9103/udp\r\n"), +PORT_DESC("xmms2 9667/tcp\r\n"), +PORT_DESC("xmms2 9667/udp\r\n"), +PORT_DESC("nbd 10809/tcp\r\n"), +PORT_DESC("zabbix-agent 10050/tcp\r\n"), +PORT_DESC("zabbix-agent 10050/udp\r\n"), +PORT_DESC("zabbix-trapper 10051/tcp\r\n"), +PORT_DESC("zabbix-trapper 10051/udp\r\n"), +PORT_DESC("amanda 10080/tcp\r\n"), +PORT_DESC("amanda 10080/udp\r\n"), +PORT_DESC("dicom 11112/tcp\r\n"), +PORT_DESC("hkp 11371/tcp\r\n"), +PORT_DESC("hkp 11371/udp\r\n"), +PORT_DESC("bprd 13720/tcp\r\n"), +PORT_DESC("bprd 13720/udp\r\n"), +PORT_DESC("bpdbm 13721/tcp\r\n"), +PORT_DESC("bpdbm 13721/udp\r\n"), +PORT_DESC("bpjava-msvc 13722/tcp\r\n"), +PORT_DESC("bpjava-msvc 13722/udp\r\n"), +PORT_DESC("vnetd 13724/tcp\r\n"), +PORT_DESC("vnetd 13724/udp\r\n"), +PORT_DESC("bpcd 13782/tcp\r\n"), +PORT_DESC("bpcd 13782/udp\r\n"), +PORT_DESC("vopied 13783/tcp\r\n"), +PORT_DESC("vopied 13783/udp\r\n"), +PORT_DESC("db-lsp 17500/tcp\r\n"), +PORT_DESC("dcap 22125/tcp\r\n"), +PORT_DESC("gsidcap 22128/tcp\r\n"), +PORT_DESC("wnn6 22273/tcp\r\n"), +PORT_DESC("wnn6 22273/udp\r\n"), +PORT_DESC("rtmp 1/ddp\r\n"), +PORT_DESC("nbp 2/ddp\r\n"), +PORT_DESC("echo 4/ddp\r\n"), +PORT_DESC("zip 6/ddp\r\n"), +PORT_DESC("kerberos4 750/udp kerberos-iv kdc\r\n"), +PORT_DESC("kerberos4 750/tcp kerberos-iv kdc\r\n"), +PORT_DESC("kerberos-master 751/udp kerberos_master\r\n"), +PORT_DESC("kerberos-master 751/tcp\r\n"), +PORT_DESC("passwd-server 752/udp passwd_server\r\n"), +PORT_DESC("krb-prop 754/tcp krb_prop krb5_prop hprop\r\n"), +PORT_DESC("krbupdate 760/tcp kreg\r\n"), +PORT_DESC("swat 901/tcp\r\n"), +PORT_DESC("kpop 1109/tcp\r\n"), +PORT_DESC("knetd 2053/tcp\r\n"), +PORT_DESC("zephyr-srv 2102/udp\r\n"), +PORT_DESC("zephyr-clt 2103/udp\r\n"), +PORT_DESC("zephyr-hm 2104/udp\r\n"), +PORT_DESC("eklogin 2105/tcp\r\n"), +PORT_DESC("kx 2111/tcp\r\n"), +PORT_DESC("iprop 2121/tcp\r\n"), +PORT_DESC("supfilesrv 871/tcp\r\n"), +PORT_DESC("supfiledbg 1127/tcp\r\n"), +PORT_DESC("linuxconf 98/tcp\r\n"), +PORT_DESC("poppassd 106/tcp\r\n"), +PORT_DESC("poppassd 106/udp\r\n"), +PORT_DESC("moira-db 775/tcp moira_db\r\n"), +PORT_DESC("moira-update 777/tcp moira_update\r\n"), +PORT_DESC("moira-ureg 779/udp moira_ureg\r\n"), +PORT_DESC("spamd 783/tcp\r\n"), +PORT_DESC("omirr 808/tcp omirrd\r\n"), +PORT_DESC("omirr 808/udp omirrd\r\n"), +PORT_DESC("customs 1001/tcp\r\n"), +PORT_DESC("customs 1001/udp\r\n"), +PORT_DESC("skkserv 1178/tcp\r\n"), +PORT_DESC("predict 1210/udp\r\n"), +PORT_DESC("rmtcfg 1236/tcp\r\n"), +PORT_DESC("wipld 1300/tcp\r\n"), +PORT_DESC("xtel 1313/tcp\r\n"), +PORT_DESC("xtelw 1314/tcp\r\n"), +PORT_DESC("support 1529/tcp\r\n"), +PORT_DESC("cfinger 2003/tcp\r\n"), +PORT_DESC("frox 2121/tcp\r\n"), +PORT_DESC("ninstall 2150/tcp\r\n"), +PORT_DESC("ninstall 2150/udp\r\n"), +PORT_DESC("zebrasrv 2600/tcp\r\n"), +PORT_DESC("zebra 2601/tcp\r\n"), +PORT_DESC("ripd 2602/tcp\r\n"), +PORT_DESC("ripngd 2603/tcp\r\n"), +PORT_DESC("ospfd 2604/tcp\r\n"), +PORT_DESC("bgpd 2605/tcp\r\n"), +PORT_DESC("ospf6d 2606/tcp\r\n"), +PORT_DESC("ospfapi 2607/tcp\r\n"), +PORT_DESC("isisd 2608/tcp\r\n"), +PORT_DESC("afbackup 2988/tcp\r\n"), +PORT_DESC("afbackup 2988/udp\r\n"), +PORT_DESC("afmbackup 2989/tcp\r\n"), +PORT_DESC("afmbackup 2989/udp\r\n"), +PORT_DESC("xtell 4224/tcp\r\n"), +PORT_DESC("fax 4557/tcp\r\n"), +PORT_DESC("hylafax 4559/tcp\r\n"), +PORT_DESC("distmp3 4600/tcp\r\n"), +PORT_DESC("munin 4949/tcp lrrd\r\n"), +PORT_DESC("enbd-cstatd 5051/tcp\r\n"), +PORT_DESC("enbd-sstatd 5052/tcp\r\n"), +PORT_DESC("pcrd 5151/tcp\r\n"), +PORT_DESC("noclog 5354/tcp\r\n"), +PORT_DESC("noclog 5354/udp\r\n"), +PORT_DESC("hostmon 5355/tcp\r\n"), +PORT_DESC("hostmon 5355/udp\r\n"), +PORT_DESC("rplay 5555/udp\r\n"), +PORT_DESC("nrpe 5666/tcp\r\n"), +PORT_DESC("nsca 5667/tcp\r\n"), +PORT_DESC("mrtd 5674/tcp\r\n"), +PORT_DESC("bgpsim 5675/tcp\r\n"), +PORT_DESC("canna 5680/tcp\r\n"), +PORT_DESC("syslog-tls 6514/tcp\r\n"), +PORT_DESC("sane-port 6566/tcp sane saned\r\n"), +PORT_DESC("ircd 6667/tcp\r\n"), +PORT_DESC("zope-ftp 8021/tcp\r\n"), +PORT_DESC("tproxy 8081/tcp\r\n"), +PORT_DESC("omniorb 8088/tcp\r\n"), +PORT_DESC("omniorb 8088/udp\r\n"), +PORT_DESC("clc-build-daemon 8990/tcp\r\n"), +PORT_DESC("xinetd 9098/tcp\r\n"), +PORT_DESC("mandelspawn 9359/udp mandelbrot\r\n"), +PORT_DESC("git 9418/tcp\r\n"), +PORT_DESC("zope 9673/tcp\r\n"), +PORT_DESC("webmin 10000/tcp\r\n"), +PORT_DESC("kamanda 10081/tcp\r\n"), +PORT_DESC("kamanda 10081/udp\r\n"), +PORT_DESC("amandaidx 10082/tcp\r\n"), +PORT_DESC("amidxtape 10083/tcp\r\n"), +PORT_DESC("smsqp 11201/tcp\r\n"), +PORT_DESC("smsqp 11201/udp\r\n"), +PORT_DESC("xpilot 15345/tcp\r\n"), +PORT_DESC("xpilot 15345/udp\r\n"), +PORT_DESC("sgi-cmsd 17001/udp\r\n"), +PORT_DESC("sgi-crsd 17002/udp\r\n"), +PORT_DESC("sgi-gcd 17003/udp\r\n"), +PORT_DESC("sgi-cad 17004/tcp\r\n"), +PORT_DESC("isdnlog 20011/tcp\r\n"), +PORT_DESC("isdnlog 20011/udp\r\n"), +PORT_DESC("vboxd 20012/tcp\r\n"), +PORT_DESC("vboxd 20012/udp\r\n"), +PORT_DESC("binkp 24554/tcp\r\n"), +PORT_DESC("asp 27374/tcp\r\n"), +PORT_DESC("asp 27374/udp\r\n"), +PORT_DESC("csync2 30865/tcp\r\n"), +PORT_DESC("dircproxy 57000/tcp\r\n"), +PORT_DESC("tfido 60177/tcp\r\n"), +PORT_DESC("fido 60179/tcp\r\n"), +#endif // SYSTEM_SERVICES_HEADER \ No newline at end of file diff --git a/porting/linux/user/src/network/getnameinfo.c b/porting/linux/user/src/network/getnameinfo.c index fe32156b290fb60211260d314d05555bcee222f4..36a7fdbb60520021559d4431d06b8f9e0e1eda30 100644 --- a/porting/linux/user/src/network/getnameinfo.c +++ b/porting/linux/user/src/network/getnameinfo.c @@ -21,6 +21,14 @@ extern char fixed_hosts[FIXED_HOSTS_MAX_LENGTH][FIXED_HOSTS_STR_MAX_LENGTH]; +char *g_fixedServices[] = { +#define PORT_DESC(a) a +#include "services.h" +#undef PORT_DESC(a) +}; + +#define FIXED_SERVICES_COUNT (sizeof(g_fixedServices) / sizeof(char*)) + static char *itoa(char *p, unsigned x) { p += 3*sizeof(int); *--p = 0; @@ -103,14 +111,27 @@ static void reverse_hosts(char *buf, const unsigned char *a, unsigned scopeid, i } } +static inline int get_services_str(char *line, int length, FILE *f, int *indexPtr) +{ + if (f) { + return fgets(line, sizeof line, f); + } + if (*indexPtr < FIXED_SERVICES_COUNT) { + memcpy(line, g_fixedServices[*indexPtr], strlen(g_fixedServices[*indexPtr])); + (*indexPtr)++; + return 1; + } + return NULL; +} + static void reverse_services(char *buf, int port, int dgram) { unsigned long svport; char line[128], *p, *z; unsigned char _buf[1032]; FILE _f, *f = __fopen_rb_ca("/etc/services", &_f, _buf, sizeof _buf); - if (!f) return; - while (fgets(line, sizeof line, f)) { + int indexPtr = 0; + while (indexPtr < FIXED_SERVICES_COUNT && get_services_str(line, sizeof line, f, &indexPtr)) { if ((p=strchr(line, '#'))) *p++='\n', *p=0; for (p=line; *p && !isspace(*p); p++); @@ -126,7 +147,9 @@ static void reverse_services(char *buf, int port, int dgram) memcpy(buf, line, p-line); break; } - __fclose_ca(f); + if (f) { + __fclose_ca(f); + } } static int dns_parse_callback(void *c, int rr, const void *data, int len, const void *packet) @@ -219,3 +242,5 @@ int getnameinfo(const struct sockaddr *restrict sa, socklen_t sl, return 0; } + +#undef FIXED_SERVICES_COUNT \ No newline at end of file diff --git a/porting/linux/user/src/network/lookup_serv.c b/porting/linux/user/src/network/lookup_serv.c new file mode 100644 index 0000000000000000000000000000000000000000..d451fb23adffb2d7fa6a646576f023d99f0932b2 --- /dev/null +++ b/porting/linux/user/src/network/lookup_serv.c @@ -0,0 +1,131 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "lookup.h" +#include "stdio_impl.h" + +char *g_fixedServicesLookup[] = { +#define PORT_DESC(a) a +#include "services.h" +#undef PORT_DESC(a) +}; + +#define FIXED_SERVICES_COUNT (sizeof(g_fixedServicesLookup) / sizeof(char*)) + +static inline int get_services_str(char *line, int length, FILE *f, int *indexPtr) +{ + if (f) { + return fgets(line, sizeof line, f); + } + if (*indexPtr < FIXED_SERVICES_COUNT) { + memcpy(line, g_fixedServicesLookup[*indexPtr], strlen(g_fixedServicesLookup[*indexPtr])); + (*indexPtr)++; + return 1; + } + return NULL; +} + +int __lookup_serv(struct service buf[static MAXSERVS], const char *name, int proto, int socktype, int flags) +{ + char line[128]; + int cnt = 0; + char *p, *z = ""; + unsigned long port = 0; + + switch (socktype) { + case SOCK_STREAM: + switch (proto) { + case 0: + proto = IPPROTO_TCP; + case IPPROTO_TCP: + break; + default: + return EAI_SERVICE; + } + break; + case SOCK_DGRAM: + switch (proto) { + case 0: + proto = IPPROTO_UDP; + case IPPROTO_UDP: + break; + default: + return EAI_SERVICE; + } + case 0: + break; + default: + if (name) return EAI_SERVICE; + buf[0].port = 0; + buf[0].proto = proto; + buf[0].socktype = socktype; + return 1; + } + + if (name) { + if (!*name) return EAI_SERVICE; + port = strtoul(name, &z, 10); + } + if (!*z) { + if (port > 65535) return EAI_SERVICE; + if (proto != IPPROTO_UDP) { + buf[cnt].port = port; + buf[cnt].socktype = SOCK_STREAM; + buf[cnt++].proto = IPPROTO_TCP; + } + if (proto != IPPROTO_TCP) { + buf[cnt].port = port; + buf[cnt].socktype = SOCK_DGRAM; + buf[cnt++].proto = IPPROTO_UDP; + } + return cnt; + } + + if (flags & AI_NUMERICSERV) return EAI_NONAME; + + size_t l = strlen(name); + + unsigned char _buf[1032]; + FILE _f, *f = __fopen_rb_ca("/etc/services", &_f, _buf, sizeof _buf); + int indexPtr = 0; + while (indexPtr < FIXED_SERVICES_COUNT && get_services_str(line, sizeof line, f, &indexPtr)) { + if ((p=strchr(line, '#'))) *p++='\n', *p=0; + + /* Find service name */ + for(p=line; (p=strstr(p, name)); p++) { + if (p>line && !isspace(p[-1])) continue; + if (p[l] && !isspace(p[l])) continue; + break; + } + if (!p) continue; + + /* Skip past canonical name at beginning of line */ + for (p=line; *p && !isspace(*p); p++); + + port = strtoul(p, &z, 10); + if (port > 65535 || z==p) continue; + if (!strncmp(z, "/udp", 4)) { + if (proto == IPPROTO_TCP) continue; + buf[cnt].port = port; + buf[cnt].socktype = SOCK_DGRAM; + buf[cnt++].proto = IPPROTO_UDP; + } + if (!strncmp(z, "/tcp", 4)) { + if (proto == IPPROTO_UDP) continue; + buf[cnt].port = port; + buf[cnt].socktype = SOCK_STREAM; + buf[cnt++].proto = IPPROTO_TCP; + } + } + if (f) { + __fclose_ca(f); + } + return cnt > 0 ? cnt : EAI_SERVICE; +} + +#undef FIXED_SERVICES_COUNT \ No newline at end of file