1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

IRKit用のコマンドをcurlで簡単作成

Posted at

curl の --libcurl オプションを使う

前提

{"format":"raw","freq":38,"data":[6881,3341,904,815,904,2537,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,2537,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,2537,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,2537,904,815,904,2537,904,2537,904,2537,904,2537,904,815,904,815,904,2537,904,815,904,2537,904,2537,904,2537,904,2537,904,815,904,2537,904,65535,0,65535,0,16832,6881,3341,904,815,904,2537,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,2537,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,2537,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,2537,904,815,935,2451,904,2451,904,2451,904,2451,904,815,904,815,904,2537,904,815,904,2537,904,2537,904,2537,904,2537,904,815,904,2537,904,65535,0,65535,0,16832,6881,3341,904,815,904,2537,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,2537,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,2537,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,2537,904,815,904,2537,904,2537,904,2537,904,2537,904,815,904,815,904,2537,904,815,904,2537,904,2537,904,2537,904,2537,904,815,904,2537,904]}

power.c を生成

curl -i "http://192.168.1.1/messages" -d "$(cat ./power.json)" --libcurl power.c

gccでコンパイル

gcc power.c -o power -lcurl

実行してみる

./power

実行時の出力がうざいときは curl -i オプションをなくせばよい

なお生成されたpower.cは以下の様な形

/********* Sample code generated by the curl command line tool **********
 * All curl_easy_setopt() options are documented at:
 * http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
 ************************************************************************/
# include <curl/curl.h>

int main(int argc, char *argv[])
{
  CURLcode ret;
  CURL *hnd;

  hnd = curl_easy_init();
  curl_easy_setopt(hnd, CURLOPT_URL, "http://192.168.1.1/messages");
  curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
  curl_easy_setopt(hnd, CURLOPT_HEADER, 1L);
  curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\"format\":\"raw\",\"freq\":38,\"data\":[6881,3341,904,815,904,2537,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,2537,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,2537,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,2537,904,815,904,2537,904,2537,904,2537,904,2537,904,815,904,815,904,2537,904,815,904,2537,904,2537,904,2537,904,2537,904,815,904,2537,904,65535,0,65535,0,16832,6881,3341,904,815,904,2537,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,2537,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,2537,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,2537,904,815,935,2451,904,2451,904,2451,904,2451,904,815,904,815,904,2537,904,815,904,2537,904,2537,904,2537,904,2537,904,815,904,2537,904,65535,0,65535,0,16832,6881,3341,904,815,904,2537,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,2537,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,2537,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,815,904,2537,904,815,904,2537,904,2537,904,2537,904,2537,904,815,904,815,904,2537,904,815,904,2537,904,2537,904,2537,904,2537,904,815,904,2537,904]}");
  curl_easy_setopt(hnd, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)1315);
  curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/7.37.1");
  curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
  curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);

  /* Here is a list of options the curl code used that cannot get generated
     as source easily. You may select to either not use them or implement
     them yourself.

  CURLOPT_WRITEDATA set to a objectpointer
  CURLOPT_WRITEFUNCTION set to a functionpointer
  CURLOPT_READDATA set to a objectpointer
  CURLOPT_READFUNCTION set to a functionpointer
  CURLOPT_SEEKDATA set to a objectpointer
  CURLOPT_SEEKFUNCTION set to a functionpointer
  CURLOPT_ERRORBUFFER set to a objectpointer
  CURLOPT_STDERR set to a objectpointer
  CURLOPT_HEADERFUNCTION set to a functionpointer
  CURLOPT_HEADERDATA set to a objectpointer

  */

  ret = curl_easy_perform(hnd);

  curl_easy_cleanup(hnd);
  hnd = NULL;

  return (int)ret;
}
/**** End of sample code ****/
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?