RPi Locator and Display Services
udp_locator_client.c File Reference
+ Include dependency graph for udp_locator_client.c:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

udp_locator_client.c

  • Client

cmdline: ./udp_locator_client -m "<request-message-string>"

Definition at line 11 of file udp_locator_client.c.

References gd_i_socket, gd_pch_message, gd_pch_service_name, gi_exit_flag, _serviceEntry::ip, _serviceEntry::name, _serviceEntry::port, SD_DEBUG, service_registry_destroy(), service_registry_entry_count(), service_registry_find_entry(), service_registry_get_via_udp_broadcast(), service_registry_list_entries(), signals_cleanup(), signals_init(), skn_handle_locator_command_line(), skn_program_name_and_description_set(), skn_udp_host_create_broadcast_socket(), and SZ_COMM_BUFF.

12 {
13  char request[SZ_COMM_BUFF];
14 
15  memset(request, 0, sizeof(request));
16  strcpy(request, "Raspberry Pi where are you?");
17 
19  "udp_locator_client",
20  "Collect IPv4 Address/Port Service info from all providers."
21  );
22 
23  /* Parse any command line options,
24  * like request string override */
25  if (skn_handle_locator_command_line(argc, argv) == EXIT_FAILURE) {
26  exit(EXIT_FAILURE);
27  }
28  if (gd_pch_message != NULL) {
29  strncpy(request, gd_pch_message, sizeof(request));
30  free(gd_pch_message); // from strdup()
31  gd_pch_message = request;
32  } else if (argc == 2) {
33  strcpy(request, argv[1]);
34  }
35  skn_logger(SD_DEBUG, "Request Message [%s]", request);
36 
37  /* Initialize Signal handler */
38  signals_init();
39 
40  /* Create local socket for sending requests */
42  if (gd_i_socket == EXIT_FAILURE) {
44  exit(EXIT_FAILURE);
45  }
46 
47  /* Get the ServiceRegistry from Provider
48  * - could return null if error */
50  if (psr != NULL && service_registry_entry_count(psr) != 0) {
51  char *service_name = "lcd_display_service";
52 
53  if (gd_pch_service_name != NULL) {
54  service_name = gd_pch_service_name;
55  }
56 
58 
59  /* find a single entry */
60  PRegistryEntry pre = service_registry_find_entry(psr, service_name);
61  if (pre != NULL) {
62  skn_logger(" ", "\nLCD DisplayService (%s) is located at IPv4: %s:%d\n", pre->name, pre->ip, pre->port);
63  }
64  }
65 
66  /* Cleanup and shutdown
67  * - if shutdown was caused by signal handler
68  * then a termination signal will be sent via signal()
69  * otherwise, a normal exit occurs
70  */
71  if (gd_i_socket) close(gd_i_socket);
72  if (psr != NULL) service_registry_destroy(psr);
74 
75  exit(EXIT_SUCCESS);
76 }
char * gd_pch_service_name
int service_registry_entry_count(PServiceRegistry psr)
#define SD_DEBUG
int port
void signals_init()
void signals_cleanup(int sig)
int skn_handle_locator_command_line(int argc, char **argv)
char * gd_pch_message
#define SZ_COMM_BUFF
Definition: cmdDC.c:59
PServiceRegistry service_registry_get_via_udp_broadcast(int i_socket, char *request)
char name[SZ_INFO_BUFF]
sig_atomic_t gi_exit_flag
int service_registry_list_entries(PServiceRegistry psr)
void service_registry_destroy(PServiceRegistry psreg)
int skn_udp_host_create_broadcast_socket(int port, double rcvTimeout)
char ip[SZ_INFO_BUFF]
void skn_program_name_and_description_set(const char *name, const char *desc)
PRegistryEntry service_registry_find_entry(PServiceRegistry psreg, char *serviceName)
int gd_i_socket

+ Here is the call graph for this function: