@@ -1101,6 +1101,95 @@ static void register_mdns_lookup_service(void)
1101
1101
ESP_ERROR_CHECK ( esp_console_cmd_register (& cmd_lookup_service ) );
1102
1102
}
1103
1103
1104
+ static struct {
1105
+ struct arg_str * hostname ;
1106
+ struct arg_str * address ;
1107
+ struct arg_end * end ;
1108
+ } mdns_delegate_host_args ;
1109
+
1110
+ static int cmd_mdns_delegate_host (int argc , char * * argv )
1111
+ {
1112
+ int nerrors = arg_parse (argc , argv , (void * * ) & mdns_delegate_host_args );
1113
+ if (nerrors != 0 ) {
1114
+ arg_print_errors (stderr , mdns_delegate_host_args .end , argv [0 ]);
1115
+ return 1 ;
1116
+ }
1117
+
1118
+ if (!mdns_delegate_host_args .hostname -> sval [0 ] || !mdns_delegate_host_args .address -> sval [0 ]) {
1119
+ printf ("ERROR: Bad arguments!\n" );
1120
+ return 1 ;
1121
+ }
1122
+
1123
+ mdns_ip_addr_t addr = { .next = NULL };
1124
+ esp_netif_str_to_ip4 (mdns_delegate_host_args .address -> sval [0 ], & addr .addr .u_addr .ip4 );
1125
+ addr .addr .type = ESP_IPADDR_TYPE_V4 ;
1126
+
1127
+ esp_err_t err = mdns_delegate_hostname_add (mdns_delegate_host_args .hostname -> sval [0 ], & addr );
1128
+ if (err ) {
1129
+ printf ("mdns_delegate_hostname_add() failed\n" );
1130
+ return 1 ;
1131
+ }
1132
+ return 0 ;
1133
+ }
1134
+
1135
+ static void register_mdns_delegate_host (void )
1136
+ {
1137
+ mdns_delegate_host_args .hostname = arg_str1 (NULL , NULL , "<hostname>" , "Delegated hostname" );
1138
+ mdns_delegate_host_args .address = arg_str1 (NULL , NULL , "<address>" , "Delegated hosts address" );
1139
+ mdns_delegate_host_args .end = arg_end (2 );
1140
+
1141
+ const esp_console_cmd_t cmd_delegate_host = {
1142
+ .command = "mdns_delegate_host" ,
1143
+ .help = "Add delegated hostname" ,
1144
+ .hint = NULL ,
1145
+ .func = & cmd_mdns_delegate_host ,
1146
+ .argtable = & mdns_delegate_host_args
1147
+ };
1148
+
1149
+ ESP_ERROR_CHECK ( esp_console_cmd_register (& cmd_delegate_host ) );
1150
+ }
1151
+
1152
+ static struct {
1153
+ struct arg_str * hostname ;
1154
+ struct arg_end * end ;
1155
+ } mdns_undelegate_host_args ;
1156
+
1157
+ static int cmd_mdns_undelegate_host (int argc , char * * argv )
1158
+ {
1159
+ int nerrors = arg_parse (argc , argv , (void * * ) & mdns_undelegate_host_args );
1160
+ if (nerrors != 0 ) {
1161
+ arg_print_errors (stderr , mdns_undelegate_host_args .end , argv [0 ]);
1162
+ return 1 ;
1163
+ }
1164
+
1165
+ if (!mdns_undelegate_host_args .hostname -> sval [0 ]) {
1166
+ printf ("ERROR: Bad arguments!\n" );
1167
+ return 1 ;
1168
+ }
1169
+
1170
+ if (mdns_delegate_hostname_remove (mdns_undelegate_host_args .hostname -> sval [0 ]) != ESP_OK ) {
1171
+ printf ("mdns_delegate_hostname_remove() failed\n" );
1172
+ return 1 ;
1173
+ }
1174
+ return 0 ;
1175
+ }
1176
+
1177
+ static void register_mdns_undelegate_host (void )
1178
+ {
1179
+ mdns_undelegate_host_args .hostname = arg_str1 (NULL , NULL , "<hostname>" , "Delegated hostname" );
1180
+ mdns_undelegate_host_args .end = arg_end (2 );
1181
+
1182
+ const esp_console_cmd_t cmd_undelegate_host = {
1183
+ .command = "mdns_undelegate_host" ,
1184
+ .help = "Remove delegated hostname" ,
1185
+ .hint = NULL ,
1186
+ .func = & cmd_mdns_undelegate_host ,
1187
+ .argtable = & mdns_undelegate_host_args
1188
+ };
1189
+
1190
+ ESP_ERROR_CHECK ( esp_console_cmd_register (& cmd_undelegate_host ) );
1191
+ }
1192
+
1104
1193
void mdns_console_register (void )
1105
1194
{
1106
1195
register_mdns_init ();
@@ -1117,6 +1206,8 @@ void mdns_console_register(void)
1117
1206
register_mdns_service_remove_all ();
1118
1207
1119
1208
register_mdns_lookup_service ();
1209
+ register_mdns_delegate_host ();
1210
+ register_mdns_undelegate_host ();
1120
1211
1121
1212
#ifdef CONFIG_LWIP_IPV4
1122
1213
register_mdns_query_a ();
0 commit comments