⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ez-ipupdate.c

📁 Connect DDNS Client Use GNUDIP
💻 C
📖 第 1 页 / 共 5 页
字号:
      else if(strcmp("qdns-stat", optarg) == 0 ||          strcmp("qdns-static", optarg) == 0)      {        service = &QDNS_STAT_service;      }      else if(strcmp("ods", optarg) == 0)      {        service = &ODS_service;      }      else if(strcmp("tzo", optarg) == 0)      {        service = &TZO_service;      }      else if(strcmp("easydns", optarg) == 0)      {        service = &EASYDNS_service;      }#ifdef USE_MD5      else if(strcmp("gnudip", optarg) == 0)      {        service = &GNUDIP_service;      }#endif      else if(strcmp("justlinux", optarg) == 0)      {        service = &JUSTL_service;      }      else if(strcmp("dyns", optarg) == 0)      {        service = &DYNS_service;      }      else if(strcmp("hn", optarg) == 0)      {        service = &HN_service;      }      else if(strcmp("zoneedit", optarg) == 0)      {        service = &ZONEEDIT_service;      }      else      {        fprintf(stderr, "unknown service type: %s\n", optarg);        fprintf(stderr, "try one of: %s\n", SERVICES_STR);        exit(1);      }      service_set = 1;      dprintf((stderr, "service_type: %s\n", service->name));      dprintf((stderr, "service->type: %d\n", service->type));      break;    case CMD_user:      strncpy(user, optarg, sizeof(user));      user[sizeof(user)-1] = '\0';      dprintf((stderr, "user: %s\n", user));      tmp = strchr(optarg, ':');      if(tmp)      {        tmp++;        while(*tmp) { *tmp++ = '*'; }      }      break;    case CMD_run_as_user:#if HAVE_PWD_H && HAVE_GRP_H      if((pw=getpwnam(optarg)) == NULL)      {        i = atoi(optarg);      }      else      {        if(setgid(pw->pw_gid) != 0)        {          fprintf(stderr, "error changing group id\n");        }        dprintf((stderr, "GID now %d\n", pw->pw_gid));        i = pw->pw_uid;      }      if(setuid(i) != 0)      {        fprintf(stderr, "error changing user id\n");      }      dprintf((stderr, "UID now %d\n", i));#else      fprintf(stderr, "option \"daemon-user\" not supported on this system\n");#endif      break;    case CMD_url:      if(url) { free(url); }      url = strdup(optarg);      dprintf((stderr, "url: %s\n", url));      break;    case CMD_wildcard:      wildcard = 1;      dprintf((stderr, "wildcard: %d\n", wildcard));      break;    case CMD_cloak_title:      if(cloak_title) { free(cloak_title); }      cloak_title = strdup(optarg);      dprintf((stderr, "cloak_title: %s\n", cloak_title));      break;    case CMD_timeout:      timeout.tv_sec = atoi(optarg);      timeout.tv_usec = (atof(optarg) - timeout.tv_sec) * 1000000L;      dprintf((stderr, "timeout: %ld.%06ld\n", timeout.tv_sec, timeout.tv_usec));      break;    case CMD_connection_type:      connection_type = atoi(optarg);      dprintf((stderr, "connection_type: %d\n", connection_type));      break;    case CMD_cache_file:      if(cache_file) { free(cache_file); }      cache_file = strdup(optarg);      dprintf((stderr, "cache_file: %s\n", cache_file));      break;    default:      dprintf((stderr, "case not handled: %d\n", id));      break;  }  return 0;}int conf_handler(struct conf_cmd *cmd, char *arg){  return(option_handler(cmd->id, arg));}#ifdef HAVE_GETOPT_LONG#  define xgetopt( x1, x2, x3, x4, x5 ) getopt_long( x1, x2, x3, x4, x5 )#else#  define xgetopt( x1, x2, x3, x4, x5 ) getopt( x1, x2, x3 )#endifvoid parse_args( int argc, char **argv ){#ifdef HAVE_GETOPT_LONG  struct option long_options[] = {      {"address",         required_argument,      0, 'a'},      {"cache-file",      required_argument,      0, 'b'},      {"config_file",     required_argument,      0, 'c'},      {"config-file",     required_argument,      0, 'c'},      {"daemon",          no_argument,            0, 'd'},      {"debug",           no_argument,            0, 'D'},      {"execute",         required_argument,      0, 'e'},      {"foreground",      no_argument,            0, 'f'},      {"pid-file",        required_argument,      0, 'F'},      {"host",            required_argument,      0, 'h'},      {"interface",       required_argument,      0, 'i'},      {"cloak_title",     required_argument,      0, 'L'},      {"mx",              required_argument,      0, 'm'},      {"max-interval",    required_argument,      0, 'M'},      {"notify-email",    required_argument,      0, 'N'},      {"resolv-period",   required_argument,      0, 'p'},      {"period",          required_argument,      0, 'P'},      {"quiet",           no_argument,            0, 'q'},      {"retrys",          required_argument,      0, 'r'},      {"run-as-user",     required_argument,      0, 'R'},      {"server",          required_argument,      0, 's'},      {"service-type",    required_argument,      0, 'S'},      {"timeout",         required_argument,      0, 't'},      {"connection-type", required_argument,      0, 'T'},      {"url",             required_argument,      0, 'U'},      {"user",            required_argument,      0, 'u'},      {"wildcard",        no_argument,            0, 'w'},      {"help",            no_argument,            0, 'H'},      {"version",         no_argument,            0, 'V'},      {"credits",         no_argument,            0, 'C'},      {"signalhelp",      no_argument,            0, 'Z'},      {0,0,0,0}  };#else#  define long_options NULL#endif  int opt;  while((opt=xgetopt(argc, argv, "a:b:c:dDe:fF:h:i:L:m:M:N:o:p:P:qr:R:s:S:t:T:U:u:wHVCZ",           long_options, NULL)) != -1)  {    switch (opt)    {      case 'a':        option_handler(CMD_address, optarg);        break;      case 'b':        option_handler(CMD_cache_file, optarg);        break;      case 'c':        if(config_file) { free(config_file); }        config_file = strdup(optarg);        dprintf((stderr, "config_file: %s\n", config_file));        if(config_file)        {          if(parse_conf_file(config_file, conf_commands) != 0)          {            fprintf(stderr, "error parsing config file \"%s\"\n", config_file);            exit(1);          }        }        break;      case 'd':        option_handler(CMD_daemon, optarg);        break;      case 'D':        option_handler(CMD_debug, optarg);        break;      case 'e':        option_handler(CMD_execute, optarg);        break;      case 'f':        option_handler(CMD_foreground, optarg);        break;      case 'F':        option_handler(CMD_pid_file, optarg);        break;      case 'h':        option_handler(CMD_host, optarg);        break;      case 'i':        option_handler(CMD_interface, optarg);        break;      case 'L':        option_handler(CMD_cloak_title, optarg);        break;      case 'm':        option_handler(CMD_mx, optarg);        break;      case 'M':        option_handler(CMD_max_interval, optarg);        break;      case 'N':        option_handler(CMD_notify_email, optarg);        break;      case 'o':        option_handler(CMD_offline, optarg);        break;      case 'p':        option_handler(CMD_resolv_period, optarg);        break;      case 'P':        option_handler(CMD_period, optarg);        break;      case 'q':        option_handler(CMD_quiet, optarg);        break;      case 'r':        option_handler(CMD_retrys, optarg);        break;      case 'R':        option_handler(CMD_run_as_user, optarg);        break;      case 's':        option_handler(CMD_server, optarg);        break;      case 'S':        option_handler(CMD_service_type, optarg);        break;      case 't':        option_handler(CMD_timeout, optarg);        break;      case 'T':        option_handler(CMD_connection_type, optarg);        break;      case 'u':        option_handler(CMD_user, optarg);        break;      case 'U':        option_handler(CMD_url, optarg);        break;      case 'w':        option_handler(CMD_wildcard, optarg);        break;      case 'H':        print_usage();        exit(0);        break;      case 'V':        print_version();        exit(0);        break;      case 'C':        print_credits();        exit(0);        break;      case 'Z':        print_signalhelp();        exit(0);        break;      default:#ifdef HAVE_GETOPT_LONG        fprintf(stderr, "Try `%s --help' for more information\n", argv[0]);#else        fprintf(stderr, "Try `%s -H' for more information\n", argv[0]);        fprintf(stderr, "warning: this program was compilied without getopt_long\n");        fprintf(stderr, "         as such all long options will not work!\n");#endif        exit(1);        break;    }  }}/* * do_connect * * connect a socket and return the file descriptor * */int do_connect(int *sock, char *host, char *port){  struct sockaddr_in address;  int len;  int result;  struct hostent *hostinfo;  struct servent *servinfo;  // set up the socket  if((*sock=socket(AF_INET, SOCK_STREAM, 0)) == -1)  {    if(!(options & OPT_QUIET))    {      perror("socket");    }    return(-1);  }  address.sin_family = AF_INET;  // get the host address  hostinfo = gethostbyname(host);  if(!hostinfo)  {    if(!(options & OPT_QUIET))    {      herror("gethostbyname");    }    close(*sock);    return(-1);  }  address.sin_addr = *(struct in_addr *)*hostinfo -> h_addr_list;  // get the host port  servinfo = getservbyname(port, "tcp");  if(servinfo)  {    address.sin_port = servinfo -> s_port;  }  else  {    address.sin_port = htons(atoi(port));  }  // connect the socket  len = sizeof(address);  if((result=connect(*sock, (struct sockaddr *)&address, len)) == -1)   {    if(!(options & OPT_QUIET))    {      perror("connect");    }    close(*sock);    return(-1);  }  // print out some info  if(!(options & OPT_QUIET))  {    fprintf(stderr,        "connected to %s (%s) on port %d.\n",        host,        inet_ntoa(address.sin_addr),        ntohs(address.sin_port));  }  return 0;}static char table64[]=  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";void base64Encode(char *intext, char *output){  unsigned char ibuf[3];  unsigned char obuf[4];  int i;  int inputparts;  while(*intext) {    for (i = inputparts = 0; i < 3; i++) {       if(*intext) {        inputparts++;        ibuf[i] = *intext;        intext++;      }      else        ibuf[i] = 0;    }    obuf [0] = (ibuf [0] & 0xFC) >> 2;    obuf [1] = ((ibuf [0] & 0x03) << 4) | ((ibuf [1] & 0xF0) >> 4);    obuf [2] = ((ibuf [1] & 0x0F) << 2) | ((ibuf [2] & 0xC0) >> 6);    obuf [3] = ibuf [2] & 0x3F;    switch(inputparts) {      case 1: /* only one byte read */        sprintf(output, "%c%c==",             table64[obuf[0]],            table64[obuf[1]]);        break;      case 2: /* two bytes read */        sprintf(output, "%c%c%c=",             table64[obuf[0]],            table64[obuf[1]],            table64[obuf[2]]);        break;      default:        sprintf(output, "%c%c%c%c",             table64[obuf[0]],            table64[obuf[1]],            table64[obuf[2]],            table64[obuf[3]] );        break;    }    output += 4;  }  *output=0;}#if IF_LOOKUP #  if !defined(HAVE_INET_ATON) #    if defined(HAVE_INET_ADDR)int inet_aton(const char *cp, struct in_addr *inp){  (*inp).s_addr = inet_addr(cp);}#  else#    error "sorry, can't compile with IF_LOOKUP and no inet_aton"#  endif#endif#endifvoid output(void *buf){  fd_set writefds;  int max_fd;  struct timeval tv;  int ret;  dprintf((stderr, "I say: %s\n", (char *)buf));  // set up our fdset and timeout  FD_ZERO(&writefds);  FD_SET(client_sockfd, &writefds);  max_fd = client_sockfd;  memcpy(&tv, &timeout, sizeof(struct timeval));  ret = select(max_fd + 1, NULL, &writefds, NULL, &tv);  dprintf((stderr, "ret: %d\n", ret));  if(ret == -1)  {    dprintf((stderr, "select: %s\n", error_string));  }  else if(ret == 0)  {    fprintf(stderr, "timeout\n");  }  else  {    /* if we woke up on client_sockfd do the data passing */    if(FD_ISSET(client_sockfd, &writefds))    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -