res_mkupdate.c (158783) | res_mkupdate.c (158787) |
---|---|
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 unchanged lines hidden (view full) --- 18/* 19 * Based on the Dynamic DNS reference implementation by Viraj Bais 20 * <viraj_bais@ccm.fm.intel.com> 21 */ 22 23#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 $"; 25#endif /* not lint */ | 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 unchanged lines hidden (view full) --- 18/* 19 * Based on the Dynamic DNS reference implementation by Viraj Bais 20 * <viraj_bais@ccm.fm.intel.com> 21 */ 22 23#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 $"; 25#endif /* not lint */ |
26#include <sys/cdefs.h> 27__FBSDID("$FreeBSD: head/lib/libc/resolv/res_mkupdate.c 158787 2006-05-21 11:19:36Z ume $"); |
|
26 27#include "port_before.h" 28 29#include <sys/types.h> 30#include <sys/param.h> 31 32#include <netinet/in.h> 33#include <arpa/nameser.h> --- 5 unchanged lines hidden (view full) --- 39#include <resolv.h> 40#include <res_update.h> 41#include <stdio.h> 42#include <stdlib.h> 43#include <string.h> 44#include <unistd.h> 45#include <ctype.h> 46 | 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> --- 5 unchanged lines hidden (view full) --- 41#include <resolv.h> 42#include <res_update.h> 43#include <stdio.h> 44#include <stdlib.h> 45#include <string.h> 46#include <unistd.h> 47#include <ctype.h> 48 |
49#ifdef _LIBC 50#include <isc/list.h> 51#endif 52 |
|
47#include "port_after.h" 48 49/* Options. Leave them on. */ 50#define DEBUG 51#define MAXPORT 1024 52 53static int getnum_str(u_char **, u_char *); 54static int gethexnum_str(u_char **, u_char *); 55static int getword_str(char *, int, u_char **, u_char *); 56static int getstr_str(char *, int, u_char **, u_char *); 57 58#define ShrinkBuffer(x) if ((buflen -= x) < 0) return (-2); 59 60/* Forward. */ 61 | 53#include "port_after.h" 54 55/* Options. Leave them on. */ 56#define DEBUG 57#define MAXPORT 1024 58 59static int getnum_str(u_char **, u_char *); 60static int gethexnum_str(u_char **, u_char *); 61static int getword_str(char *, int, u_char **, u_char *); 62static int getstr_str(char *, int, u_char **, u_char *); 63 64#define ShrinkBuffer(x) if ((buflen -= x) < 0) return (-2); 65 66/* Forward. */ 67 |
68#ifdef _LIBC 69static 70#endif |
|
62int res_protocolnumber(const char *); | 71int res_protocolnumber(const char *); |
72#ifdef _LIBC 73static 74#endif |
|
63int res_servicenumber(const char *); 64 65/* 66 * Form update packets. 67 * Returns the size of the resulting packet if no error 68 * On error, 69 * returns -1 if error in reading a word/number in rdata 70 * portion for update packets --- 13 unchanged lines hidden (view full) --- 84 struct in_addr ina; 85 struct in6_addr in6a; 86 char buf2[MAXDNAME]; 87 u_char buf3[MAXDNAME]; 88 int section, numrrs = 0, counts[ns_s_max]; 89 u_int16_t rtype, rclass; 90 u_int32_t n1, rttl; 91 u_char *dnptrs[20], **dpp, **lastdnptr; | 75int res_servicenumber(const char *); 76 77/* 78 * Form update packets. 79 * Returns the size of the resulting packet if no error 80 * On error, 81 * returns -1 if error in reading a word/number in rdata 82 * portion for update packets --- 13 unchanged lines hidden (view full) --- 96 struct in_addr ina; 97 struct in6_addr in6a; 98 char buf2[MAXDNAME]; 99 u_char buf3[MAXDNAME]; 100 int section, numrrs = 0, counts[ns_s_max]; 101 u_int16_t rtype, rclass; 102 u_int32_t n1, rttl; 103 u_char *dnptrs[20], **dpp, **lastdnptr; |
92 int siglen, keylen, certlen; | 104#ifndef _LIBC 105 int siglen; 106#endif 107 int keylen, certlen; |
93 94 /* 95 * Initialize header fields. 96 */ 97 if ((buf == NULL) || (buflen < HFIXEDSZ)) 98 return (-1); 99 memset(buf, 0, HFIXEDSZ); 100 hp = (HEADER *) buf; --- 339 unchanged lines hidden (view full) --- 440 if ((n = loc_aton((char *)startp, (u_char *)buf2)) != 0) { 441 ShrinkBuffer(n); 442 memcpy(cp, buf2, n); 443 cp += n; 444 } else 445 return (-1); 446 break; 447 case ns_t_sig: | 108 109 /* 110 * Initialize header fields. 111 */ 112 if ((buf == NULL) || (buflen < HFIXEDSZ)) 113 return (-1); 114 memset(buf, 0, HFIXEDSZ); 115 hp = (HEADER *) buf; --- 339 unchanged lines hidden (view full) --- 455 if ((n = loc_aton((char *)startp, (u_char *)buf2)) != 0) { 456 ShrinkBuffer(n); 457 memcpy(cp, buf2, n); 458 cp += n; 459 } else 460 return (-1); 461 break; 462 case ns_t_sig: |
463#ifdef _LIBC 464 return (-1); 465#else |
|
448 { 449 int sig_type, success, dateerror; 450 u_int32_t exptime, timesigned; 451 452 /* type */ 453 if ((n = getword_str(buf2, sizeof buf2, 454 &startp, endp)) < 0) 455 return (-1); --- 74 unchanged lines hidden (view full) --- 530 siglen = b64_pton(buf2, buf3, sizeof(buf3)); 531 if (siglen < 0) 532 return (-1); 533 ShrinkBuffer(siglen); 534 memcpy(cp, buf3, siglen); 535 cp += siglen; 536 break; 537 } | 466 { 467 int sig_type, success, dateerror; 468 u_int32_t exptime, timesigned; 469 470 /* type */ 471 if ((n = getword_str(buf2, sizeof buf2, 472 &startp, endp)) < 0) 473 return (-1); --- 74 unchanged lines hidden (view full) --- 548 siglen = b64_pton(buf2, buf3, sizeof(buf3)); 549 if (siglen < 0) 550 return (-1); 551 ShrinkBuffer(siglen); 552 memcpy(cp, buf3, siglen); 553 cp += siglen; 554 break; 555 } |
556#endif |
|
538 case ns_t_key: 539 /* flags */ 540 n = gethexnum_str(&startp, endp); 541 if (n < 0) 542 return (-1); 543 ShrinkBuffer(INT16SZ); 544 PUTSHORT(n, cp); 545 /* proto */ --- 429 unchanged lines hidden (view full) --- 975 slp->prev = NULL; 976 if (servicelist) 977 servicelist->prev = slp; 978 servicelist = slp; 979 } 980 endservent(); 981} 982 | 557 case ns_t_key: 558 /* flags */ 559 n = gethexnum_str(&startp, endp); 560 if (n < 0) 561 return (-1); 562 ShrinkBuffer(INT16SZ); 563 PUTSHORT(n, cp); 564 /* proto */ --- 429 unchanged lines hidden (view full) --- 994 slp->prev = NULL; 995 if (servicelist) 996 servicelist->prev = slp; 997 servicelist = slp; 998 } 999 endservent(); 1000} 1001 |
1002#ifndef _LIBC |
|
983void 984res_destroyservicelist() { 985 struct valuelist *slp, *slp_next; 986 987 for (slp = servicelist; slp != NULL; slp = slp_next) { 988 slp_next = slp->next; 989 free(slp->name); 990 free(slp->proto); 991 free(slp); 992 } 993 servicelist = (struct valuelist *)0; 994} | 1003void 1004res_destroyservicelist() { 1005 struct valuelist *slp, *slp_next; 1006 1007 for (slp = servicelist; slp != NULL; slp = slp_next) { 1008 slp_next = slp->next; 1009 free(slp->name); 1010 free(slp->proto); 1011 free(slp); 1012 } 1013 servicelist = (struct valuelist *)0; 1014} |
1015#endif |
|
995 | 1016 |
1017#ifdef _LIBC 1018static 1019#endif |
|
996void 997res_buildprotolist(void) { 998 struct protoent *pp; 999 struct valuelist *slp; 1000 1001#ifdef MAYBE_HESIOD 1002 setprotoent(0); 1003#else --- 13 unchanged lines hidden (view full) --- 1017 slp->prev = NULL; 1018 if (protolist) 1019 protolist->prev = slp; 1020 protolist = slp; 1021 } 1022 endprotoent(); 1023} 1024 | 1020void 1021res_buildprotolist(void) { 1022 struct protoent *pp; 1023 struct valuelist *slp; 1024 1025#ifdef MAYBE_HESIOD 1026 setprotoent(0); 1027#else --- 13 unchanged lines hidden (view full) --- 1041 slp->prev = NULL; 1042 if (protolist) 1043 protolist->prev = slp; 1044 protolist = slp; 1045 } 1046 endprotoent(); 1047} 1048 |
1049#ifndef _LIBC |
|
1025void 1026res_destroyprotolist(void) { 1027 struct valuelist *plp, *plp_next; 1028 1029 for (plp = protolist; plp != NULL; plp = plp_next) { 1030 plp_next = plp->next; 1031 free(plp->name); 1032 free(plp); 1033 } 1034 protolist = (struct valuelist *)0; 1035} | 1050void 1051res_destroyprotolist(void) { 1052 struct valuelist *plp, *plp_next; 1053 1054 for (plp = protolist; plp != NULL; plp = plp_next) { 1055 plp_next = plp->next; 1056 free(plp->name); 1057 free(plp); 1058 } 1059 protolist = (struct valuelist *)0; 1060} |
1061#endif |
|
1036 1037static int 1038findservice(const char *s, struct valuelist **list) { 1039 struct valuelist *lp = *list; 1040 int n; 1041 1042 for (; lp != NULL; lp = lp->next) 1043 if (strcasecmp(lp->name, s) == 0) { --- 10 unchanged lines hidden (view full) --- 1054 if (sscanf(s, "%d", &n) != 1 || n <= 0) 1055 n = -1; 1056 return (n); 1057} 1058 1059/* 1060 * Convert service name or (ascii) number to int. 1061 */ | 1062 1063static int 1064findservice(const char *s, struct valuelist **list) { 1065 struct valuelist *lp = *list; 1066 int n; 1067 1068 for (; lp != NULL; lp = lp->next) 1069 if (strcasecmp(lp->name, s) == 0) { --- 10 unchanged lines hidden (view full) --- 1080 if (sscanf(s, "%d", &n) != 1 || n <= 0) 1081 n = -1; 1082 return (n); 1083} 1084 1085/* 1086 * Convert service name or (ascii) number to int. 1087 */ |
1088#ifdef _LIBC 1089static 1090#endif |
|
1062int 1063res_servicenumber(const char *p) { 1064 if (servicelist == (struct valuelist *)0) 1065 res_buildservicelist(); 1066 return (findservice(p, &servicelist)); 1067} 1068 1069/* 1070 * Convert protocol name or (ascii) number to int. 1071 */ | 1091int 1092res_servicenumber(const char *p) { 1093 if (servicelist == (struct valuelist *)0) 1094 res_buildservicelist(); 1095 return (findservice(p, &servicelist)); 1096} 1097 1098/* 1099 * Convert protocol name or (ascii) number to int. 1100 */ |
1101#ifdef _LIBC 1102static 1103#endif |
|
1072int 1073res_protocolnumber(const char *p) { 1074 if (protolist == (struct valuelist *)0) 1075 res_buildprotolist(); 1076 return (findservice(p, &protolist)); 1077} 1078 | 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 |
|
1079static struct servent * 1080cgetservbyport(u_int16_t port, const char *proto) { /* Host byte order. */ 1081 struct valuelist **list = &servicelist; 1082 struct valuelist *lp = *list; 1083 static struct servent serv; 1084 1085 port = ntohs(port); 1086 for (; lp != NULL; lp = lp->next) { --- 64 unchanged lines hidden (view full) --- 1151 res_buildservicelist(); 1152 ss = cgetservbyport(htons(port), proto); 1153 if (ss == 0) { 1154 (void) sprintf(number, "%d", port); 1155 return (number); 1156 } 1157 return (ss->s_name); 1158} | 1112static struct servent * 1113cgetservbyport(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) { --- 64 unchanged lines hidden (view full) --- 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 |
|