RPi Locator and Display Services
udp_locator_service.c
Go to the documentation of this file.
1 
18 #include "skn_network_helpers.h"
19 
20 int main(int argc, char *argv[])
21 {
22  int exit_code = EXIT_SUCCESS;
23  char response[SZ_COMM_BUFF];
24 
25  memset(response, 0, sizeof(response));
26 
28  "udp_locator_service",
29  "Provides IPv4 Address/Port Service info."
30  );
31 
32  if (skn_handle_locator_command_line(argc, argv) == EXIT_FAILURE) {
33  exit(EXIT_FAILURE);
34  }
35  if (gd_pch_message != NULL) {
36  strncpy(response, gd_pch_message, sizeof(response));
37  free(gd_pch_message); // from strdup()
38  gd_pch_message = response;
39  }
41  skn_logger(SD_NOTICE, "%s-%s is in startup mode as user(%s)", gd_ch_program_name, PACKAGE_VERSION, gd_pch_effective_userid);
42 
43  if ((strlen(response) > 16) && (service_registry_valiadate_response_format(response) == EXIT_FAILURE)) {
44  skn_logger(SD_EMERG, "Message format is invalid! cannot proceed.");
46  exit(EXIT_FAILURE);
47  }
48 
49  /* Initialize Signal handler */
50  signals_init();
51 
53  if (gd_i_socket == EXIT_FAILURE) {
54  skn_logger(SD_EMERG, "Application Host Init Failed! ExitCode=%d", exit_code);
56  exit(EXIT_FAILURE);
57  }
58 
59  exit_code = service_registry_provider(gd_i_socket, response);
60  skn_logger(SD_NOTICE, "Application ExitCode=%d", exit_code);
61 
62  if (gd_i_socket) close(gd_i_socket);
64 
65  skn_logger(SD_NOTICE, "\n============================\nShutdown Complete\n============================\n");
66 
67  exit(exit_code);
68 }
int service_registry_provider(int i_socket, char *response)
void signals_init()
void signals_cleanup(int sig)
int skn_handle_locator_command_line(int argc, char **argv)
char * gd_pch_message
uid_t skn_get_userids()
#define SZ_COMM_BUFF
Definition: cmdDC.c:59
#define SD_EMERG
void service_registry_entry_response_message_log(const char *response)
char gd_ch_program_name[SZ_INFO_BUFF]
int main(int argc, char *argv[])
int service_registry_valiadate_response_format(const char *response)
sig_atomic_t gi_exit_flag
#define SD_NOTICE
int skn_udp_host_create_broadcast_socket(int port, double rcvTimeout)
char * gd_pch_effective_userid
void skn_program_name_and_description_set(const char *name, const char *desc)
#define PACKAGE_VERSION
Definition: cmdDC.c:19
#define SKN_FIND_RPI_PORT
int gd_i_socket