Changeset 246


Ignore:
Timestamp:
Jul 15, 2011, 4:36:44 PM (13 years ago)
Author:
jazz
Message:
  • icas_send : read blacklist to send UDP packets.
  • icas_recv : receive UDP packets and print messages.


Location:
icas_send
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • icas_send/Makefile

    r245 r246  
    11all:
    2   gcc icas_send.c -o icas_send
    3   gcc icas_recv.c -o icas_recv
     2  gcc icas_send.c -o icas_send -static
     3  gcc icas_recv.c -o icas_recv -static
     4  strip icas_send
     5  strip icas_recv
    46clean:
    57  rm icas_send icas_recv
  • icas_send/icas_recv.c

    r245 r246  
    2222    int    recv_length = sizeof(recv_sockopt);
    2323    int    received;
    24     char   BLACK_LIST[256];
     24    char   BLACK_LIST[1024];
    2525
    2626    if (argc <= 1)
     
    5252    fprintf(stderr,"Finished binding port #%s for icas_recv socket.\n",argv[1]);
    5353
    54     if ((received = recvfrom(recv_sock, BLACK_LIST, sizeof(BLACK_LIST), 0, (struct sockaddr *) &recv_sockopt, (socklen_t *) &recv_length)) < 0)
     54    while(1)
    5555    {
    56   Die("Failed to receive message");
     56  if ((received = recvfrom(recv_sock, BLACK_LIST, sizeof(BLACK_LIST), 0,
     57                     (struct sockaddr *) &recv_sockopt,
     58                     (socklen_t *) &recv_length)) < 0)
     59  {
     60      Die("Failed to receive message");
     61  }
     62  fprintf(stderr,"Received: %s\n", BLACK_LIST);
    5763    }
    58     fprintf(stderr,"Received: %s\n", BLACK_LIST);
    5964
    6065    close(recv_sock);
  • icas_send/icas_send.c

    r245 r246  
    1818int main(int argc, char *argv[])
    1919{
    20     struct sockaddr_in send_sockopt;
    21     int    send_sock;
    22     int    send_length = sizeof(send_sockopt);
    23     char   BLACK_LIST[256];
     20    struct  sockaddr_in send_sockopt;
     21    int     send_sock;
     22    int     send_length = sizeof(send_sockopt);
     23    FILE    *fd;
     24    char    BLACK_LIST[1024];
     25    size_t  len = 0;
     26    ssize_t read;
    2427
    2528    if (argc <= 2)
    2629    {
    2730  fprintf(stderr, "USAGE: %s <RECV_IP> <RECV_PORT>\n", argv[0]);
     31  exit(1);
     32    }
     33
     34    /* open blacklist to read black list data */
     35    fd = fopen("blacklist","r");
     36    if (fd == NULL)
     37    {
     38      fprintf(stderr, "%s: Couldn't open file %s; %s\n", argv[0], "blacklist", strerror (errno));
    2839  exit(1);
    2940    }
     
    4556    send_sockopt.sin_port = htons(atoi(argv[2]));        /* server port */
    4657
    47     if (sendto(send_sock, BLACK_LIST, sizeof(BLACK_LIST), 0,
    48          (struct sockaddr *) &send_sockopt,
    49          sizeof(send_sockopt)) != sizeof(BLACK_LIST)) {
    50   Die("1: Mismatch in number of sent bytes");
     58    while(fgets(BLACK_LIST,sizeof(BLACK_LIST),fd))
     59    {
     60  if (sendto(send_sock, BLACK_LIST, sizeof(BLACK_LIST), 0,
     61       (struct sockaddr *) &send_sockopt,
     62       sizeof(send_sockopt)) != sizeof(BLACK_LIST))
     63  {
     64      Die("1: Mismatch in number of sent bytes");
     65  }
    5166    }
    5267
Note: See TracChangeset for help on using the changeset viewer.