APUE Learning Example Source Code
guowenxue
2020-01-01 5c07107b73c234ef1f80a92abe795bf3f5c7050f
update ddns client, server and configure file
3 files modified
26 ■■■■■ changed files
app_ddns/ddns.conf 11 ●●●● patch | view | raw | blame | history
app_ddns/ddns_client.c 11 ●●●● patch | view | raw | blame | history
app_ddns/ddns_server.c 4 ●●●● patch | view | raw | blame | history
app_ddns/ddns.conf
@@ -1,6 +1,7 @@
[common]
domain="studio.iot-yun.club"
id="MasterServer"
domain="master.iot-yun.club"
#[host0]
#comment="localhost"
@@ -12,10 +13,10 @@
ip=122.51.234.174
port=10001
[host2]
comment="aliyun"
ip=47.74.239.156
port=10001
#[host2]
#comment="aliyun"
#ip=47.74.239.156
#port=10001
app_ddns/ddns_client.c
@@ -52,10 +52,12 @@
    char              *str;
    int                val;
    char              *domain;
    char              *id;
    char              *serverip;
    int                port;
    int                i;
    char               key[64];
    char               msg[512];
    struct option long_options[] = { 
        {"conf", required_argument, NULL, 'c'},
@@ -95,12 +97,17 @@
        return -1; 
    }   
    id=iniparser_getstring(ini, "common:id", NULL);
    domain=iniparser_getstring(ini, "common:domain", NULL);
    if( !domain )
    {
        printf("ERROR: cannot parse domain in '%s'\n", conf_file);
        printf("ERROR: cannot parse domain/id in '%s'\n", conf_file);
        return -1; 
    }
    memset(msg, 0, sizeof(msg));
    snprintf(msg, sizeof(msg), "[%s]: '%s'", id, domain);
    for(i=0; i<MAX_HOSTS; i++)
    {
@@ -118,7 +125,7 @@
        }
        printf("==> Start send domain '%s' to [%s:%d]\n", domain, serverip, port);
        socket_send_domain(serverip, port, domain);
        socket_send_domain(serverip, port, msg);
        printf("\n");
    }
app_ddns/ddns_server.c
@@ -185,7 +185,7 @@
                memset(buf, 0, sizeof(buf));
                if( (rv=read(clifd, buf, sizeof(buf))) <= 0)
                {
                    log_err("socket[%d] already get disconncet and will be removed.\n", clifd);
                    log_dbg("socket[%d] already get disconncet and will be removed.\n", clifd);
                    epoll_ctl(epollfd, EPOLL_CTL_DEL, clifd, NULL);
                    close(clifd);
                    continue;
@@ -209,7 +209,7 @@
                    }
                    log_nrml("Domain: %s=>%s\n", buf, ipaddr);
                    log_nrml("<<<<< %s => '%s' >>>>>\n", buf, ipaddr);
                } 
            } 
        } /* for(i=0; i<rv; i++) */