#include <stdio.h>
#include <stdlib.h>
char buff[10000];
typedef int (*funcPtr)();
int main(void)
{
int result;
funcPtr add;
printf("fetch C2M module \n");
add = (funcPtr) fetch("C2M");
if (add == NULL) {
printf("c2Msub: fetch of c2m module failed\n");
}
else {
printf("calling c2m routine \n");
result = (*add)(buff);
printf("buffer after c2m call = %d\n", *add);
}
}


#pragma linkage(C2M, FETCHABLE)
#define _XOPEN_SOURCE_EXTENDED 1
#define _OE_SOCKETS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl.h>

struct MemoryStruct {
  char *memory;
  size_t size;
};

static size_t
WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
  size_t realsize = size * nmemb;
  struct MemoryStruct *mem = (struct MemoryStruct *)userp;

  mem->memory = realloc(mem->memory, mem->size + realsize + 1);
  if(mem->memory == NULL) {
    /* out of memory! */
    printf("not enough memory (realloc returned NULL)\n");
    return 0;
  }

  memcpy(&(mem->memory[mem->size]), contents, realsize);
  mem->size += realsize;
  mem->memory[mem->size] = 0;

  return realsize;
}

int C2M(void)
{
  CURL *curl_handle;
  CURLcode res;

  struct MemoryStruct chunk;

  chunk.memory = malloc(1);  /* grown as needed realloc above */
  chunk.size = 0;    /* no data at this point */

  curl_global_init(CURL_GLOBAL_ALL);

  curl_handle = curl_easy_init();

 curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L);

 curl_easy_setopt(curl_handle, CURLOPT_URL, "http://ukmet/");

 curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);

 curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);

 curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");

 res = curl_easy_perform(curl_handle);

 if(res != CURLE_OK) {
   fprintf(stderr, "curl_easy_perform() failed: %s\n",
           curl_easy_strerror(res));
 }
 else {
   printf("%lu bytes retrieved\n", (long)chunk.size);
   printf("Buffer from curl: [%s]\n", chunk);
 }

 curl_easy_cleanup(curl_handle);

 free(chunk.memory);

  curl_global_cleanup();

  return 0;
}

