Dietzi

Untitled

May 11th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.63 KB | None | 0 0
  1. struct clients {
  2.     uint32_t client_id;
  3.     ...
  4.     ...
  5.     ...
  6.     struct clients *next;
  7. };
  8.  
  9. struct listeners {
  10.     struct tcp_callback tcp_listener;
  11.     struct clients **clients;
  12. };
  13.  
  14. struct listeners listeners[65536];
  15.  
  16. void show_clients(uint16_t port) {
  17.     struct clients *client1 = listeners[port].clients;
  18.     while(client1 != NULL) {
  19.         kprintf("0x%x -> ",client1->client_id);
  20.         client1 = client1->next;
  21.     }
  22.     kprintf("\n");
  23. }
  24.  
  25. struct clients *add_client(uint32_t client_id, uint16_t port) {
  26.     struct clients *client;
  27.     client = pmm_alloc();
  28.     client->client_id = client_id;
  29.     client->con_est = false;
  30.     client->last_ack = 0;
  31.     client->last_seq = 0;
  32.     client->fin_ack = 0;
  33.     client->fin_seq = 0;
  34.     client->next = NULL;
  35.     struct clients *client1 = listeners[port].clients;
  36.     if(client1 == NULL) {
  37.         listeners[port].clients = client;
  38.         return client;
  39.     }
  40.     while(client1->next != NULL) {
  41.         client1 = client1->next;
  42.     }
  43.     client1->next = client;
  44.     show_clients(port);
  45.     return client;
  46. }
  47.  
  48. bool del_client(uint32_t client_id, uint16_t port) {
  49.     struct clients *client = listeners[port].clients;
  50.     if(client->client_id == client_id) {
  51.             struct clients *client_temp = client;
  52.             listeners[port].clients = client->next;
  53.             kprintf("Deleted1: 0x%x\n",client_temp->client_id);
  54.             pmm_free(client_temp);
  55.             show_clients(port);
  56.             return true;       
  57.     }
  58.     while(client->next != NULL) {
  59.         if(client->next->client_id == client_id) {
  60.             struct clients *client_temp = client->next;
  61.             client->next = client->next->next;
  62.             kprintf("Deleted2: 0x%x\n",client_temp->client_id);
  63.             pmm_free(client_temp);
  64.             show_clients(port);
  65.             return true;           
  66.         }
  67.     }
  68.     return false;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment