Deleted Added
full compact
res_mkupdate.c (158787) res_mkupdate.c (170244)
1/*
2 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (c) 1996-1999 by Internet Software Consortium.
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
15 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
1/*
2 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (c) 1996-1999 by Internet Software Consortium.
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
15 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18/*
18/*! \file
19 * \brief
19 * Based on the Dynamic DNS reference implementation by Viraj Bais
20 * Based on the Dynamic DNS reference implementation by Viraj Bais
20 * <viraj_bais@ccm.fm.intel.com>
21 * &lt;viraj_bais@ccm.fm.intel.com>
21 */
22
23#if !defined(lint) && !defined(SABER)
22 */
23
24#if !defined(lint) && !defined(SABER)
24static const char rcsid[] = "$Id: res_mkupdate.c,v 1.1.2.1.4.5 2005/10/14 05:43:47 marka Exp $";
25static const char rcsid[] = "$Id: res_mkupdate.c,v 1.4.18.4 2005/10/14 05:44:12 marka Exp $";
25#endif /* not lint */
26#include <sys/cdefs.h>
26#endif /* not lint */
27#include <sys/cdefs.h>
27__FBSDID("$FreeBSD: head/lib/libc/resolv/res_mkupdate.c 158787 2006-05-21 11:19:36Z ume $");
28__FBSDID("$FreeBSD: head/lib/libc/resolv/res_mkupdate.c 170244 2007-06-03 17:20:27Z ume $");
28
29#include "port_before.h"
30
31#include <sys/types.h>
32#include <sys/param.h>
33
34#include <netinet/in.h>
35#include <arpa/nameser.h>

--- 33 unchanged lines hidden (view full) ---

69static
70#endif
71int res_protocolnumber(const char *);
72#ifdef _LIBC
73static
74#endif
75int res_servicenumber(const char *);
76
29
30#include "port_before.h"
31
32#include <sys/types.h>
33#include <sys/param.h>
34
35#include <netinet/in.h>
36#include <arpa/nameser.h>

--- 33 unchanged lines hidden (view full) ---

70static
71#endif
72int res_protocolnumber(const char *);
73#ifdef _LIBC
74static
75#endif
76int res_servicenumber(const char *);
77
77/*
78/*%
78 * Form update packets.
79 * Returns the size of the resulting packet if no error
79 * Form update packets.
80 * Returns the size of the resulting packet if no error
81 *
80 * On error,
82 * On error,
81 * returns -1 if error in reading a word/number in rdata
83 * returns
84 *\li -1 if error in reading a word/number in rdata
82 * portion for update packets
85 * portion for update packets
83 * -2 if length of buffer passed is insufficient
84 * -3 if zone section is not the first section in
86 *\li -2 if length of buffer passed is insufficient
87 *\li -3 if zone section is not the first section in
85 * the linked list, or section order has a problem
88 * the linked list, or section order has a problem
86 * -4 on a number overflow
87 * -5 unknown operation or no records
89 *\li -4 on a number overflow
90 *\li -5 unknown operation or no records
88 */
89int
90res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) {
91 ns_updrec *rrecp_start = rrecp_in;
92 HEADER *hp;
93 u_char *cp, *sp2, *startp, *endp;
94 int n, i, soanum, multiline;
95 ns_updrec *rrecp;

--- 103 unchanged lines hidden (view full) ---

199 PUTSHORT(rclass, cp);
200 if (section == S_ZONE) {
201 if (numrrs != 1 || rrecp->r_type != T_SOA)
202 return (-3);
203 continue;
204 }
205 ShrinkBuffer(INT32SZ + INT16SZ);
206 PUTLONG(rttl, cp);
91 */
92int
93res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) {
94 ns_updrec *rrecp_start = rrecp_in;
95 HEADER *hp;
96 u_char *cp, *sp2, *startp, *endp;
97 int n, i, soanum, multiline;
98 ns_updrec *rrecp;

--- 103 unchanged lines hidden (view full) ---

202 PUTSHORT(rclass, cp);
203 if (section == S_ZONE) {
204 if (numrrs != 1 || rrecp->r_type != T_SOA)
205 return (-3);
206 continue;
207 }
208 ShrinkBuffer(INT32SZ + INT16SZ);
209 PUTLONG(rttl, cp);
207 sp2 = cp; /* save pointer to length byte */
210 sp2 = cp; /*%< save pointer to length byte */
208 cp += INT16SZ;
209 if (rrecp->r_size == 0) {
210 if (section == S_UPDATE && rclass != C_ANY)
211 return (-1);
212 else {
213 PUTSHORT(0, sp2);
214 continue;
215 }

--- 189 unchanged lines hidden (view full) ---

405 return (-1);
406 ShrinkBuffer(n+1);
407 *cp++ = n;
408 memcpy(cp, buf2, n);
409 cp += n;
410 }
411 break;
412 case T_X25:
211 cp += INT16SZ;
212 if (rrecp->r_size == 0) {
213 if (section == S_UPDATE && rclass != C_ANY)
214 return (-1);
215 else {
216 PUTSHORT(0, sp2);
217 continue;
218 }

--- 189 unchanged lines hidden (view full) ---

408 return (-1);
409 ShrinkBuffer(n+1);
410 *cp++ = n;
411 memcpy(cp, buf2, n);
412 cp += n;
413 }
414 break;
415 case T_X25:
413 /* RFC 1183 */
416 /* RFC1183 */
414 if ((n = getstr_str(buf2, sizeof buf2, &startp,
415 endp)) < 0)
416 return (-1);
417 if (n > 255)
418 return (-1);
419 ShrinkBuffer(n+1);
420 *cp++ = n;
421 memcpy(cp, buf2, n);
422 cp += n;
423 break;
424 case T_ISDN:
417 if ((n = getstr_str(buf2, sizeof buf2, &startp,
418 endp)) < 0)
419 return (-1);
420 if (n > 255)
421 return (-1);
422 ShrinkBuffer(n+1);
423 *cp++ = n;
424 memcpy(cp, buf2, n);
425 cp += n;
426 break;
427 case T_ISDN:
425 /* RFC 1183 */
428 /* RFC1183 */
426 if ((n = getstr_str(buf2, sizeof buf2, &startp,
427 endp)) < 0)
428 return (-1);
429 if ((n > 255) || (n == 0))
430 return (-1);
431 ShrinkBuffer(n+1);
432 *cp++ = n;
433 memcpy(cp, buf2, n);

--- 288 unchanged lines hidden (view full) ---

722
723 hp->qdcount = htons(counts[0]);
724 hp->ancount = htons(counts[1]);
725 hp->nscount = htons(counts[2]);
726 hp->arcount = htons(counts[3]);
727 return (cp - buf);
728}
729
429 if ((n = getstr_str(buf2, sizeof buf2, &startp,
430 endp)) < 0)
431 return (-1);
432 if ((n > 255) || (n == 0))
433 return (-1);
434 ShrinkBuffer(n+1);
435 *cp++ = n;
436 memcpy(cp, buf2, n);

--- 288 unchanged lines hidden (view full) ---

725
726 hp->qdcount = htons(counts[0]);
727 hp->ancount = htons(counts[1]);
728 hp->nscount = htons(counts[2]);
729 hp->arcount = htons(counts[3]);
730 return (cp - buf);
731}
732
730/*
733/*%
731 * Get a whitespace delimited word from a string (not file)
732 * into buf. modify the start pointer to point after the
733 * word in the string.
734 */
735static int
736getword_str(char *buf, int size, u_char **startpp, u_char *endp) {
737 char *cp;
738 int c;
739
740 for (cp = buf; *startpp <= endp; ) {
741 c = **startpp;
742 if (isspace(c) || c == '\0') {
734 * Get a whitespace delimited word from a string (not file)
735 * into buf. modify the start pointer to point after the
736 * word in the string.
737 */
738static int
739getword_str(char *buf, int size, u_char **startpp, u_char *endp) {
740 char *cp;
741 int c;
742
743 for (cp = buf; *startpp <= endp; ) {
744 c = **startpp;
745 if (isspace(c) || c == '\0') {
743 if (cp != buf) /* trailing whitespace */
746 if (cp != buf) /*%< trailing whitespace */
744 break;
747 break;
745 else { /* leading whitespace */
748 else { /*%< leading whitespace */
746 (*startpp)++;
747 continue;
748 }
749 }
750 (*startpp)++;
751 if (cp >= buf+size-1)
752 break;
753 *cp++ = (u_char)c;
754 }
755 *cp = '\0';
756 return (cp != buf);
757}
758
749 (*startpp)++;
750 continue;
751 }
752 }
753 (*startpp)++;
754 if (cp >= buf+size-1)
755 break;
756 *cp++ = (u_char)c;
757 }
758 *cp = '\0';
759 return (cp != buf);
760}
761
759/*
762/*%
760 * get a white spae delimited string from memory. Process quoted strings
763 * get a white spae delimited string from memory. Process quoted strings
761 * and \DDD escapes. Return length or -1 on error. Returned string may
764 * and \\DDD escapes. Return length or -1 on error. Returned string may
762 * contain nulls.
763 */
764static char digits[] = "0123456789";
765static int
766getstr_str(char *buf, int size, u_char **startpp, u_char *endp) {
767 char *cp;
768 int c, c1 = 0;
769 int inquote = 0;

--- 60 unchanged lines hidden (view full) ---

830 *cp++ = (u_char)c;
831 (*startpp)++;
832 }
833 }
834 done:
835 *cp = '\0';
836 return ((cp == buf)? (seen_quote? 0: -1): (cp - buf));
837}
765 * contain nulls.
766 */
767static char digits[] = "0123456789";
768static int
769getstr_str(char *buf, int size, u_char **startpp, u_char *endp) {
770 char *cp;
771 int c, c1 = 0;
772 int inquote = 0;

--- 60 unchanged lines hidden (view full) ---

833 *cp++ = (u_char)c;
834 (*startpp)++;
835 }
836 }
837 done:
838 *cp = '\0';
839 return ((cp == buf)? (seen_quote? 0: -1): (cp - buf));
840}
838/*
841
842/*%
839 * Get a whitespace delimited base 16 number from a string (not file) into buf
840 * update the start pointer to point after the number in the string.
841 */
842static int
843gethexnum_str(u_char **startpp, u_char *endp) {
844 int c, n;
845 int seendigit = 0;
846 int m = 0;
847
848 if (*startpp + 2 >= endp || strncasecmp((char *)*startpp, "0x", 2) != 0)
849 return getnum_str(startpp, endp);
850 (*startpp)+=2;
851 for (n = 0; *startpp <= endp; ) {
852 c = **startpp;
853 if (isspace(c) || c == '\0') {
843 * Get a whitespace delimited base 16 number from a string (not file) into buf
844 * update the start pointer to point after the number in the string.
845 */
846static int
847gethexnum_str(u_char **startpp, u_char *endp) {
848 int c, n;
849 int seendigit = 0;
850 int m = 0;
851
852 if (*startpp + 2 >= endp || strncasecmp((char *)*startpp, "0x", 2) != 0)
853 return getnum_str(startpp, endp);
854 (*startpp)+=2;
855 for (n = 0; *startpp <= endp; ) {
856 c = **startpp;
857 if (isspace(c) || c == '\0') {
854 if (seendigit) /* trailing whitespace */
858 if (seendigit) /*%< trailing whitespace */
855 break;
859 break;
856 else { /* leading whitespace */
860 else { /*%< leading whitespace */
857 (*startpp)++;
858 continue;
859 }
860 }
861 if (c == ';') {
862 while ((*startpp <= endp) &&
863 ((c = **startpp) != '\n'))
864 (*startpp)++;

--- 13 unchanged lines hidden (view full) ---

878 n = n * 16 + (c - '0');
879 else
880 n = n * 16 + (tolower(c) - 'a' + 10);
881 seendigit = 1;
882 }
883 return (n + m);
884}
885
861 (*startpp)++;
862 continue;
863 }
864 }
865 if (c == ';') {
866 while ((*startpp <= endp) &&
867 ((c = **startpp) != '\n'))
868 (*startpp)++;

--- 13 unchanged lines hidden (view full) ---

882 n = n * 16 + (c - '0');
883 else
884 n = n * 16 + (tolower(c) - 'a' + 10);
885 seendigit = 1;
886 }
887 return (n + m);
888}
889
886/*
890/*%
887 * Get a whitespace delimited base 10 number from a string (not file) into buf
888 * update the start pointer to point after the number in the string.
889 */
890static int
891getnum_str(u_char **startpp, u_char *endp) {
892 int c, n;
893 int seendigit = 0;
894 int m = 0;
895
896 for (n = 0; *startpp <= endp; ) {
897 c = **startpp;
898 if (isspace(c) || c == '\0') {
891 * Get a whitespace delimited base 10 number from a string (not file) into buf
892 * update the start pointer to point after the number in the string.
893 */
894static int
895getnum_str(u_char **startpp, u_char *endp) {
896 int c, n;
897 int seendigit = 0;
898 int m = 0;
899
900 for (n = 0; *startpp <= endp; ) {
901 c = **startpp;
902 if (isspace(c) || c == '\0') {
899 if (seendigit) /* trailing whitespace */
903 if (seendigit) /*%< trailing whitespace */
900 break;
904 break;
901 else { /* leading whitespace */
905 else { /*%< leading whitespace */
902 (*startpp)++;
903 continue;
904 }
905 }
906 if (c == ';') {
907 while ((*startpp <= endp) &&
908 ((c = **startpp) != '\n'))
909 (*startpp)++;

--- 10 unchanged lines hidden (view full) ---

920 }
921 (*startpp)++;
922 n = n * 10 + (c - '0');
923 seendigit = 1;
924 }
925 return (n + m);
926}
927
906 (*startpp)++;
907 continue;
908 }
909 }
910 if (c == ';') {
911 while ((*startpp <= endp) &&
912 ((c = **startpp) != '\n'))
913 (*startpp)++;

--- 10 unchanged lines hidden (view full) ---

924 }
925 (*startpp)++;
926 n = n * 10 + (c - '0');
927 seendigit = 1;
928 }
929 return (n + m);
930}
931
928/*
932/*%
929 * Allocate a resource record buffer & save rr info.
930 */
931ns_updrec *
932res_mkupdrec(int section, const char *dname,
933 u_int class, u_int type, u_long ttl) {
934 ns_updrec *rrecp = (ns_updrec *)calloc(1, sizeof(ns_updrec));
935
936 if (!rrecp || !(rrecp->r_dname = strdup(dname))) {

--- 5 unchanged lines hidden (view full) ---

942 INIT_LINK(rrecp, r_glink);
943 rrecp->r_class = (ns_class)class;
944 rrecp->r_type = (ns_type)type;
945 rrecp->r_ttl = ttl;
946 rrecp->r_section = (ns_sect)section;
947 return (rrecp);
948}
949
933 * Allocate a resource record buffer & save rr info.
934 */
935ns_updrec *
936res_mkupdrec(int section, const char *dname,
937 u_int class, u_int type, u_long ttl) {
938 ns_updrec *rrecp = (ns_updrec *)calloc(1, sizeof(ns_updrec));
939
940 if (!rrecp || !(rrecp->r_dname = strdup(dname))) {

--- 5 unchanged lines hidden (view full) ---

946 INIT_LINK(rrecp, r_glink);
947 rrecp->r_class = (ns_class)class;
948 rrecp->r_type = (ns_type)type;
949 rrecp->r_ttl = ttl;
950 rrecp->r_section = (ns_sect)section;
951 return (rrecp);
952}
953
950/*
954/*%
951 * Free a resource record buffer created by res_mkupdrec.
952 */
953void
954res_freeupdrec(ns_updrec *rrecp) {
955 /* Note: freeing r_dp is the caller's responsibility. */
956 if (rrecp->r_dname != NULL)
957 free(rrecp->r_dname);
958 free(rrecp);

--- 25 unchanged lines hidden (view full) ---

984 slp->name = strdup(sp->s_name);
985 slp->proto = strdup(sp->s_proto);
986 if ((slp->name == NULL) || (slp->proto == NULL)) {
987 if (slp->name) free(slp->name);
988 if (slp->proto) free(slp->proto);
989 free(slp);
990 break;
991 }
955 * Free a resource record buffer created by res_mkupdrec.
956 */
957void
958res_freeupdrec(ns_updrec *rrecp) {
959 /* Note: freeing r_dp is the caller's responsibility. */
960 if (rrecp->r_dname != NULL)
961 free(rrecp->r_dname);
962 free(rrecp);

--- 25 unchanged lines hidden (view full) ---

988 slp->name = strdup(sp->s_name);
989 slp->proto = strdup(sp->s_proto);
990 if ((slp->name == NULL) || (slp->proto == NULL)) {
991 if (slp->name) free(slp->name);
992 if (slp->proto) free(slp->proto);
993 free(slp);
994 break;
995 }
992 slp->port = ntohs((u_int16_t)sp->s_port); /* host byt order */
996 slp->port = ntohs((u_int16_t)sp->s_port); /*%< host byt order */
993 slp->next = servicelist;
994 slp->prev = NULL;
995 if (servicelist)
996 servicelist->prev = slp;
997 servicelist = slp;
998 }
999 endservent();
1000}

--- 30 unchanged lines hidden (view full) ---

1031 slp = (struct valuelist *)malloc(sizeof(struct valuelist));
1032 if (!slp)
1033 break;
1034 slp->name = strdup(pp->p_name);
1035 if (slp->name == NULL) {
1036 free(slp);
1037 break;
1038 }
997 slp->next = servicelist;
998 slp->prev = NULL;
999 if (servicelist)
1000 servicelist->prev = slp;
1001 servicelist = slp;
1002 }
1003 endservent();
1004}

--- 30 unchanged lines hidden (view full) ---

1035 slp = (struct valuelist *)malloc(sizeof(struct valuelist));
1036 if (!slp)
1037 break;
1038 slp->name = strdup(pp->p_name);
1039 if (slp->name == NULL) {
1040 free(slp);
1041 break;
1042 }
1039 slp->port = pp->p_proto; /* host byte order */
1043 slp->port = pp->p_proto; /*%< host byte order */
1040 slp->next = protolist;
1041 slp->prev = NULL;
1042 if (protolist)
1043 protolist->prev = slp;
1044 protolist = slp;
1045 }
1046 endprotoent();
1047}

--- 22 unchanged lines hidden (view full) ---

1070 if (lp != *list) {
1071 lp->prev->next = lp->next;
1072 if (lp->next)
1073 lp->next->prev = lp->prev;
1074 (*list)->prev = lp;
1075 lp->next = *list;
1076 *list = lp;
1077 }
1044 slp->next = protolist;
1045 slp->prev = NULL;
1046 if (protolist)
1047 protolist->prev = slp;
1048 protolist = slp;
1049 }
1050 endprotoent();
1051}

--- 22 unchanged lines hidden (view full) ---

1074 if (lp != *list) {
1075 lp->prev->next = lp->next;
1076 if (lp->next)
1077 lp->next->prev = lp->prev;
1078 (*list)->prev = lp;
1079 lp->next = *list;
1080 *list = lp;
1081 }
1078 return (lp->port); /* host byte order */
1082 return (lp->port); /*%< host byte order */
1079 }
1080 if (sscanf(s, "%d", &n) != 1 || n <= 0)
1081 n = -1;
1082 return (n);
1083}
1084
1083 }
1084 if (sscanf(s, "%d", &n) != 1 || n <= 0)
1085 n = -1;
1086 return (n);
1087}
1088
1085/*
1089/*%
1086 * Convert service name or (ascii) number to int.
1087 */
1088#ifdef _LIBC
1089static
1090#endif
1091int
1092res_servicenumber(const char *p) {
1093 if (servicelist == (struct valuelist *)0)
1094 res_buildservicelist();
1095 return (findservice(p, &servicelist));
1096}
1097
1090 * Convert service name or (ascii) number to int.
1091 */
1092#ifdef _LIBC
1093static
1094#endif
1095int
1096res_servicenumber(const char *p) {
1097 if (servicelist == (struct valuelist *)0)
1098 res_buildservicelist();
1099 return (findservice(p, &servicelist));
1100}
1101
1098/*
1102/*%
1099 * Convert protocol name or (ascii) number to int.
1100 */
1101#ifdef _LIBC
1102static
1103#endif
1104int
1105res_protocolnumber(const char *p) {
1106 if (protolist == (struct valuelist *)0)
1107 res_buildprotolist();
1108 return (findservice(p, &protolist));
1109}
1110
1111#ifndef _LIBC
1112static struct servent *
1103 * Convert protocol name or (ascii) number to int.
1104 */
1105#ifdef _LIBC
1106static
1107#endif
1108int
1109res_protocolnumber(const char *p) {
1110 if (protolist == (struct valuelist *)0)
1111 res_buildprotolist();
1112 return (findservice(p, &protolist));
1113}
1114
1115#ifndef _LIBC
1116static struct servent *
1113cgetservbyport(u_int16_t port, const char *proto) { /* Host byte order. */
1117cgetservbyport(u_int16_t port, const char *proto) { /*%< Host byte order. */
1114 struct valuelist **list = &servicelist;
1115 struct valuelist *lp = *list;
1116 static struct servent serv;
1117
1118 port = ntohs(port);
1119 for (; lp != NULL; lp = lp->next) {
1118 struct valuelist **list = &servicelist;
1119 struct valuelist *lp = *list;
1120 static struct servent serv;
1121
1122 port = ntohs(port);
1123 for (; lp != NULL; lp = lp->next) {
1120 if (port != (u_int16_t)lp->port) /* Host byte order. */
1124 if (port != (u_int16_t)lp->port) /*%< Host byte order. */
1121 continue;
1122 if (strcasecmp(lp->proto, proto) == 0) {
1123 if (lp != *list) {
1124 lp->prev->next = lp->next;
1125 if (lp->next)
1126 lp->next->prev = lp->prev;
1127 (*list)->prev = lp;
1128 lp->next = *list;

--- 4 unchanged lines hidden (view full) ---

1133 serv.s_proto = lp->proto;
1134 return (&serv);
1135 }
1136 }
1137 return (0);
1138}
1139
1140static struct protoent *
1125 continue;
1126 if (strcasecmp(lp->proto, proto) == 0) {
1127 if (lp != *list) {
1128 lp->prev->next = lp->next;
1129 if (lp->next)
1130 lp->next->prev = lp->prev;
1131 (*list)->prev = lp;
1132 lp->next = *list;

--- 4 unchanged lines hidden (view full) ---

1137 serv.s_proto = lp->proto;
1138 return (&serv);
1139 }
1140 }
1141 return (0);
1142}
1143
1144static struct protoent *
1141cgetprotobynumber(int proto) { /* Host byte order. */
1145cgetprotobynumber(int proto) { /*%< Host byte order. */
1142 struct valuelist **list = &protolist;
1143 struct valuelist *lp = *list;
1144 static struct protoent prot;
1145
1146 for (; lp != NULL; lp = lp->next)
1146 struct valuelist **list = &protolist;
1147 struct valuelist *lp = *list;
1148 static struct protoent prot;
1149
1150 for (; lp != NULL; lp = lp->next)
1147 if (lp->port == proto) { /* Host byte order. */
1151 if (lp->port == proto) { /*%< Host byte order. */
1148 if (lp != *list) {
1149 lp->prev->next = lp->next;
1150 if (lp->next)
1151 lp->next->prev = lp->prev;
1152 (*list)->prev = lp;
1153 lp->next = *list;
1154 *list = lp;
1155 }
1156 prot.p_name = lp->name;
1152 if (lp != *list) {
1153 lp->prev->next = lp->next;
1154 if (lp->next)
1155 lp->next->prev = lp->prev;
1156 (*list)->prev = lp;
1157 lp->next = *list;
1158 *list = lp;
1159 }
1160 prot.p_name = lp->name;
1157 prot.p_proto = lp->port; /* Host byte order. */
1161 prot.p_proto = lp->port; /*%< Host byte order. */
1158 return (&prot);
1159 }
1160 return (0);
1161}
1162
1163const char *
1164res_protocolname(int num) {
1165 static char number[8];

--- 5 unchanged lines hidden (view full) ---

1171 if (pp == 0) {
1172 (void) sprintf(number, "%d", num);
1173 return (number);
1174 }
1175 return (pp->p_name);
1176}
1177
1178const char *
1162 return (&prot);
1163 }
1164 return (0);
1165}
1166
1167const char *
1168res_protocolname(int num) {
1169 static char number[8];

--- 5 unchanged lines hidden (view full) ---

1175 if (pp == 0) {
1176 (void) sprintf(number, "%d", num);
1177 return (number);
1178 }
1179 return (pp->p_name);
1180}
1181
1182const char *
1179res_servicename(u_int16_t port, const char *proto) { /* Host byte order. */
1183res_servicename(u_int16_t port, const char *proto) { /*%< Host byte order. */
1180 static char number[8];
1181 struct servent *ss;
1182
1183 if (servicelist == (struct valuelist *)0)
1184 res_buildservicelist();
1185 ss = cgetservbyport(htons(port), proto);
1186 if (ss == 0) {
1187 (void) sprintf(number, "%d", port);
1188 return (number);
1189 }
1190 return (ss->s_name);
1191}
1192#endif
1184 static char number[8];
1185 struct servent *ss;
1186
1187 if (servicelist == (struct valuelist *)0)
1188 res_buildservicelist();
1189 ss = cgetservbyport(htons(port), proto);
1190 if (ss == 0) {
1191 (void) sprintf(number, "%d", port);
1192 return (number);
1193 }
1194 return (ss->s_name);
1195}
1196#endif