ehrlich@psuvax1.psu.edu (Dan Ehrlich) (08/21/87)
After pulling my hair out for a while I discovered that although /usr/include/netdb.h indicates that the s_port field of a servent is an int, not even an u_long, the routine getservent was still assuming this field to be a u_short. Below is the patch to correct this oversight. RCS file: RCS/getservent.c,v retrieving revision 1.1 diff -c -r1.1 getservent.c *** /tmp/,RCSt1012010 Thu Aug 20 23:55:07 1987 --- getservent.c Thu Aug 20 23:53:35 1987 *************** *** 71,77 **** if (cp == NULL) goto again; *cp++ = '\0'; ! serv.s_port = htons((u_short)atoi(p)); serv.s_proto = cp; q = serv.s_aliases = serv_aliases; cp = any(cp, " \t"); --- 71,77 ---- if (cp == NULL) goto again; *cp++ = '\0'; ! serv.s_port = htonl((u_long)atoi(p)); serv.s_proto = cp; q = serv.s_aliases = serv_aliases; cp = any(cp, " \t");
bostic@ucbvax.BERKELEY.EDU (Keith Bostic) (08/25/87)
In article <2861@psuvax1.psu.edu>, ehrlich@psuvax1.psu.edu (Dan Ehrlich) writes: > ... although /usr/include/netdb.h indicates that the s_port field of a > servent is an int, not even an u_long, the routine getservent was still > assuming this field to be a u_short. Below is the patch to correct > this oversight. The problem with this fix is that it gets placed into the port field of a sockaddr_in, which is a u_short. With the posted fix, all port numbers will be set to zero. Do not apply the fix.