function of the same name and presents the results as a data expression.
This function can be used to incorporate the system level hostname of
the system the DHCP software is operating on in responses or queries (such
as including a failover partner's hostname in a dhcp message or binding
scope, or having a DHCP client send any system hostname in the host-name or
FQDN options by default). [ISC-Bugs #17351]
please carefully review the documentation of this parameter in the
dhcpd.conf(5) manpage before determining to use it yourself.
+- Added a configuration function, 'gethostname()', which calls the system
+ function of the same name and presents the results as a data expression.
+ This function can be used to incorporate the system level hostname of
+ the system the DHCP software is operating on in responses or queries (such
+ as including a failover partner's hostname in a dhcp message or binding
+ scope, or having a DHCP client send any system hostname in the host-name or
+ FQDN options by default).
+
Changes since 4.1.0 (bug fixes)
- Remove infinite loop in token_print_indent_concat().
-send host-name "andare.fugue.com";
+send host-name = pick-first-value(gethostname(), "ISC-dhclient");
send dhcp-client-identifier 1:0:a0:24:ab:fb:9c;
send dhcp-lease-time 3600;
supersede domain-name "fugue.com home.vix.com";
return TOKEN_FREE;
break;
case 'g':
+ if (!strncasecmp(atom + 1, "et", 2)) {
+ if (!strcasecmp(atom + 3, "-lease-hostnames"))
+ return GET_LEASE_HOSTNAMES;
+ if (!strcasecmp(atom + 3, "hostname"))
+ return GETHOSTNAME;
+ break;
+ }
if (!strcasecmp (atom + 1, "iaddr"))
return GIADDR;
if (!strcasecmp (atom + 1, "roup"))
return GROUP;
- if (!strcasecmp (atom + 1, "et-lease-hostnames"))
- return GET_LEASE_HOSTNAMES;
break;
case 'h':
if (!strcasecmp(atom + 1, "ash"))
-.\" $Id: dhcp-eval.5,v 1.27 2007/06/07 15:52:29 dhankins Exp $
+.\" $Id: dhcp-eval.5,v 1.28 2009/07/06 23:29:51 dhankins Exp $
.\"
.\" Copyright (c) 2004,2007 by Internet Systems Consortium, Inc. ("ISC")
.\" Copyright (c) 1996-2003 by Internet Software Consortium
that the DHCP client or server has been configured to send.
.RE
.PP
+.B gethostname()
+.PP
+.RS 0.25i
+The \fBgethostname()\fR function returns a data string whose contents are a
+character string, the results of calling gethostname() on the local
+system with a size limit of 255 bytes (not including NULL terminator). This
+can be used for example to configure dhclient to send the local hostname
+without knowing the local hostname at the time dhclient.conf is written.
+.RE
+.PP
.B hardware
.PP
.RS 0.25i
goto norparen;
break;
+ /* This parses 'gethostname()'. */
+ case GETHOSTNAME:
+ token = next_token(&val, NULL, cfile);
+ if (!expression_allocate(expr, MDL))
+ log_fatal("can't allocate expression");
+ (*expr)->op = expr_gethostname;
+
+ token = next_token(NULL, NULL, cfile);
+ if (token != LPAREN)
+ goto nolparen;
+
+ token = next_token(NULL, NULL, cfile);
+ if (token != RPAREN)
+ goto norparen;
+ break;
+
/* Not a valid start to an expression... */
default:
if (token != NAME && token != NUMBER_OR_NAME)
return rv;
}
+ case expr_gethostname:
+ if (len > 13) {
+ strcpy(buf, "(gethostname)");
+ return 13;
+ }
+ break;
+
default:
log_fatal("Impossible case at %s:%d (undefined expression "
"%d).", MDL, expr->op);
case expr_config_option:
case expr_leased_address:
case expr_null:
+ case expr_gethostname:
log_error ("Data opcode in evaluate_dns_expression: %d",
expr -> op);
return 0;
case expr_null:
case expr_filename:
case expr_sname:
+ case expr_gethostname:
log_error ("Data opcode in evaluate_boolean_expression: %d",
expr -> op);
return 0;
#endif
return s0;
+ /* Provide the system's local hostname as a return value. */
+ case expr_gethostname:
+ /*
+ * Allocate a buffer to return.
+ *
+ * The largest valid hostname is maybe 64 octets at a single
+ * label, or 255 octets if you think a hostname is allowed
+ * to contain labels (plus termination).
+ */
+ memset(result, 0, sizeof(*result));
+ if (!buffer_allocate(&result->buffer, 255, file, line)) {
+ log_error("data: gethostname(): no memory for buffer");
+ return 0;
+ }
+ result->data = result->buffer->data;
+
+ /*
+ * On successful completion, gethostname() resturns 0. It may
+ * not null-terminate the string if there was insufficient
+ * space.
+ */
+ if (!gethostname((char *)result->buffer->data, 255)) {
+ if (result->buffer->data[255] == '\0')
+ result->len =
+ strlen((char *)result->buffer->data);
+ else
+ result->len = 255;
+ return 1;
+ }
+
+ data_string_forget(result, MDL);
+ return 0;
+
case expr_check:
case expr_equal:
case expr_not_equal:
case expr_config_option:
case expr_leased_address:
case expr_null:
+ case expr_gethostname:
log_error ("Data opcode in evaluate_numeric_expression: %d",
expr -> op);
return 0;
case expr_exists:
case expr_known:
case expr_null:
+ case expr_gethostname:
break;
default:
expr->op == expr_host_decl_name ||
expr->op == expr_leased_address ||
expr->op == expr_config_option ||
- expr->op == expr_null);
+ expr->op == expr_null ||
+ expr->op == expr_gethostname);
}
int is_numeric_expression (expr)
case expr_binary_or:
case expr_binary_xor:
case expr_client_state:
+ case expr_gethostname:
return 100;
case expr_equal:
case expr_arg:
case expr_funcall:
case expr_function:
+ case expr_gethostname:
return context_any;
case expr_equal:
col = token_print_indent (file, col, indent, "", "", ")");
break;
+ case expr_gethostname:
+ col = token_print_indent(file, col, indent, "", "",
+ "gethostname()");
+ break;
+
default:
log_fatal ("invalid expression type in print_expression: %d",
expr -> op);
case expr_binary_or:
case expr_binary_xor:
case expr_client_state:
+ case expr_gethostname:
return 0;
}
return 0;
FIXED_PREFIX6 = 658,
ANYCAST_MAC = 659,
CONFLICT_DONE = 660,
- AUTO_PARTNER_DOWN = 661
+ AUTO_PARTNER_DOWN = 661,
+ GETHOSTNAME = 662
};
#define is_identifier(x) ((x) >= FIRST_TOKEN && \
expr_ucase,
expr_lcase,
expr_regex_match,
- expr_iregex_match
+ expr_iregex_match,
+ expr_gethostname
};
struct expression {