SHARE
TWEET

Untitled

a guest Oct 22nd, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <sys/socket.h>
  3. #include <sys/types.h>
  4. #include <arpa/inet.h>
  5. #include <unistd.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8.  
  9. #define NUM_MSG 10 /* Change this to set how many messages we process with a single call to send() */
  10.  
  11. int main(int argc, char const *argv[])
  12. {
  13.     int sock = 0, valread;
  14.     struct sockaddr_in serv_addr;
  15.     char *one_message = "|slca|trafficgenerator3|hyperlvs76|31|CalPublisherTest1.0|unset|67c2da756f9f509b|T06:49:36.00  ERROR   root-0  0   10  corr_id_=002a4eae4b97f&log_id_=012a50414b97e&m_rc=Retry&m_cfgset_name=m_cfgset_name&m_credit_issuer=m_credit_issuer&m_txn_timestamp=1564249775&m_end_time=1564382975&m_norm_cvv_resp_code=m_norm_cvv_resp_code&m_sndr_price_category=m_sndr_price_category&m_cfgset_service_name=m_cfgset_service_name&m_tokenized_value_type=m_tokenized_value_type&m_cfgset_name=m_cfgset_name&m_user_acct_type=m_user_acct_type&m_conversion_type=m_conversion_type&m_cfgset_version=m_cfgset_version&m_ext_wallet_providers=m_ext_wallet_providers&m_start_time=1564418975&m_incentive_funding_type=m_incentive_funding_type&m_extn_partner_incentive_type=m_extn_partner_incentive_type&m_is_millennium_eligible=m_is_millennium_eligible&m_dest_curr=m_dest_curr&m_fee_type=m_fee_type&m_source_curr=m_source_curr&m_bank_txn_type=m_bank_txn_type&m_compliance_decision=m_compliance_decision&m_bank_routing_entity=m_bank_routing_entity&m_rcpnt_price_category=m_rcpnt_price_category&m_txn_acquirer_country=m_txn_acquirer_country&m_partner_client_id=m_partner_client_id&m_api_name=m_api_name&m_proc_endpoint_uri=m_proc_endpoint_uri&m_balance_type=m_balance_type&call-duration=4711&m_bank_proc=m_bank_proc\n";
  16.     int l = strlen(one_message);
  17.     char *message = malloc(l * NUM_MSG);
  18.     char *p = message;
  19.     for(int i = 0; i < NUM_MSG; ++i) {
  20.         memcpy(p, one_message,l);
  21.         p += l;
  22.     }
  23.  
  24.     /* Notice the TCP_NODELAY flag. This *may* result in faster and more efficient handling of
  25.        large payloads. It may also reduce (but not eliminate) the number of partial messages. */
  26.     if ((sock = socket(AF_INET, SOCK_STREAM, TCP_NODELAY)) < 0)
  27.     {
  28.         printf("Socket creation error\n");
  29.         return -1;
  30.     }
  31.  
  32.     serv_addr.sin_family = AF_INET;
  33.     serv_addr.sin_port = htons(atoi(argv[2]));
  34.    
  35.     if(inet_pton(AF_INET, argv[1], &serv_addr.sin_addr)<=0)
  36.     {
  37.         printf("Invalid address/ Address not supported: %s\n", argv[1]);
  38.         return -1;
  39.     }
  40.  
  41.     if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
  42.     {
  43.         printf("Connection Failed \n");
  44.         return -1;
  45.     }
  46.  
  47.     for(;;) {
  48.     int size = l * NUM_MSG;
  49.     char *m = message;
  50.         for(;;) {
  51.             int n = send(sock , m , size , 0);
  52.             if(n < 0) {
  53.                 printf("Send Failed\n");
  54.                 return -1;
  55.             }
  56.  
  57.             /* If we could sen the entire message, we're done. */
  58.             if(size == n) {
  59.                 break;
  60.             }
  61.  
  62.             /* Only part of the message sent. Advance buffer pointer by n steps and reduce size of remaining
  63.                message by n. Then try again. */
  64.             m += n;
  65.             size -= n;
  66.             printf("%d bytes remain to be sent, and that's OK!\n", size);
  67.         }
  68.     }
  69.     return 0;
  70. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top